Skip to content

Commit

Permalink
test: fix lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed Nov 2, 2019
1 parent d4b3c6c commit a8519ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
31 changes: 17 additions & 14 deletions elements/sifrr-code-editor/src/sifrrcodeeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ class SifrrCodeEditor extends SifrrDom.Element {
}

cmLoaded() {
SifrrDom.Loader.executeJS(
`https://cdn.jsdelivr.net/npm/codemirror@${CM_VERSION}/mode/${this.getLang()}/${this.getLang()}.js`
).then(() => {
this.cm = window.CodeMirror.fromTextArea(this.$('textarea'), {
value: this.$('textarea').value,
mode: this.getLang(),
htmlMode: true,
theme: this.getTheme(),
indentUnit: 2,
tabSize: 2,
lineNumbers: true
this.loading =
this.loading ||
SifrrDom.Loader.executeJS(
`https://cdn.jsdelivr.net/npm/codemirror@${CM_VERSION}/mode/${this.getLang()}/${this.getLang()}.js`
).then(() => {
this.cm = window.CodeMirror.fromTextArea(this.$('textarea'), {
value: this.$('textarea').value,
mode: this.getLang(),
htmlMode: true,
theme: this.getTheme(),
indentUnit: 2,
tabSize: 2,
lineNumbers: true
});
this.cm.on('change', this.setValueFromCm.bind(this));
this._cmLoaded = true;
});
this.cm.on('change', this.setValueFromCm.bind(this));
this._cmLoaded = true;
});
return this.loading;
}

getTheme() {
Expand Down
3 changes: 2 additions & 1 deletion elements/sifrr-code-editor/test/browser/loading.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
async function assertValue(selector, value) {
await page.$eval(selector, async el => await el.cmLoaded());

const value0 = await page.$eval(selector, el => el.value);
expect(value0).to.be.equal(value);

Expand All @@ -13,7 +15,6 @@ describe('code editor', function() {
before(async () => {
await page.goto(`${PATH}/codeeditor.html`);
await page.evaluate(async () => await Sifrr.Dom.loading());
await page.evaluate(async () => await Sifrr.Dom.elements['sifrr-code-editor'].cm());
});

it('loads code editor', async function() {
Expand Down

0 comments on commit a8519ad

Please sign in to comment.