hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Test suite for guided tour. |
| 3 | * |
| 4 | * @author Helge Stallkamp |
| 5 | */ |
| 6 | |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 7 | define(['tour/tours', 'vc', 'session'], function(tourClass, vcClass, sessionClass){ |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 8 | const loc = KorAP.Locale; |
| 9 | |
| 10 | //TODO Read this file from the file system, see https://korap.ids-mannheim.de/gerrit/#/c/KorAP/Kalamar/+/2241/ |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 11 | var introKorAP = |
| 12 | "<form autocomplete='off' action='/' id='searchform'>" + |
| 13 | "<div id='searchbar' class=''>" + |
| 14 | "<input autocapitalize='off' autocomplete='off' autocorrect='off' autofocus='autofocus' id='q-field' name='q' placeholder='Finde ...' spellcheck='false' type='search'>" + |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 15 | "<button type='submit' id='qsubmit' title='Los!'><span>Los!</span></button>" + |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 16 | "</div>" + |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 17 | "<!-- Search in the following virtual corpus -->"+ |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 18 | "<div id='vc-view'></div>" + |
| 19 | "in" + |
| 20 | "<span id='vc-choose' class='select'><span>allen Korpora</span></span>" + |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 21 | "<input id='cq' name='cq' type='text' style='display: none;'>" + |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 22 | "mit" + |
| 23 | "<span class='select'>" + |
| 24 | "<select id='ql-field' name='ql' style='display: none;'>" + |
| 25 | "<option value='poliqarp'>Poliqarp</option>" + |
| 26 | "<option value='cosmas2'>Cosmas II</option>" + |
| 27 | "<option value='annis'>Annis QL</option>" + |
| 28 | "<option value='cql'>CQL v1.2</option>" + |
| 29 | "<option value='fcsql'>FCSQL</option>" + |
| 30 | "</select>" + |
| 31 | "<span style='display: inline;'> Poliqarp</span>" + |
| 32 | "<ul style='outline: currentcolor none 0px;' tabindex='0' class='menu roll'>" + |
| 33 | "<span class='pref'></span>" + |
| 34 | "<div class='lengthField'>" + |
| 35 | "<span>Poliqarp--</span>" + |
| 36 | "<span>Cosmas II--</span>" + |
| 37 | "<span>Annis QL--</span>" + |
| 38 | "<span>CQL v1.2--</span>" + |
| 39 | "<span>FCSQL--</span>" + |
| 40 | "</div><div class='ruler' style='display: none;'><span></span><div></div>" + |
| 41 | "</div>" + |
| 42 | "</ul>" + |
| 43 | "</span>" + |
| 44 | "<div class='button right'>" + |
| 45 | "<input checked='' class='checkbox' id='q-cutoff-field' name='cutoff' type='checkbox' value='1'>" + |
| 46 | "<label for='q-cutoff-field' title='Zeige nur die ersten Treffer in beliebiger Reihenfolge'><span id='glimpse'></span>Glimpse</label>" + |
| 47 | "<a class='tutorial' id='view-tutorial' tabindex='-1' title='Einführung'><span>Einführung</span></a>"+ |
| 48 | "</div>" + |
| 49 | "<div class='clear'></div>"+ |
| 50 | "</form>" + |
| 51 | "<div class='hint mirror' style='height: 0px; left: 238px; top: 36px; width: 1272px; padding-left: 2px; margin-left: 0px; border-left-width: 2px; border-left-style: solid; font-size: 14.6667px; font-family: Noto Sans;'>" + |
| 52 | "<span></span>" + |
| 53 | "<div id='hint' class=''>" + |
| 54 | "<div style='display: none;' class='alert hint'></div>" + |
| 55 | "<ul style='outline: currentcolor none 0px;' tabindex='0' class='menu roll hint'>" + |
| 56 | "<span class='pref'></span>" + |
| 57 | "<div class='lengthField'>" + |
| 58 | "<span>Base Annotation--</span>" + |
| 59 | "<span class='desc'>Structure--</span>" + |
| 60 | "<span>DeReKo--</span><span class='desc'>Structure--</span>"+ |
| 61 | "</div>" |
| 62 | "<div class='ruler' style='display: none;'><span></span><div></div></div>" |
| 63 | "</ul>" + |
| 64 | "</div>" + |
| 65 | "</div>"; |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 66 | |
| 67 | |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 68 | var preDefinedStat={ |
| 69 | "documents":12, |
| 70 | "tokens":2323, |
| 71 | "sentences":343434, |
| 72 | "paragraphs":45454545 |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | KorAP.API.getCorpStat = function(collQu, cb){ |
| 77 | return cb(preDefinedStat); |
| 78 | }; |
| 79 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 80 | |
| 81 | let template = document.createElement('template'); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 82 | let html = introKorAP.trim(); // Do not return a text node of whitespace as the result |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 83 | template.innerHTML = html; |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 84 | let intrkorap = template.content; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 85 | |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 86 | let vc= vcClass.create().fromJson({ |
| 87 | '@type' : 'koral:doc', |
| 88 | 'key' : 'title', |
| 89 | 'match': 'match:eq', |
| 90 | 'value' : 'TestTour!', |
| 91 | 'type' : 'type:string' |
| 92 | }); |
| 93 | |
| 94 | KorAP.vc = vc; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 95 | //TODO Add hint and vc-choose, they are not part of the generated file |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 96 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 97 | describe('KorAP.GuidedTour', function(){ |
| 98 | it('IDs and classes, that are needed for the guided tour should be in existence', function(){ |
| 99 | expect(intrkorap.querySelector('#searchbar')).not.toBeNull(); |
| 100 | expect(intrkorap.querySelector('#q-field')).not.toBeNull(); |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 101 | expect(intrkorap.querySelector('#hint')).not.toBeNull(); |
| 102 | expect(intrkorap.querySelector('#vc-choose')).not.toBeNull(); |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 103 | expect(intrkorap.querySelector('#vc-view')).not.toBeNull(); |
| 104 | expect(intrkorap.querySelector('#ql-field').parentNode).not.toBeNull(); |
Akron | e9e5e83 | 2019-04-02 14:56:23 +0200 | [diff] [blame] | 105 | expect(intrkorap.querySelector('#glimpse')).not.toBeNull(); |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 106 | expect(intrkorap.querySelector('#view-tutorial')).not.toBeNull(); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 107 | expect(intrkorap.querySelector('#qsubmit')).not.toBeNull(); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 108 | let show = document.createElement('div'); |
hebasta | d090a51 | 2019-07-10 16:36:01 +0200 | [diff] [blame] | 109 | show.appendChild(vc.element()); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 110 | let statbut = show.querySelector('.statistic'); |
| 111 | expect(statbut).not.toBeNull(); |
| 112 | statbut.click(); |
| 113 | expect(show.querySelector('.stattable')).not.toBeNull(); |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 114 | }); |
| 115 | |
| 116 | |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 117 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 118 | it('Guided Tour should be started and display steps and labels in the right order', function(){ |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 119 | |
| 120 | let vcpanel = intrkorap.getElementById("vc-view"); |
| 121 | vcpanel.appendChild(vc.element()); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 122 | let searchTour = tourClass.gTstartSearch(intrkorap); |
| 123 | searchTour.start(); |
| 124 | let totalSteps = searchTour.stepCount; |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 125 | expect(document.querySelector(".introjs-tooltiptext").textContent).toEqual(loc.TOUR_sear1); |
| 126 | expect(document.querySelector(".introjs-skipbutton").textContent).toEqual(loc.TOUR_lskip); |
| 127 | expect(document.querySelector(".introjs-prevbutton").textContent).toEqual(loc.TOUR_lprev); |
| 128 | expect(document.querySelector(".introjs-nextbutton").textContent).toEqual(loc.TOUR_lnext); |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 129 | searchTour.exit(); |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 130 | |
| 131 | for(let i = 2; i <= totalSteps; i++){ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 132 | searchTour.goToStepNumber(i); |
| 133 | expect(document.querySelector(".introjs-tooltiptext").textContent).toEqual(searchTour.testIntros[i-1]); |
hebasta | 94e47cb | 2019-07-24 22:24:27 +0200 | [diff] [blame] | 134 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 135 | if(i == totalSteps){ |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 136 | expect(document.querySelector(".introjs-donebutton").textContent).toEqual(loc.TOUR_seargo); |
| 137 | expect(document.querySelector(".introjs-prevbutton").textContent).toEqual(loc.TOUR_lprev); |
| 138 | expect(document.querySelector(".introjs-nextbutton").classList.contains("introjs-disabled")).toBe(true); |
hebasta | 0c93d8e | 2019-05-15 12:06:16 +0200 | [diff] [blame] | 139 | } |
hebasta | 5df796f | 2019-05-21 15:27:12 +0200 | [diff] [blame] | 140 | searchTour.exit(); |
| 141 | } |
| 142 | |
| 143 | let resultTour = tourClass.gTshowResults(intrkorap); |
| 144 | KorAP.session = sessionClass.create('KalamarJSDem'); |
| 145 | resultTour.start(); |
| 146 | expect(document.querySelector(".introjs-tooltiptext").textContent).toEqual(loc.TOUR_result); |
| 147 | expect(document.querySelector(".introjs-donebutton").textContent).toEqual(loc.TOUR_ldone); |
| 148 | resultTour.exit(); |
| 149 | |
hebasta | 75cfca5 | 2019-02-19 13:15:27 +0100 | [diff] [blame] | 150 | }); |
| 151 | }); |
| 152 | } |
| 153 | ); |