Add initial NativeImage.addRepresentation specs

This commit is contained in:
Kevin Sawicki 2017-03-07 13:47:31 -08:00
parent 783b5e84f4
commit 17b70670f8
3 changed files with 27 additions and 0 deletions

View file

@ -249,4 +249,31 @@ describe('nativeImage module', () => {
assert.equal(nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png')).getAspectRatio(), 2.8315789699554443)
})
})
describe('addRepresentation()', () => {
it('supports adding a representation for a scale factor', () => {
const image = nativeImage.createEmpty()
image.addRepresentation({
scaleFactor: 1.0,
buffer: nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '1x1.png')).toPNG()
})
image.addRepresentation({
scaleFactor: 2.0,
buffer: nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '2x2.jpg')).toPNG()
})
image.addRepresentation({
scaleFactor: 3.0,
buffer: nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '3x3.png')).toPNG()
})
image.addRepresentation({
scaleFactor: 4.0,
buffer: 'invalid'
})
assert.equal(image.toDataURL({scaleFactor: 1.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=')
assert.equal(image.toDataURL({scaleFactor: 2.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFUlEQVQYlWP8////fwYGBgYmBigAAD34BABBrq9BAAAAAElFTkSuQmCC')
assert.equal(image.toDataURL({scaleFactor: 3.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAADElEQVQYlWNgIAoAAAAnAAGZWEMnAAAAAElFTkSuQmCC')
assert.equal(image.toDataURL({scaleFactor: 4.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAYAAABWKLW/AAAADElEQVQYlWNgIAoAAAAnAAGZWEMnAAAAAElFTkSuQmCC')
})
})
})

BIN
spec/fixtures/assets/2x2.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
spec/fixtures/assets/3x3.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B