diff --git a/ui/tests/.eslintrc.js b/ui/tests/.eslintrc.js index 7cf1e81db..0d333ae8e 100644 --- a/ui/tests/.eslintrc.js +++ b/ui/tests/.eslintrc.js @@ -5,6 +5,7 @@ module.exports = { selectSearch: true, removeMultipleOption: true, clearSelected: true, + getCodeMirrorInstance: true, }, env: { embertest: true, diff --git a/ui/tests/helpers/codemirror.js b/ui/tests/helpers/codemirror.js new file mode 100644 index 000000000..87db0c814 --- /dev/null +++ b/ui/tests/helpers/codemirror.js @@ -0,0 +1,19 @@ +import { registerHelper } from '@ember/test'; + +const invariant = (truthy, error) => { + if (!truthy) throw new Error(error); +}; + +export default function registerCodeMirrorHelpers() { + registerHelper('getCodeMirrorInstance', function(app, selector) { + const cmService = app.__container__.lookup('service:code-mirror'); + + const element = document.querySelector(selector); + invariant(element, `Selector ${selector} matched no elements`); + + const cm = cmService.instanceFor(element.id); + invariant(cm, `No registered CodeMirror instance for ${selector}`); + + return cm; + }); +} diff --git a/ui/tests/helpers/start-app.js b/ui/tests/helpers/start-app.js index 304c6e377..496f7190a 100644 --- a/ui/tests/helpers/start-app.js +++ b/ui/tests/helpers/start-app.js @@ -3,8 +3,10 @@ import { merge } from '@ember/polyfills'; import Application from '../../app'; import config from '../../config/environment'; import registerPowerSelectHelpers from 'ember-power-select/test-support/helpers'; +import registerCodeMirrorHelpers from 'nomad-ui/tests/helpers/codemirror'; registerPowerSelectHelpers(); +registerCodeMirrorHelpers(); export default function startApp(attrs) { let attributes = merge({}, config.APP);