2020-05-29 19:05:44 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
2020-07-15 19:48:07 +08:00
|
|
|
import {
|
|
|
|
waitForHighlighting,
|
|
|
|
setupHighlightJs
|
|
|
|
} from "discourse/lib/highlight-syntax";
|
2020-05-29 19:05:44 +08:00
|
|
|
|
2020-07-07 23:51:19 +08:00
|
|
|
const LONG_CODE_BLOCK = "puts a\n".repeat(15000);
|
|
|
|
|
2020-05-29 19:05:44 +08:00
|
|
|
moduleForComponent("highlighted-code", { integration: true });
|
|
|
|
|
|
|
|
componentTest("highlighting code", {
|
|
|
|
template: "{{highlighted-code lang='ruby' code=code}}",
|
|
|
|
|
|
|
|
beforeEach() {
|
2020-07-15 19:48:07 +08:00
|
|
|
setupHighlightJs({
|
|
|
|
highlightJsUrl: "/assets/highlightjs/highlight-test-bundle.min.js",
|
|
|
|
highlightJsWorkerUrl: "/assets/highlightjs-worker.js"
|
|
|
|
});
|
2020-05-29 19:05:44 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
async test(assert) {
|
2020-07-15 19:48:07 +08:00
|
|
|
this.set("code", "def test; end");
|
|
|
|
await waitForHighlighting();
|
2020-05-29 19:05:44 +08:00
|
|
|
assert.equal(
|
|
|
|
find("code.ruby.hljs .hljs-function .hljs-keyword")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"def"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2020-07-07 23:51:19 +08:00
|
|
|
|
2020-07-15 19:48:07 +08:00
|
|
|
componentTest("highlighting code limit", {
|
2020-07-07 23:51:19 +08:00
|
|
|
template: "{{highlighted-code lang='ruby' code=code}}",
|
|
|
|
|
|
|
|
beforeEach() {
|
2020-07-15 19:48:07 +08:00
|
|
|
setupHighlightJs({
|
|
|
|
highlightJsUrl: "/assets/highlightjs/highlight-test-bundle.min.js",
|
|
|
|
highlightJsWorkerUrl: "/assets/highlightjs-worker.js"
|
|
|
|
});
|
2020-07-07 23:51:19 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
async test(assert) {
|
2020-07-15 19:48:07 +08:00
|
|
|
this.set("code", LONG_CODE_BLOCK);
|
|
|
|
await waitForHighlighting();
|
2020-07-07 23:51:19 +08:00
|
|
|
assert.equal(
|
|
|
|
find("code")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
LONG_CODE_BLOCK.trim()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|