-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement unit testing and refactor functions
- Loading branch information
Antonio Contreras LEMONCODE
committed
Aug 22, 2024
1 parent
b40559a
commit bf6f112
Showing
6 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import { ShapeModel } from '../model'; | ||
import { QuickMockFileContract } from './local-disk.model'; | ||
import { QuickMockFileContract, Page } from './local-disk.model'; | ||
|
||
export const mapFromShapesArrayToQuickMockDocument = ( | ||
export const mapFromShapesArrayToQuickMockFileDocument = ( | ||
shapes: ShapeModel[] | ||
): QuickMockFileContract => { | ||
const pages: Page[] = shapes.reduce((acc, shape) => { | ||
const newPage: Page = { | ||
id: '1', | ||
name: 'default', | ||
shapes: [{ ...shape }], | ||
}; | ||
|
||
return [...acc, newPage]; | ||
}, [] as Page[]); | ||
|
||
return { | ||
version: '0.1', | ||
pages: [ | ||
{ | ||
id: '1', | ||
name: 'default', | ||
shapes, | ||
}, | ||
], | ||
pages, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { mapFromShapesArrayToQuickMockFileDocument } from './shapes-to-document.mapper'; | ||
import { ShapeModel } from '../model'; | ||
import { QuickMockFileContract } from './local-disk.model'; | ||
|
||
describe('shapes to document mapper', () => { | ||
describe('mapFromShapesArrayToQuickMockFileDocument', () => { | ||
it('Should return a ShapeModel with empty pages', () => { | ||
// Arrange | ||
const shapes: ShapeModel[] = []; | ||
const expectedResult: QuickMockFileContract = { | ||
version: '0.1', | ||
pages: [], | ||
}; | ||
// Act | ||
const result = mapFromShapesArrayToQuickMockFileDocument(shapes); | ||
|
||
// Assert | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
it('Should return a ShapeModel with one pages and shapes', () => { | ||
// Arrange | ||
const shapes: ShapeModel[] = [ | ||
{ | ||
id: '1', | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100, | ||
type: 'rectangle', | ||
allowsInlineEdition: false, | ||
typeOfTransformer: ['rotate'], | ||
}, | ||
]; | ||
const expectedResult: QuickMockFileContract = { | ||
version: '0.1', | ||
pages: [ | ||
{ | ||
id: '1', | ||
name: 'default', | ||
shapes: [ | ||
{ | ||
id: '1', | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100, | ||
type: 'rectangle', | ||
allowsInlineEdition: false, | ||
typeOfTransformer: ['rotate'], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
// Act | ||
const result = mapFromShapesArrayToQuickMockFileDocument(shapes); | ||
|
||
// Assert | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
|
||
it('Should return a ShapeModel with two pages and shapes', () => { | ||
// Arrange | ||
const shapes: ShapeModel[] = [ | ||
{ | ||
id: '1', | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100, | ||
type: 'rectangle', | ||
allowsInlineEdition: false, | ||
typeOfTransformer: ['rotate'], | ||
}, | ||
{ | ||
id: '2', | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100, | ||
type: 'circle', | ||
allowsInlineEdition: true, | ||
typeOfTransformer: ['rotate'], | ||
}, | ||
]; | ||
const expectedResult: QuickMockFileContract = { | ||
version: '0.1', | ||
pages: [ | ||
{ | ||
id: '1', | ||
name: 'default', | ||
shapes: [ | ||
{ | ||
id: '1', | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100, | ||
type: 'rectangle', | ||
allowsInlineEdition: false, | ||
typeOfTransformer: ['rotate'], | ||
}, | ||
], | ||
}, | ||
{ | ||
id: '1', | ||
name: 'default', | ||
shapes: [ | ||
{ | ||
id: '2', | ||
x: 0, | ||
y: 0, | ||
width: 100, | ||
height: 100, | ||
type: 'circle', | ||
allowsInlineEdition: true, | ||
typeOfTransformer: ['rotate'], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
// Act | ||
const result = mapFromShapesArrayToQuickMockFileDocument(shapes); | ||
|
||
// Assert | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters