diff options
author | Timotheus Kampik <timotheus.kampik@gmail.com> | 2018-08-04 23:49:48 +0200 |
---|---|---|
committer | Timotheus Kampik <timotheus.kampik@gmail.com> | 2018-08-05 10:45:21 +0200 |
commit | 97fd09177c617543f8272eaaf7fb9799c94067db (patch) | |
tree | 9ecb6b1b3ee4678c14e02fb9dc906c59e7949001 | |
parent | b66ea577e813ee3496806710b2ac8a01b73c46fa (diff) | |
download | sphinx-git-97fd09177c617543f8272eaaf7fb9799c94067db.tar.gz |
#5258 add tests for highlightText()
-rw-r--r-- | tests/js/doctools.js | 92 |
1 files changed, 73 insertions, 19 deletions
diff --git a/tests/js/doctools.js b/tests/js/doctools.js index 8533f7148..c569bcb8a 100644 --- a/tests/js/doctools.js +++ b/tests/js/doctools.js @@ -1,32 +1,86 @@ var DOCUMENTATION_OPTIONS = {}; -describe('urldecode', function() { - it('should correctly decode URLs and replace `+`s with a spaces', function() { - var test_encoded_string = - '%D1%88%D0%B5%D0%BB%D0%BB%D1%8B+%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'; - var test_decoded_string = 'шеллы шеллы'; - expect(jQuery.urldecode(test_encoded_string)).toEqual(test_decoded_string); +describe('jQuery extensions', function() { + + describe('urldecode', function() { + + it('should correctly decode URLs and replace `+`s with a spaces', function() { + var test_encoded_string = + '%D1%88%D0%B5%D0%BB%D0%BB%D1%8B+%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'; + var test_decoded_string = 'шеллы шеллы'; + expect(jQuery.urldecode(test_encoded_string)).toEqual(test_decoded_string); + }); + }); -}); + describe('getQueryParameters', function() { + var paramString = '?q=test+this&check_keywords=yes&area=default'; + var queryParamObject = { + area: ['default'], + check_keywords: ['yes'], + q: ['test this'] + }; + + it('should correctly create query parameter object from string', function() { + expect(jQuery.getQueryParameters(paramString)).toEqual(queryParamObject); + }); -describe('getQueryParameters', function() { - var paramString = '?q=test+this&check_keywords=yes&area=default'; - var queryParamObject = { - area: ['default'], - check_keywords: ['yes'], - q: ['test this'] - }; + it('should correctly create query param object from URL params', function() { + history.pushState({}, '_', window.location + paramString); + expect(jQuery.getQueryParameters()).toEqual(queryParamObject); + }); - it('should correctly create query parameter object from string', function() { - expect(jQuery.getQueryParameters(paramString)).toEqual(queryParamObject); }); - it('should correctly create query param object from URL params', function() { - history.pushState({}, '_', window.location + paramString); - expect(jQuery.getQueryParameters()).toEqual(queryParamObject); + describe('highlightText', function() { + + var cyrillicTerm = 'шеллы'; + var umlautTerm = 'gänsefüßchen'; + + it('should highlight text incl. special characters correctly in HTML', function() { + var highlightTestSpan = + jQuery('<span>This is the шеллы and Gänsefüßchen test!</span>'); + jQuery(document.body).append(highlightTestSpan); + highlightTestSpan.highlightText(cyrillicTerm, 'highlighted'); + highlightTestSpan.highlightText(umlautTerm, 'highlighted'); + var expectedHtmlString = + 'This is the <span class=\"highlighted\">шеллы</span> and ' + + '<span class=\"highlighted\">Gänsefüßchen</span> test!'; + expect(highlightTestSpan.html()).toEqual(expectedHtmlString); + }); + + it('should highlight text incl. special characters correctly in SVG', function() { + var highlightTestSvg = jQuery( + '<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>'); + $("#svg-highlight-test").html($("#svg-highlight-test").html()); + jQuery(document.body).append(highlightTestSvg); + highlightTestSvg.highlightText(cyrillicTerm, 'highlighted'); + highlightTestSvg.highlightText(umlautTerm, 'highlighted'); + var expectedSvgString = + '<svg xmlns="http://www.w3.org/2000/svg" height="50" width="500">' + + '<rect x="-0.5" y="3" width="271.683" height="16" class="highlighted">' + + '</rect>' + + '<rect x="-0.5" y="3" width="271.683" height="16" class="highlighted">' + + '</rect>' + + '<text x="0" y="15">' + + 'This is the ' + + '<tspan>шеллы</tspan> and ' + + '<tspan>Gänsefüßchen</tspan> test!' + + '</text>' + + '</svg>'; + expect(highlightTestSvg.html()).toEqual(expectedSvgString); + }); + }); + }); + |