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/unit/lib/highlight-search-test.js
Jarek Radosz 1b52cdedb1
DEV: Move more tests into modules (#11119)
Models, services, mixins, utilities, and most of the controllers
2020-11-05 20:23:28 +01:00

50 lines
1.2 KiB
JavaScript

import highlightSearch, { CLASS_NAME } from "discourse/lib/highlight-search";
import { fixture } from "discourse/tests/helpers/qunit-helpers";
import { module, test } from "qunit";
module("Unit | Utility | highlight-search", function () {
test("highlighting text", function (assert) {
fixture().html(
`
<p>This is some text to highlight</p>
`
);
highlightSearch(fixture()[0], "some text");
const terms = [];
fixture(`.${CLASS_NAME}`).each((_, elem) => {
terms.push(elem.textContent);
});
assert.equal(
terms.join(" "),
"some text",
"it should highlight the terms correctly"
);
});
test("highlighting unicode text", function (assert) {
fixture().html(
`
<p>This is some தமிழ் & русский text to highlight</p>
`
);
highlightSearch(fixture()[0], "தமிழ் & русский");
const terms = [];
fixture(`.${CLASS_NAME}`).each((_, elem) => {
terms.push(elem.textContent);
});
assert.equal(
terms.join(" "),
"தமிழ் & русский",
"it should highlight the terms correctly"
);
});
});