summaryrefslogtreecommitdiffstats
path: root/tests/js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
commitcf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch)
tree18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/js
parentInitial commit. (diff)
downloadsphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz
sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip
Adding upstream version 7.2.6.upstream/7.2.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/js')
-rw-r--r--tests/js/documentation_options.js1
-rw-r--r--tests/js/searchtools.js62
-rw-r--r--tests/js/sphinx_highlight.js39
3 files changed, 102 insertions, 0 deletions
diff --git a/tests/js/documentation_options.js b/tests/js/documentation_options.js
new file mode 100644
index 0000000..e736460
--- /dev/null
+++ b/tests/js/documentation_options.js
@@ -0,0 +1 @@
+const DOCUMENTATION_OPTIONS = {};
diff --git a/tests/js/searchtools.js b/tests/js/searchtools.js
new file mode 100644
index 0000000..c9e0c43
--- /dev/null
+++ b/tests/js/searchtools.js
@@ -0,0 +1,62 @@
+describe('Basic html theme search', function() {
+
+ describe('terms search', function() {
+
+ it('should find "C++" when in index', function() {
+ index = {
+ docnames:["index"],
+ filenames:["index.rst"],
+ terms:{'c++':0},
+ titles:["&lt;no title&gt;"],
+ titleterms:{}
+ }
+ Search.setIndex(index);
+ searchterms = ['c++'];
+ excluded = [];
+ terms = index.terms;
+ titleterms = index.titleterms;
+
+ hits = [[
+ "index",
+ "&lt;no title&gt;",
+ "",
+ null,
+ 2,
+ "index.rst"
+ ]];
+ expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
+ });
+
+ });
+
+});
+
+// This is regression test for https://github.com/sphinx-doc/sphinx/issues/3150
+describe('splitQuery regression tests', () => {
+
+ it('can split English words', () => {
+ const parts = splitQuery(' Hello World ')
+ expect(parts).toEqual(['Hello', 'World'])
+ })
+
+ it('can split special characters', () => {
+ const parts = splitQuery('Pin-Code')
+ expect(parts).toEqual(['Pin', 'Code'])
+ })
+
+ it('can split Chinese characters', () => {
+ const parts = splitQuery('Hello from 中国 上海')
+ expect(parts).toEqual(['Hello', 'from', '中国', '上海'])
+ })
+
+ it('can split Emoji (surrogate pair) characters. It should keep emojis.', () => {
+ const parts = splitQuery('😁😁')
+ expect(parts).toEqual(['😁😁'])
+ })
+
+ it('can split umlauts. It should keep umlauts.', () => {
+ const parts = splitQuery('Löschen Prüfung Abändern ærlig spørsmål')
+ expect(parts).toEqual(['Löschen', 'Prüfung', 'Abändern', 'ærlig', 'spørsmål'])
+ })
+
+})
diff --git a/tests/js/sphinx_highlight.js b/tests/js/sphinx_highlight.js
new file mode 100644
index 0000000..1f52eab
--- /dev/null
+++ b/tests/js/sphinx_highlight.js
@@ -0,0 +1,39 @@
+describe('highlightText', function() {
+
+ const cyrillicTerm = 'шеллы';
+ const umlautTerm = 'gänsefüßchen';
+
+ it('should highlight text incl. special characters correctly in HTML', function() {
+ const highlightTestSpan = new DOMParser().parseFromString(
+ '<span>This is the шеллы and Gänsefüßchen test!</span>', 'text/html').body.firstChild
+ _highlightText(highlightTestSpan, cyrillicTerm, 'highlighted');
+ _highlightText(highlightTestSpan, umlautTerm, 'highlighted');
+ const expectedHtmlString =
+ 'This is the <span class=\"highlighted\">шеллы</span> and ' +
+ '<span class=\"highlighted\">Gänsefüßchen</span> test!';
+ expect(highlightTestSpan.innerHTML).toEqual(expectedHtmlString);
+ });
+
+ it('should highlight text incl. special characters correctly in SVG', function() {
+ const highlightTestSvg = new DOMParser().parseFromString(
+ '<span id="svg-highlight-test">' +
+ '<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">' +
+ '<text x="0" y="15">' +
+ 'This is the шеллы and Gänsefüßchen test!' +
+ '</text>' +
+ '</svg>' +
+ '</span>', 'text/html').body.firstChild
+ _highlightText(highlightTestSvg, cyrillicTerm, 'highlighted');
+ _highlightText(highlightTestSvg, umlautTerm, 'highlighted');
+ /* Note wild cards and ``toMatch``; allowing for some variability
+ seems to be necessary, even between different FF versions */
+ const expectedSvgString =
+ '<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">'
+ + '<rect x=".*" y=".*" width=".*" height=".*" class="highlighted"/>'
+ + '<rect x=".*" y=".*" width=".*" height=".*" class="highlighted"/>'
+ + '<text x=".*" y=".*">This is the <tspan>шеллы</tspan> and '
+ + '<tspan>Gänsefüßchen</tspan> test!</text></svg>';
+ expect(new XMLSerializer().serializeToString(highlightTestSvg.firstChild)).toMatch(new RegExp(expectedSvgString));
+ });
+
+});