Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect translation reporter #1364

Merged
merged 5 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions docs/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
"Activate the hand tool",
"Activate the lasso tool",
"Ad-hoc",
"Add Lane above",
"Add Lane below",
"Append ConditionIntermediateCatchEvent",
"Append EndEvent",
"Append Gateway",
"Append Intermediate/Boundary Event",
"Append MessageIntermediateCatchEvent",
"Append ReceiveTask",
"Append SignalIntermediateCatchEvent",
"Append Task",
"Append TimerIntermediateCatchEvent",
"Append compensation activity",
"Append {type}",
"Business Rule Task",
"Call Activity",
"Cancel Boundary Event",
"Cancel End Event",
"Change type",
"Compensation Boundary Event",
"Compensation End Event",
Expand All @@ -25,11 +35,19 @@
"Connect using Association",
"Connect using DataInputAssociation",
"Connect using Sequence/MessageFlow or Association",
"Create IntermediateThrowEvent/BoundaryEvent",
"Create DataObjectReference",
"Create DataStoreReference",
"Create EndEvent",
"Create Gateway",
"Create Group",
"Create Intermediate/Boundary Event",
"Create Pool/Participant",
"Create StartEvent",
"Create Task",
"Create expanded SubProcess",
"Create {type}",
"Default Flow",
"Divide into three Lanes",
"Divide into two Lanes",
"End Event",
"Error Boundary Event",
"Error End Event",
Expand All @@ -41,8 +59,8 @@
"Escalation Start Event",
"Escalation Start Event (non-interrupting)",
"Event Sub Process",
"Event based Gateway",
"Exclusive Gateway",
"HELLO {you}!",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💕

"Inclusive Gateway",
"Intermediate Throw Event",
"Link Intermediate Catch Event",
Expand Down Expand Up @@ -93,6 +111,5 @@
"multiple DI elements defined for {element}",
"no bpmnElement referenced in {element}",
"no diagram to display",
"no process or collaboration to display",
"participants cannot be pasted onto a non-empty process diagram"
"no process or collaboration to display"
]
17 changes: 1 addition & 16 deletions lib/features/modeling/behavior/ModelingFeedback.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { is } from '../../../util/ModelUtil';

var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants',
PROCESS_ERR_MSG = 'participants cannot be pasted onto a non-empty process diagram';

var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants';

export default function ModelingFeedback(eventBus, tooltips, translate) {

Expand All @@ -28,19 +26,6 @@ export default function ModelingFeedback(eventBus, tooltips, translate) {
}
});

eventBus.on([ 'elements.paste.rejected' ], function(event) {
var context = event.context,
position = context.position,
target = context.target;

if (is(target, 'bpmn:Collaboration')) {
showError(position, translate(COLLAB_ERR_MSG));
}

if (is(target, 'bpmn:Process')) {
showError(position, translate(PROCESS_ERR_MSG), 3000);
}
});
}

ModelingFeedback.$inject = [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev": "npm test -- --auto-watch --no-single-run",
"test": "karma start test/config/karma.unit.js",
"distro": "node tasks/build-distro.js",
"collect-translations": "COLLECT_TRANSLATIONS=1 npm test",
"test:distro": "node tasks/test-distro.js",
"preversion": "run-s distro test:distro"
},
Expand Down
18 changes: 16 additions & 2 deletions test/config/karma.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var path = require('path');

var collectTranslations = process.env.COLLECT_TRANSLATIONS;

var coverage = process.env.COVERAGE;

// configures browsers to run test against
Expand All @@ -19,7 +21,8 @@ var suite = coverage ? 'test/coverageBundle.js' : 'test/testBundle.js';


module.exports = function(karma) {
karma.set({

var config = {

basePath,

Expand Down Expand Up @@ -86,5 +89,16 @@ module.exports = function(karma) {
},
devtool: 'eval-source-map'
}
});
};

if (collectTranslations) {
config.plugins = [].concat(config.plugins || [], 'karma-*', require('./translation-reporter'));
config.reporters = [].concat(config.reporters || [], 'translation-reporter');

config.envPreprocessor = [
'TRANSLATIONS'
];
}

