blob: 5e4dca6c51cf6114e49502486c1282e6cf373679 [file] [log] [blame]
hebasta75cfca52019-02-19 13:15:27 +01001/**
2 * Test suite for guided tour.
3 *
4 * @author Helge Stallkamp
5 */
6
7define(['tour/tours', 'vc'], function(tourClass, vcClass){
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/
11 var introKorAP = "<form autocomplete='off' action='/' id='searchform'>" +
12 "<div id='searchbar'>" +
13 "<input autocapitalize='off' autocomplete='off ' autocorrect='off' autofocus='autofocus' id='q-field' name='q' placeholder='Find ...' spellcheck='false' type='search'>" +
14 "<button type='submit' title='Go!'><span>Go!</span></button>" +
15 "</div>"+
16 "<!-- Search in the following virtual collection -->"+
17 "<div id='vc-view'></div>" +
18 "in" +
19 "<input id='collection' name='collection' type='text'>" +
20 "with" +
21 "<span class='select'>" +
22 "<select id='ql-field' name='ql'><option value='poliqarp'>Poliqarp</option><option value='cosmas2'>Cosmas II</option><option value='annis'>Annis QL</option><option value='cql'>CQL v1.2</option><option value='fcsql'>FCSQL</option></select>" +
23 "</span>" +
24 "<div class='button right'>" +
25 "<input checked class='checkbox' id='q-cutoff-field' name='cutoff' type='checkbox' value='1'>"+
Akrone9e5e832019-04-02 14:56:23 +020026 "<label for='q-cutoff-field' title='Just show the first matches in arbitrary order'><span id='glimpse'></span>Glimpse</label>" +
hebasta75cfca52019-02-19 13:15:27 +010027 "<a class='tutorial' href='/doc' id='view-tutorial' tabindex='-1' title='Tutorial'><span>Tutorial</span></a>" +
28 "</div>" +
29 "<div class='clear'></div>" +
30 "</form>";
31
32 let template = document.createElement('template');
33 html = introKorAP.trim(); // Do not return a text node of whitespace as the result
34 template.innerHTML = html;
35 intrkorap = template.content.firstChild;
36
37
38 //TODO Add hint and vc-choose, they are not part of the generated file
39 describe('KorAP.GuidedTour', function(){
40 it('IDs and classes, that are needed for the guided tour should be in existence', function(){
41 expect(intrkorap.querySelector('#searchbar')).not.toBeNull();
42 expect(intrkorap.querySelector('#q-field')).not.toBeNull();
43 //expect(intrkorap.querySelector('#hint')).not.toBeNull();
44 //expect(intrkorap.querySelector('#vc-choose')).not.toBeNull();
45 expect(intrkorap.querySelector('#vc-view')).not.toBeNull();
46 expect(intrkorap.querySelector('#ql-field').parentNode).not.toBeNull();
Akrone9e5e832019-04-02 14:56:23 +020047 expect(intrkorap.querySelector('#glimpse')).not.toBeNull();
hebasta75cfca52019-02-19 13:15:27 +010048 expect(intrkorap.querySelector('#view-tutorial')).not.toBeNull();
49 expect(intrkorap.querySelector('#searchbar button[type=submit]')).not.toBeNull();
50 });
51
52
53 it('Guided Tour should be started and display steps and labels in the right order', function(){
54 let testTour = tourClass.guidedTour(intrkorap);
55 testTour.start();
56 let totalSteps = testTour.stepCount;
57
58 expect(document.querySelector(".introjs-tooltiptext").textContent).toEqual(loc.TOUR_sear1);
59 expect(document.querySelector(".introjs-skipbutton").textContent).toEqual(loc.TOUR_lskip);
60 expect(document.querySelector(".introjs-prevbutton").textContent).toEqual(loc.TOUR_lprev);
61 expect(document.querySelector(".introjs-nextbutton").textContent).toEqual(loc.TOUR_lnext);
62 testTour.exit();
63
64 for(let i = 2; i <= totalSteps; i++){
65 testTour.goToStepNumber(i);
66 expect(document.querySelector(".introjs-tooltiptext").textContent).toEqual(testTour.testIntros[i-1]);
67 if(i == totalSteps){
68 expect(document.querySelector('.introjs-donebutton').textContent).toEqual(loc.TOUR_ldone);
69 }
70 testTour.exit();
71 }
72 });
73 });
74}
75);