sphinx/tests/js/sphinx_highlight.spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.9 KiB
JavaScript
Raw Normal View History

Drop JavaScript Frameworks (#10028) * Delete jQuery and underscore.js * Move underscores.js setup to searchtools.js * Update jQuery.url(en|de)code * Update jQuery.getQueryParameters * Firefox bug is no longer present xref https://bugzilla.mozilla.org/show_bug.cgi?id=645075#c49 * Update jQuery.fn.highlightText * Use enum instead of magic number * Update test descriptions to remove obsolete jQuery reference * Update Documentation.getCurrentURL * Revert accidental fix of Documentation.getCurrentURL * Update Documentation.initOnKeyListeners * Update Documentation.hideSearchWords * Update Documentation.highlightSearchWords * Update Documentation.initDomainIndexTable * Use arrow functions and const * Replace $(document).ready * Strict mode * Move Documentation.hideSearchWords next to Documentation.highlightSearchWords * Update translation functions in Documentation * Replace $(document).ready in searchtools.js * Update Scorer * Update Search.hasIndex, Search.deferQuery, Search.stopPulse * Prefer window.location * Update Search.init * Update Search.loadIndex * Update Search.setIndex * Update Search.startPulse * Add _escapeRegExp * Update Search.makeSearchSummary * Update Search.htmlToText * Update Search.performSearch * Factor out _displayNextItem * Update Search.query * Update Search.performObjectSearch * Update Search.performTermsSearch * Remove underscores.js setup * Use Sets * Update test configuration * Fix test failures * Drop unused make/get URL functions * Strict mode in searchtools.js * Remove outmoded check for jQuery and underscore.js * Ran prettier prettier --print-width 120 --no-semi --quote-props as-needed --no-bracket-spacing --arrow-parens avoid --write sphinx/themes/basic/static * Remove more references to jQuery and underscore.js * Remove jQuery and underscore.js licences * Update classic theme for no jQuery * Update all other themes for no jQuery * Restore jQuery & underscores.js to Sphinx themes Enables a more gradual deprecation * Added deprecation note to CHANGES * Run prettier with defaults * Update deprecation message to include extensions, note that sources must be copied * oops * Address Pradyun's feedback * Forgot this one * `let` doesn't work, as it is scoped to the block... * Remove missed jQuery in sphinx13 theme
2022-01-30 13:27:12 -06:00
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);
});
Drop JavaScript Frameworks (#10028) * Delete jQuery and underscore.js * Move underscores.js setup to searchtools.js * Update jQuery.url(en|de)code * Update jQuery.getQueryParameters * Firefox bug is no longer present xref https://bugzilla.mozilla.org/show_bug.cgi?id=645075#c49 * Update jQuery.fn.highlightText * Use enum instead of magic number * Update test descriptions to remove obsolete jQuery reference * Update Documentation.getCurrentURL * Revert accidental fix of Documentation.getCurrentURL * Update Documentation.initOnKeyListeners * Update Documentation.hideSearchWords * Update Documentation.highlightSearchWords * Update Documentation.initDomainIndexTable * Use arrow functions and const * Replace $(document).ready * Strict mode * Move Documentation.hideSearchWords next to Documentation.highlightSearchWords * Update translation functions in Documentation * Replace $(document).ready in searchtools.js * Update Scorer * Update Search.hasIndex, Search.deferQuery, Search.stopPulse * Prefer window.location * Update Search.init * Update Search.loadIndex * Update Search.setIndex * Update Search.startPulse * Add _escapeRegExp * Update Search.makeSearchSummary * Update Search.htmlToText * Update Search.performSearch * Factor out _displayNextItem * Update Search.query * Update Search.performObjectSearch * Update Search.performTermsSearch * Remove underscores.js setup * Use Sets * Update test configuration * Fix test failures * Drop unused make/get URL functions * Strict mode in searchtools.js * Remove outmoded check for jQuery and underscore.js * Ran prettier prettier --print-width 120 --no-semi --quote-props as-needed --no-bracket-spacing --arrow-parens avoid --write sphinx/themes/basic/static * Remove more references to jQuery and underscore.js * Remove jQuery and underscore.js licences * Update classic theme for no jQuery * Update all other themes for no jQuery * Restore jQuery & underscores.js to Sphinx themes Enables a more gradual deprecation * Added deprecation note to CHANGES * Run prettier with defaults * Update deprecation message to include extensions, note that sources must be copied * oops * Address Pradyun's feedback * Forgot this one * `let` doesn't work, as it is scoped to the block... * Remove missed jQuery in sphinx13 theme
2022-01-30 13:27:12 -06:00
it('should highlight text incl. special characters correctly in SVG', function() {
const highlightTestSvg = new DOMParser().parseFromString(
'<span id="svg-highlight-test">' +
2018-08-04 16:49:48 -05:00
'<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">' +
Drop JavaScript Frameworks (#10028) * Delete jQuery and underscore.js * Move underscores.js setup to searchtools.js * Update jQuery.url(en|de)code * Update jQuery.getQueryParameters * Firefox bug is no longer present xref https://bugzilla.mozilla.org/show_bug.cgi?id=645075#c49 * Update jQuery.fn.highlightText * Use enum instead of magic number * Update test descriptions to remove obsolete jQuery reference * Update Documentation.getCurrentURL * Revert accidental fix of Documentation.getCurrentURL * Update Documentation.initOnKeyListeners * Update Documentation.hideSearchWords * Update Documentation.highlightSearchWords * Update Documentation.initDomainIndexTable * Use arrow functions and const * Replace $(document).ready * Strict mode * Move Documentation.hideSearchWords next to Documentation.highlightSearchWords * Update translation functions in Documentation * Replace $(document).ready in searchtools.js * Update Scorer * Update Search.hasIndex, Search.deferQuery, Search.stopPulse * Prefer window.location * Update Search.init * Update Search.loadIndex * Update Search.setIndex * Update Search.startPulse * Add _escapeRegExp * Update Search.makeSearchSummary * Update Search.htmlToText * Update Search.performSearch * Factor out _displayNextItem * Update Search.query * Update Search.performObjectSearch * Update Search.performTermsSearch * Remove underscores.js setup * Use Sets * Update test configuration * Fix test failures * Drop unused make/get URL functions * Strict mode in searchtools.js * Remove outmoded check for jQuery and underscore.js * Ran prettier prettier --print-width 120 --no-semi --quote-props as-needed --no-bracket-spacing --arrow-parens avoid --write sphinx/themes/basic/static * Remove more references to jQuery and underscore.js * Remove jQuery and underscore.js licences * Update classic theme for no jQuery * Update all other themes for no jQuery * Restore jQuery & underscores.js to Sphinx themes Enables a more gradual deprecation * Added deprecation note to CHANGES * Run prettier with defaults * Update deprecation message to include extensions, note that sources must be copied * oops * Address Pradyun's feedback * Forgot this one * `let` doesn't work, as it is scoped to the block... * Remove missed jQuery in sphinx13 theme
2022-01-30 13:27:12 -06:00
'<text x="0" y="15">' +
'This is the шеллы and Gänsefüßchen test!' +
2018-08-04 16:49:48 -05:00
'</text>' +
Drop JavaScript Frameworks (#10028) * Delete jQuery and underscore.js * Move underscores.js setup to searchtools.js * Update jQuery.url(en|de)code * Update jQuery.getQueryParameters * Firefox bug is no longer present xref https://bugzilla.mozilla.org/show_bug.cgi?id=645075#c49 * Update jQuery.fn.highlightText * Use enum instead of magic number * Update test descriptions to remove obsolete jQuery reference * Update Documentation.getCurrentURL * Revert accidental fix of Documentation.getCurrentURL * Update Documentation.initOnKeyListeners * Update Documentation.hideSearchWords * Update Documentation.highlightSearchWords * Update Documentation.initDomainIndexTable * Use arrow functions and const * Replace $(document).ready * Strict mode * Move Documentation.hideSearchWords next to Documentation.highlightSearchWords * Update translation functions in Documentation * Replace $(document).ready in searchtools.js * Update Scorer * Update Search.hasIndex, Search.deferQuery, Search.stopPulse * Prefer window.location * Update Search.init * Update Search.loadIndex * Update Search.setIndex * Update Search.startPulse * Add _escapeRegExp * Update Search.makeSearchSummary * Update Search.htmlToText * Update Search.performSearch * Factor out _displayNextItem * Update Search.query * Update Search.performObjectSearch * Update Search.performTermsSearch * Remove underscores.js setup * Use Sets * Update test configuration * Fix test failures * Drop unused make/get URL functions * Strict mode in searchtools.js * Remove outmoded check for jQuery and underscore.js * Ran prettier prettier --print-width 120 --no-semi --quote-props as-needed --no-bracket-spacing --arrow-parens avoid --write sphinx/themes/basic/static * Remove more references to jQuery and underscore.js * Remove jQuery and underscore.js licences * Update classic theme for no jQuery * Update all other themes for no jQuery * Restore jQuery & underscores.js to Sphinx themes Enables a more gradual deprecation * Added deprecation note to CHANGES * Run prettier with defaults * Update deprecation message to include extensions, note that sources must be copied * oops * Address Pradyun's feedback * Forgot this one * `let` doesn't work, as it is scoped to the block... * Remove missed jQuery in sphinx13 theme
2022-01-30 13:27:12 -06:00
'</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));
});
});