karma.set(config);
};
8 changes: 4 additions & 4 deletions test/config/translation-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var {
function TranslationReporter() {
process.env.TRANSLATIONS = 'enabled';

var outputFile = path.join(__dirname, '../../docs/translations.json');
var translationsFile = path.join(__dirname, '../../docs/translations.json');

var translations = [];

Expand Down Expand Up @@ -38,10 +38,10 @@ function TranslationReporter() {


this.onRunComplete = function() {
translations = uniqueBy(function(e) {return e;}, translations);
translations = sortBy(translations, function(e) {return e;});
translations = uniqueBy(function(e) { return e; }, translations);
translations = sortBy(translations, function(e) { return e; });

fs.writeFileSync(outputFile, JSON.stringify(translations, null, 2));
fs.writeFileSync(translationsFile, JSON.stringify(translations, null, 2));
};
}

Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/bpmn/error/no-process-collaboration.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions
xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
id="definitions"
targetNamespace="http://bpmn.io/schema/bpmn">

<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1">
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
14 changes: 12 additions & 2 deletions test/helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ import {
import TestContainer from 'mocha-test-container-support';

import Modeler from '../../lib/Modeler';
import NavigatedViewer from '../../lib/NavigatedViewer';
import Viewer from '../../lib/Viewer';

var OPTIONS, BPMN_JS;

import translationModule from './TranslationCollector';

export var collectTranslations = window.__env__ && window.__env__.TRANSLATIONS === 'enabled';

// inject logging translation module into default modules
if (collectTranslations) {

[ Modeler, Viewer, NavigatedViewer ].forEach(function(constructor) {
constructor.prototype._modules.push(translationModule);
});
}

export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {

Expand Down Expand Up @@ -105,7 +115,7 @@ export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
}

// used to extract translations used during tests
if (window.__env__ && window.__env__.TRANSLATIONS === 'enabled') {
if (collectTranslations) {
_options.additionalModules = [].concat(
_options.additionalModules || [],
[ translationModule ]
Expand Down Expand Up @@ -278,4 +288,4 @@ export function insertCSS(name, css) {
}

head.appendChild(style);
}
}
5 changes: 3 additions & 2 deletions test/spec/ModelerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {

import {
setBpmnJS,
clearBpmnJS
clearBpmnJS,
collectTranslations
} from 'test/TestHelper';


Expand Down Expand Up @@ -156,7 +157,7 @@ describe('Modeler', function() {
});


describe('translate support', function() {
!collectTranslations && describe('translate support', function() {

var xml = require('../fixtures/bpmn/simple.bpmn');

Expand Down
15 changes: 15 additions & 0 deletions test/spec/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ describe('Viewer', function() {
});
});


it('should handle missing process/collaboration', function() {

var xml = require('../fixtures/bpmn/error/no-process-collaboration.bpmn');

// when
return createViewer(container, Viewer, xml).then(function(result) {

var err = result.error;

// then
expect(err.message).to.eql('no process or collaboration to display');
});
});

});


Expand Down
14 changes: 14 additions & 0 deletions test/spec/features/modeling/behavior/ModelingFeedback.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js" exporterVersion="7.3.0">
<collaboration id="Collaboration_1">
<participant name="Participant_1" id="Participant_1" processRef="Process_1" />
</collaboration>
<process id="Process_1" />
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
<bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="Participant_1_di" bpmnElement="Participant_1" isHorizontal="true">
<omgdc:Bounds x="160" y="80" width="420" height="180" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
57 changes: 57 additions & 0 deletions test/spec/features/modeling/behavior/ModelingFeedbackSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
bootstrapModeler,
getBpmnJS,
inject
} from 'test/TestHelper';

import {
createCanvasEvent as canvasEvent
} from 'test/util/MockEvents';

import coreModule from 'lib/core';
import modelingModule from 'lib/features/modeling';


describe('features/modeling - ModelingFeedback', function() {

var collaborationDiagramXML = require('./ModelingFeedback.bpmn');

beforeEach(bootstrapModeler(collaborationDiagramXML, {
modules: [
coreModule,
modelingModule
]
}));


it('should indicate', inject(function(create, canvas, elementFactory, dragging) {

// given
var task = elementFactory.createShape({ type: 'bpmn:Task' });

var collaboration = canvas.getRootElement();
var collaborationGfx = canvas.getGraphics(collaboration);

create.start(canvasEvent({ x: 100, y: 100 }), task);
dragging.hover({ element: collaboration, gfx: collaborationGfx });

// when
dragging.end();

// then
expectTooltip('error', 'flow elements must be children of pools/participants');
}));

});


function expectTooltip(cls, message) {

return getBpmnJS().invoke(function(canvas) {

var tooltipEl = document.querySelector('[data-tooltip-id]', canvas.getContainer());

expect(tooltipEl.textContent).to.eql(message);
expect(tooltipEl.classList.contains(cls));
});
}