Skip to content

Commit

Permalink
fix(client): fix image export
Browse files Browse the repository at this point in the history
* change jpg to jpeg
* remove point from extensions

Closes #1102
Closes #1103
  • Loading branch information
philippfromme authored and barmac committed Jan 17, 2019
1 parent dca6bdd commit dc9e628
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/lib/file-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ function ensureExtension(filePath, defaultExtension) {
}

function getBase64Contents(contents) {
return contents.replace(/^data:image\/(jpg|png)+;base64,/, '');
return contents.replace(/^data:image\/(jpeg|png)+;base64,/, '');
}
33 changes: 26 additions & 7 deletions app/test/spec/file-system-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const FileSystem = require('../../lib/file-system');
const ENCODING_BASE64 = 'base64',
ENCODING_UTF8 = 'utf8';

const BASE64_ENCODED =
'data:image/png;base64,' +
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8Xw8AAoMBgDTD2qgAAAAASUVORK5CYII=';
const PNG_BASE64_ENCODED = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAA';

const JPEG_BASE64_ENCODED = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD';

let testFilePaths = [];

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('FileSystem', function() {
// given
const fooPath = getTestFilePath('foo.file');

fileSystem.writeFile(fooPath, { contents: BASE64_ENCODED }, {
fileSystem.writeFile(fooPath, { contents: PNG_BASE64_ENCODED }, {
encoding: ENCODING_BASE64
});

Expand Down Expand Up @@ -179,13 +179,13 @@ describe('FileSystem', function() {
});


it('should write file (encoding=BASE64)', function() {
it('should write PNG file (encoding=BASE64)', function() {

// given
const fooPath = getTestFilePath('foo.file');

// when
fileSystem.writeFile(fooPath, { contents: BASE64_ENCODED }, {
fileSystem.writeFile(fooPath, { contents: PNG_BASE64_ENCODED }, {
encoding: ENCODING_BASE64
});

Expand All @@ -194,7 +194,26 @@ describe('FileSystem', function() {
encoding: ENCODING_BASE64
});

expect(file.contents).to.match(/iVBOR/);
expect(file.contents).to.match(/iVBORw0KGgoAAAANSUhEUgAAADAA/);
});


it('should write JPEG file (encoding=BASE64)', function() {

// given
const fooPath = getTestFilePath('foo.file');

// when
fileSystem.writeFile(fooPath, { contents: JPEG_BASE64_ENCODED }, {
encoding: ENCODING_BASE64
});

// then
const file = fileSystem.readFile(fooPath, {
encoding: ENCODING_BASE64
});

expect(file.contents).to.match(/\/9j\/4AAQSkZJRgABAQAAAQABAAA/);
});


Expand Down
20 changes: 10 additions & 10 deletions client/src/app/TabsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ const noopProvider = {
const ENCODING_BASE64 = 'base64',
ENCODING_UTF8 = 'utf8';

const EXPORT_JPG = {
name: 'JPG',
const EXPORT_JPEG = {
name: 'JPEG image',
encoding: ENCODING_BASE64,
extensions: [ '.jpg' ]
extensions: [ 'jpeg' ]
};

const EXPORT_PNG = {
name: 'PNG',
name: 'PNG image',
encoding: ENCODING_BASE64,
extensions: [ '.png' ]
extensions: [ 'png' ]
};

const EXPORT_SVG = {
name: 'SVG',
name: 'SVG image',
encoding: ENCODING_UTF8,
extensions: [ '.svg' ]
extensions: [ 'svg' ]
};

/**
Expand All @@ -61,8 +61,8 @@ export default class TabsProvider {
name: 'BPMN',
encoding: ENCODING_UTF8,
exports: {
jpg: EXPORT_JPG,
png: EXPORT_PNG,
jpeg: EXPORT_JPEG,
svg: EXPORT_SVG
},
extensions: [ 'bpmn', 'xml' ],
Expand Down Expand Up @@ -94,8 +94,8 @@ export default class TabsProvider {
name: 'CMMN',
encoding: ENCODING_UTF8,
exports: {
jpg: EXPORT_JPG,
png: EXPORT_PNG,
jpeg: EXPORT_JPEG,
svg: EXPORT_SVG
},
extensions: [ 'cmmn', 'xml' ],
Expand Down Expand Up @@ -126,8 +126,8 @@ export default class TabsProvider {
name: 'DMN',
encoding: ENCODING_UTF8,
exports: {
jpg: EXPORT_JPG,
png: EXPORT_PNG,
jpeg: EXPORT_JPEG,
svg: EXPORT_SVG
},
extensions: [ 'dmn', 'xml' ],
Expand Down
32 changes: 31 additions & 1 deletion client/src/app/__tests__/TabsProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,44 @@ describe('TabsProvider', function() {
const tabsProvider = new TabsProvider();

// then
expect(tabsProvider.getProvider('cmmn')).to.exist;
expect(tabsProvider.getProvider('bpmn')).to.exist;
expect(tabsProvider.getProvider('cmmn')).to.exist;
expect(tabsProvider.getProvider('dmn')).to.exist;

expect(tabsProvider.getProvider('empty')).to.exist;
});


it('should export BPMN, CMMN and DMN as JPEG, PNG and SVG', function() {

// given
const tabsProvider = new TabsProvider();

const expected = {
png: {
name: 'PNG image',
encoding: 'base64',
extensions: [ 'png' ]
},
jpeg: {
name: 'JPEG image',
encoding: 'base64',
extensions: [ 'jpeg' ]
},
svg: {
name: 'SVG image',
encoding: 'utf8',
extensions: [ 'svg' ]
}
};

// then
expect(tabsProvider.getProvider('bpmn').exports).to.eql(expected);
expect(tabsProvider.getProvider('cmmn').exports).to.eql(expected);
expect(tabsProvider.getProvider('dmn').exports).to.eql(expected);
});


it('should provide initial tab contents', function() {

// given
Expand Down
20 changes: 10 additions & 10 deletions client/src/app/__tests__/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import EmptyTab from '../../EmptyTab';
const ENCODING_BASE64 = 'base64',
ENCODING_UTF8 = 'utf8';

const EXPORT_JPG = {
name: 'JPG',
const EXPORT_JPEG = {
name: 'JPEG image',
encoding: ENCODING_BASE64,
extensions: [ '.jpg' ]
extensions: [ 'jpeg' ]
};

const EXPORT_PNG = {
name: 'PNG',
name: 'PNG image',
encoding: ENCODING_BASE64,
extensions: [ '.png' ]
extensions: [ 'png' ]
};

const EXPORT_SVG = {
name: 'SVG',
name: 'SVG image',
encoding: ENCODING_UTF8,
extensions: [ '.svg' ]
extensions: [ 'svg' ]
};


Expand Down Expand Up @@ -107,8 +107,8 @@ export class TabsProvider {
name: 'BPMN',
encoding: ENCODING_UTF8,
exports: {
jpg: EXPORT_JPG,
png: EXPORT_PNG,
jpeg: EXPORT_JPEG,
svg: EXPORT_SVG
},
extensions: [ 'bpmn', 'xml' ]
Expand All @@ -117,8 +117,8 @@ export class TabsProvider {
name: 'CMMN',
encoding: ENCODING_UTF8,
exports: {
jpg: EXPORT_JPG,
png: EXPORT_PNG,
jpeg: EXPORT_JPEG,
svg: EXPORT_SVG
},
extensions: [ 'cmmn', 'xml' ]
Expand All @@ -127,8 +127,8 @@ export class TabsProvider {
name: 'DMN',
encoding: ENCODING_UTF8,
exports: {
jpg: EXPORT_JPG,
png: EXPORT_PNG,
jpeg: EXPORT_JPEG,
svg: EXPORT_SVG
},
extensions: [ 'dmn', 'xml' ]
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const NAMESPACE_URL_ACTIVITI = 'http://activiti.org/bpmn',
NAMESPACE_PREFIX_ACTIVITI = 'activiti',
NAMESPACE_PREFIX_CAMUNDA = 'camunda';

const EXPORT_AS = [ 'svg', 'png' ];
const EXPORT_AS = [ 'png', 'jpeg', 'svg' ];

const COLORS = [{
title: 'White',
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/tabs/cmmn/CmmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import generateImage from '../../util/generateImage';
import Metadata from '../../../util/Metadata';


const EXPORT_AS = [ 'svg', 'png' ];
const EXPORT_AS = [ 'png', 'jpeg', 'svg' ];


export class CmmnEditor extends CachedComponent {
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/tabs/dmn/DmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import generateImage from '../../util/generateImage';
import Metadata from '../../../util/Metadata';


const EXPORT_AS = [ 'svg', 'png' ];
const EXPORT_AS = [ 'png', 'jpeg', 'svg' ];


export class DmnEditor extends CachedComponent {
Expand Down

0 comments on commit dc9e628

Please sign in to comment.