-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #44 Previous behavior was to assign Model once per class which may produce mutations, now each class has own Model getter which returns new Object every time it called
- Loading branch information
1 parent
80c9e29
commit 84293db
Showing
30 changed files
with
612 additions
and
547 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,49 @@ | ||
const {Sketch, Text, Page, Artboard} = require('../index'); | ||
const {fileExists, clearOutput} = require('./__helpers'); | ||
const { Sketch, Text, Page, Artboard } = require('../index'); | ||
const { fileExists, clearOutput } = require('./__helpers'); | ||
|
||
describe('Building from scratch', () => { | ||
beforeEach(() => { | ||
clearOutput(); | ||
}); | ||
|
||
it('should write a valid file', () => { | ||
let sketch = new Sketch(); | ||
const page = new Page({ | ||
name: 'My Page' | ||
}); | ||
const artboard = new Artboard({ | ||
frame: { | ||
width: 1024, | ||
height: 768 | ||
}, | ||
name: 'My Artboard' | ||
}); | ||
const text = new Text({ | ||
name: 'My Text', | ||
string: 'Test', | ||
fontSize: 24 | ||
}); | ||
artboard.addLayer( text ); | ||
sketch.addPage( page ); | ||
sketch.addArtboard(page.getID(), artboard); | ||
const path = `${process.cwd()}/__tests__/__output/output2.sketch`; | ||
sketch.build(path).then((path) => { | ||
expect(fileExists(path)).toBeTruthy(); | ||
}); | ||
it('should write a valid file', async () => { | ||
await (async () => { | ||
const sketch = new Sketch(); | ||
const page = new Page({ | ||
name: 'My Page', | ||
}); | ||
const artboard = new Artboard({ | ||
frame: { | ||
width: 1024, | ||
height: 768, | ||
}, | ||
name: 'My Artboard', | ||
}); | ||
const text = new Text({ | ||
name: 'My Text', | ||
string: 'Test', | ||
fontSize: 24, | ||
}); | ||
artboard.addLayer(text); | ||
sketch.addPage(page); | ||
sketch.addArtboard(page.getID(), artboard); | ||
const path = `${process.cwd()}/__tests__/__output/output2.sketch`; | ||
const outputPath = await sketch.build(path); | ||
expect(fileExists(outputPath)).toBeTruthy(); | ||
|
||
const { meta } = sketch; | ||
expect(Object.keys(meta.pagesAndArtboards || {}).length).toEqual(1); | ||
const metaPage = Object.values(meta.pagesAndArtboards)[0]; | ||
expect(metaPage.name).toEqual('My Page'); | ||
expect(Object.keys(metaPage.artboards).length).toEqual(1); | ||
const metaArtboard = Object.values(metaPage.artboards)[0]; | ||
expect(metaArtboard.name).toEqual('My Artboard'); | ||
})(); | ||
|
||
// another sketch should have correct meta | ||
await (async () => { | ||
const { meta } = new Sketch(); | ||
expect(Object.keys(meta.pagesAndArtboards || {}).length).toEqual(0); | ||
})(); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.