diff options
Diffstat (limited to 'tests/js/searchtools.js')
-rw-r--r-- | tests/js/searchtools.js | 99 |
1 files changed, 98 insertions, 1 deletions
diff --git a/tests/js/searchtools.js b/tests/js/searchtools.js index c9e0c43..4f9984d 100644 --- a/tests/js/searchtools.js +++ b/tests/js/searchtools.js @@ -21,7 +21,59 @@ describe('Basic html theme search', function() { "<no title>", "", null, - 2, + 5, + "index.rst" + ]]; + expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits); + }); + + it('should be able to search for multiple terms', function() { + index = { + alltitles: { + 'Main Page': [[0, 'main-page']], + }, + docnames:["index"], + filenames:["index.rst"], + terms:{main:0, page:0}, + titles:["Main Page"], + titleterms:{ main:0, page:0 } + } + Search.setIndex(index); + + searchterms = ['main', 'page']; + excluded = []; + terms = index.terms; + titleterms = index.titleterms; + hits = [[ + 'index', + 'Main Page', + '', + null, + 15, + 'index.rst']]; + expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits); + }); + + it('should partially-match "sphinx" when in title index', function() { + index = { + docnames:["index"], + filenames:["index.rst"], + terms:{'useful': 0, 'utilities': 0}, + titles:["sphinx_utils module"], + titleterms:{'sphinx_utils': 0} + } + Search.setIndex(index); + searchterms = ['sphinx']; + excluded = []; + terms = index.terms; + titleterms = index.titleterms; + + hits = [[ + "index", + "sphinx_utils module", + "", + null, + 7, "index.rst" ]]; expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits); @@ -31,6 +83,51 @@ describe('Basic html theme search', function() { }); +describe("htmlToText", function() { + + const testHTML = `<html> + <body> + <script src="directory/filename.js"></script> + <div class="body" role="main"> + <script> + console.log('dynamic'); + </script> + <style> + div.body p.centered { + text-align: center; + margin-top: 25px; + } + </style> + <!-- main content --> + <section id="getting-started"> + <h1>Getting Started</h1> + <p>Some text</p> + </section> + <section id="other-section"> + <h1>Other Section</h1> + <p>Other text</p> + </section> + <section id="yet-another-section"> + <h1>Yet Another Section</h1> + <p>More text</p> + </section> + </div> + </body> + </html>`; + + it("basic case", () => { + expect(Search.htmlToText(testHTML).trim().split(/\s+/)).toEqual([ + 'Getting', 'Started', 'Some', 'text', + 'Other', 'Section', 'Other', 'text', + 'Yet', 'Another', 'Section', 'More', 'text' + ]); + }); + + it("will start reading from the anchor", () => { + expect(Search.htmlToText(testHTML, '#other-section').trim().split(/\s+/)).toEqual(['Other', 'Section', 'Other', 'text']); + }); +}); + // This is regression test for https://github.com/sphinx-doc/sphinx/issues/3150 describe('splitQuery regression tests', () => { |