mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: remove word boundary regex (\b) for search result highlights. (#9338)
This commit is contained in:
@@ -94,13 +94,13 @@ QUnit.test("Search with context", async assert => {
|
||||
|
||||
const highlighted = [];
|
||||
|
||||
find("#post_7 span.highlight-strong").map((_, span) => {
|
||||
find("#post_7 span.highlighted").map((_, span) => {
|
||||
highlighted.push(span.innerText);
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
highlighted,
|
||||
["a", "a", "proper", "a"],
|
||||
["a proper"],
|
||||
"it should highlight the post with the search terms correctly"
|
||||
);
|
||||
|
||||
|
||||
48
test/javascripts/lib/highlight-search-test.js.es6
Normal file
48
test/javascripts/lib/highlight-search-test.js.es6
Normal file
@@ -0,0 +1,48 @@
|
||||
import highlightSearch, { CLASS_NAME } from "discourse/lib/highlight-search";
|
||||
import { fixture } from "helpers/qunit-helpers";
|
||||
|
||||
QUnit.module("lib:highlight-search");
|
||||
|
||||
QUnit.test("highlighting text", 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"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("highlighting unicode text", 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"
|
||||
);
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
import highlightText, { CLASS_NAME } from "discourse/lib/highlight-text";
|
||||
import { fixture } from "helpers/qunit-helpers";
|
||||
|
||||
QUnit.module("lib:highlight-text");
|
||||
|
||||
QUnit.test("highlighting text", assert => {
|
||||
fixture().html(
|
||||
`
|
||||
<p>This is some text to highlight</p>
|
||||
`
|
||||
);
|
||||
|
||||
highlightText(fixture(), "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"
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user