Skip to content

Commit

Permalink
test: prevent test from breaking on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgoulart committed Feb 12, 2025
1 parent bbe3595 commit 1c165ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/form-js-playground/src/components/JSONEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,21 @@ export function JSONEditor(options = {}) {
function createPlaceholderLinterExtension() {
return linter((view) => {
const placeholders = view.dom.querySelectorAll('.cm-placeholder');
if (placeholders.length > 0) {
domClasses(container, document.body).add(NO_LINT_CLS);
} else {
domClasses(container, document.body).remove(NO_LINT_CLS);

try {
if (placeholders.length > 0) {
domClasses(container, document.body).add(NO_LINT_CLS);
} else {
domClasses(container, document.body).remove(NO_LINT_CLS);
}
} catch (e) {
console.log(view.dom);
console.log(container);
console.log(document.body);
console.log(domClasses);
console.debug('Failed to update editor classes:', e);
}

return [];
});
}
Expand Down
19 changes: 19 additions & 0 deletions packages/form-js-playground/test/spec/JSONEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import { JSONEditor } from '../../src/components/JSONEditor';
import { currentCompletions, startCompletion } from '@codemirror/autocomplete';

describe('JSONEditor', function () {
let testContainer;

beforeEach(function () {
testContainer = document.createElement('div');
document.body.appendChild(testContainer);
});

afterEach(function () {
if (testContainer && testContainer.parentNode) {
testContainer.parentNode.removeChild(testContainer);
}
});

describe('#setValue', function () {
it('should accept external change', async function () {
// given
Expand Down Expand Up @@ -287,6 +300,7 @@ describe('JSONEditor', function () {
const variables = ['foobar', 'baz'];

const editor = new JSONEditor();
editor.attachTo(document.body);
editor.setValue(initialValue);
editor.setVariables(variables);

Expand All @@ -311,6 +325,8 @@ describe('JSONEditor', function () {
expect(completionDisplayLabels).to.include('"foobar"');
expect(completionDisplayLabels).to.include('"baz"');
});

editor.destroy();
});

it('should suggest property completion after comma', async function () {
Expand All @@ -319,6 +335,7 @@ describe('JSONEditor', function () {
const variables = ['foobar', 'baz'];

const editor = new JSONEditor();
editor.attachTo(document.body);
editor.setValue(initialValue);
editor.setVariables(variables);

Expand All @@ -343,6 +360,8 @@ describe('JSONEditor', function () {
expect(completionDisplayLabels).to.include('"foobar"');
expect(completionDisplayLabels).to.include('"baz"');
});

editor.destroy();
});
});
});
Expand Down

0 comments on commit 1c165ce

Please sign in to comment.