Skip to content

Commit

Permalink
chore: pass search pad tokens as is
Browse files Browse the repository at this point in the history
The `search-pad` is now compatible with the new syntax.
  • Loading branch information
nikku committed Nov 1, 2024
1 parent 8819365 commit 36c610e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
17 changes: 2 additions & 15 deletions lib/features/search/BpmnSearchProvider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { map } from 'min-dash';

import {
getLabel,
isLabel
Expand Down Expand Up @@ -79,17 +77,6 @@ BpmnSearchProvider.prototype.find = function(pattern) {
*/
function toSearchPadResult(result) {

/**
* @param {SearchToken} token
*
* @return {SearchPadToken}
*/
function toSearchPadToken(token) {
return {
[ token.match ? 'matched' : 'normal' ]: token.value
};
}

const {
item: {
element
Expand All @@ -99,7 +86,7 @@ function toSearchPadResult(result) {

return {
element,
primaryTokens: map(tokens.label, toSearchPadToken),
secondaryTokens: map(tokens.id, toSearchPadToken)
primaryTokens: tokens.label,
secondaryTokens: tokens.id
};
}
53 changes: 35 additions & 18 deletions test/spec/features/search/BpmnSearchProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
inject
} from 'test/TestHelper';

import {
pick
} from 'min-dash';

import coreModule from 'lib/core';
import modelingModule from 'lib/features/modeling';
import bpmnSearchModule from 'lib/features/search';
Expand Down Expand Up @@ -72,13 +76,13 @@ describe('features - BPMN search provider', function() {
var elements = bpmnSearch.find(pattern);

// then
expect(elements[0].primaryTokens).to.eql([
{ normal: 'has matched ID' }
expectTokens(elements[0].primaryTokens, [
{ value: 'has matched ID' }
]);
expect(elements[0].secondaryTokens).to.eql([
{ normal: 'some_' },
{ matched: 'DataStore' },
{ normal: '_123456_id' }
expectTokens(elements[0].secondaryTokens, [
{ value: 'some_' },
{ value: 'DataStore', match: true },
{ value: '_123456_id' }
]);
}));

Expand Down Expand Up @@ -122,8 +126,10 @@ describe('features - BPMN search provider', function() {
var elements = bpmnSearch.find(pattern);

// then
expect(elements[0].primaryTokens).to.eql([
{ matched: 'all matched' }
expectTokens(elements[0].primaryTokens, [
{ value: 'all', match: true },
{ value: ' ' },
{ value: 'matched', match: true }
]);
}));

Expand All @@ -137,9 +143,9 @@ describe('features - BPMN search provider', function() {
var elements = bpmnSearch.find(pattern);

// then
expect(elements[0].primaryTokens).to.eql([
{ matched: 'before' },
{ normal: ' 321' }
expectTokens(elements[0].primaryTokens, [
{ value: 'before', match: true },
{ value: ' 321' }
]);
}));

Expand All @@ -153,10 +159,10 @@ describe('features - BPMN search provider', function() {
var elements = bpmnSearch.find(pattern);

// then
expect(elements[0].primaryTokens).to.eql([
{ normal: '123 ' },
{ matched: 'middle' },
{ normal: ' 321' }
expectTokens(elements[0].primaryTokens, [
{ value: '123 ' },
{ value: 'middle', match: true },
{ value: ' 321' }
]);
}));

Expand All @@ -170,9 +176,9 @@ describe('features - BPMN search provider', function() {
var elements = bpmnSearch.find(pattern);

// then
expect(elements[0].primaryTokens).to.eql([
{ normal: '123 ' },
{ matched: 'after' }
expectTokens(elements[0].primaryTokens, [
{ value: '123 ' },
{ value: 'after', match: true }
]);
}));

Expand Down Expand Up @@ -224,3 +230,14 @@ describe('features - BPMN search provider', function() {
});

});


// helpers ///////////////

function expectTokens(tokens, expectedTokens) {
const cleanTokens = tokens.map(
token => pick(token, ['value', 'match'])
);

expect(cleanTokens).to.eql(expectedTokens);
}

0 comments on commit 36c610e

Please sign in to comment.