2016-03-27 14:04:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-01-24 10:41:21 +00:00
|
|
|
var coreModule = require('lib/core'),
|
|
|
|
modelingModule = require('lib/features/modeling'),
|
|
|
|
bpmnSearchModule = require('lib/features/search');
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
/* global bootstrapViewer, inject */
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// 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) {
|
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) {
|
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) {
|
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) {
|
|
|
|
// 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) {
|
|
|
|
// 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) {
|
|
|
|
// 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) {
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|