This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/components/highlighted-code-test.js
Robin Ward 435a9913a4 REFACTOR: Replace global find with queryAll
In newer Embers jQuery is removed. There is a `find` but it only returns
one element and not a jQuery selector. This patch migrates our code to a
new helper `queryAll` which allows us to remove the global.
2020-10-29 14:45:51 -04:00

39 lines
1.0 KiB
JavaScript

import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { moduleForComponent } from "ember-qunit";
import componentTest from "discourse/tests/helpers/component-test";
const LONG_CODE_BLOCK = "puts a\n".repeat(15000);
moduleForComponent("highlighted-code", { integration: true });
componentTest("highlighting code", {
template: "{{highlighted-code lang='ruby' code=code}}",
beforeEach() {
this.session.highlightJsPath =
"assets/highlightjs/highlight-test-bundle.min.js";
this.set("code", "def test; end");
},
test(assert) {
assert.equal(
queryAll("code.ruby.hljs .hljs-function .hljs-keyword").text().trim(),
"def"
);
},
});
componentTest("large code blocks are not highlighted", {
template: "{{highlighted-code lang='ruby' code=code}}",
beforeEach() {
this.session.highlightJsPath =
"assets/highlightjs/highlight-test-bundle.min.js";
this.set("code", LONG_CODE_BLOCK);
},
test(assert) {
assert.equal(queryAll("code").text().trim(), LONG_CODE_BLOCK.trim());
},
});