Skip to content

Commit

Permalink
test: use spy to check if variables were retrieved
Browse files Browse the repository at this point in the history
Closes #873
  • Loading branch information
barmac committed May 27, 2024
1 parent 5f97076 commit 019298e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/dmn-js-literal-expression/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"literal expression"
],
"devDependencies": {
"@testing-library/dom": "^10.1.0",
"dmn-font": "^0.6.2",
"inferno-test-utils": "~5.6.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global sinon */

import { bootstrapModeler, inject } from 'test/helper';

import { query as domQuery } from 'min-dom';

import { DmnVariableResolverModule } from '@bpmn-io/dmn-variable-resolver';

import { queryEditor } from 'dmn-js-shared/test/util/EditorUtil';

import ExpressionLanguagesModule from 'dmn-js-shared/lib/features/expression-languages';
Expand All @@ -12,8 +12,6 @@ import { triggerInputEvent } from 'dmn-js-shared/test/util/EventUtil';

import TestContainer from 'mocha-test-container-support';

import { waitFor } from '@testing-library/dom';

import literalExpressionXML from '../../literal-expression.dmn';

import CoreModule from 'src/core';
Expand All @@ -25,13 +23,21 @@ import ModelingModule from 'src/features/modeling';

describe('textarea editor', function() {

const variableResolver = {
getVariables: () => [
{ name: 'Variable', typeRef: 'string' }
]
};

beforeEach(bootstrapModeler(literalExpressionXML, {
modules: [
CoreModule,
TextareaEditorModule,
ModelingModule,
ExpressionLanguagesModule,
DmnVariableResolverModule
{
variableResolver: [ 'value', variableResolver ]
}
],
debounceInput: false
}));
Expand Down Expand Up @@ -90,26 +96,23 @@ describe('textarea editor', function() {

describe('integration', function() {

afterEach(function() {
sinon.restore();
});


it('should pass variables to editor', async function() {

// given
const getVariablesSpy = sinon.spy(variableResolver, 'getVariables');
const editor = queryEditor('.textarea', testContainer);
await changeFocus(editor);

// when
await changeInput(document.activeElement, 'Var');

// then
return waitFor(() => {
const options = testContainer.querySelectorAll('[role="option"]');

expect(options).to.exist;
expect(options).to.satisfy(options => {
const result = Array.from(options).some(
option => option.textContent === 'Variable');
return result;
});
});
expect(getVariablesSpy).to.have.been.called;
});
});

Expand Down

0 comments on commit 019298e

Please sign in to comment.