2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapViewer,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
|
|
|
|
|
|
|
import coreModule from 'lib/core';
|
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import bpmnSearchModule from 'lib/features/search';
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features - BPMN search provider', function() {
|
|
|
|
|
|
|
|
var testModules = [
|
|
|
|
coreModule,
|
|
|
|
modelingModule,
|
|
|
|
bpmnSearchModule
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
describe(' - with collaboration as root - ', function() {
|
|
|
|
var diagramXML = require('./bpmn-search-collaboration.bpmn');
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
it('should not return root element (collaboration)', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// given
|
|
|
|
var pattern = 'collaboration';
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// then
|
|
|
|
expect(elements).to.have.length(0);
|
|
|
|
}));
|
|
|
|
});
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
describe(' - with process as root - ', function() {
|
|
|
|
var diagramXML = require('./bpmn-search.bpmn');
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
it('find should return all elements that match label or ID', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-03-27 14:04:07 +00:00
|
|
|
// given
|
2016-05-18 08:42:38 +00:00
|
|
|
var pattern = '123456';
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
2016-05-18 08:42:38 +00:00
|
|
|
expect(elements).length(3);
|
|
|
|
elements.forEach(function(e) {
|
|
|
|
expect(e).to.have.property('element');
|
|
|
|
expect(e).to.have.property('primaryTokens');
|
|
|
|
expect(e).to.have.property('secondaryTokens');
|
|
|
|
});
|
2016-03-27 14:04:07 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
it('matches IDs', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-03-27 14:04:07 +00:00
|
|
|
// given
|
2016-05-18 08:42:38 +00:00
|
|
|
var pattern = 'datastore';
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements[0].primaryTokens).to.eql([
|
2016-06-07 06:46:45 +00:00
|
|
|
{ normal: 'has matched ID' }
|
2016-05-18 08:42:38 +00:00
|
|
|
]);
|
|
|
|
expect(elements[0].secondaryTokens).to.eql([
|
2016-06-07 06:46:45 +00:00
|
|
|
{ normal: 'some_' },
|
|
|
|
{ matched: 'DataStore' },
|
|
|
|
{ normal: '_123456_id' }
|
2016-03-27 14:04:07 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
it('should not return root element (process)', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-03-27 14:04:07 +00:00
|
|
|
// given
|
2016-05-18 08:42:38 +00:00
|
|
|
var pattern = 'process';
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
2016-05-18 08:42:38 +00:00
|
|
|
expect(elements).to.have.length(0);
|
2016-03-27 14:04:07 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
describe('should split result into matched and non matched tokens', function() {
|
|
|
|
|
|
|
|
it('matched all', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// given
|
|
|
|
var pattern = 'all matched';
|
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements[0].primaryTokens).to.eql([
|
2016-06-07 06:46:45 +00:00
|
|
|
{ matched: 'all matched' }
|
2016-05-18 08:42:38 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('matched start', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// given
|
|
|
|
var pattern = 'before';
|
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements[0].primaryTokens).to.eql([
|
2016-06-07 06:46:45 +00:00
|
|
|
{ matched: 'before' },
|
|
|
|
{ normal: ' 321' }
|
2016-05-18 08:42:38 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('matched middle', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// given
|
|
|
|
var pattern = 'middle';
|
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements[0].primaryTokens).to.eql([
|
2016-06-07 06:46:45 +00:00
|
|
|
{ normal: '123 ' },
|
|
|
|
{ matched: 'middle' },
|
|
|
|
{ normal: ' 321' }
|
2016-05-18 08:42:38 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('matched end', inject(function(bpmnSearch) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-05-18 08:42:38 +00:00
|
|
|
// given
|
|
|
|
var pattern = 'after';
|
|
|
|
|
|
|
|
// when
|
|
|
|
var elements = bpmnSearch.find(pattern);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements[0].primaryTokens).to.eql([
|
2016-06-07 06:46:45 +00:00
|
|
|
{ normal: '123 ' },
|
|
|
|
{ matched: 'after' }
|
2016-05-18 08:42:38 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|