Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 1 | define( |
| 2 | ['selectMenu'], |
| 3 | function (selectMenuClass) { |
| 4 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 5 | /* |
| 6 | * Check for preselected values |
| 7 | */ |
| 8 | |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 9 | describe('KorAP.SelectMenu', function () { |
| 10 | var list = [ |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 11 | { |
| 12 | content : 'Poliqarp', |
| 13 | value : 'poliqarp', |
| 14 | desc : 'The Polish National Corpus QL' |
| 15 | }, |
| 16 | { |
| 17 | content : 'Cosmas II', |
| 18 | value : 'cosmas2', |
| 19 | desc : 'The Polish National Corpus QL' |
| 20 | }, |
| 21 | { |
| 22 | content : 'Annis', |
| 23 | value : 'annis' |
| 24 | }, |
| 25 | { |
| 26 | content : 'CQL v1.2', |
| 27 | value : 'cql' |
| 28 | } |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 29 | ]; |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 30 | |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 31 | it('should replace a select element', function () { |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 32 | var div = document.createElement('div'); |
| 33 | var element = div.appendChild(document.createElement('select')); |
| 34 | for (i in list) { |
| 35 | var opt = element.appendChild(document.createElement('option')); |
| 36 | opt.setAttribute('value', list[i].value); |
| 37 | opt.appendChild(document.createTextNode(list[i].content)); |
| 38 | }; |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 39 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 40 | var menu = selectMenuClass.create(div); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 41 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 42 | expect(element.style.display).toEqual('none'); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 43 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 44 | // This selects the first item |
| 45 | expect(menu.select()).toEqual(0); |
| 46 | expect(menu._title.textContent).toEqual('Poliqarp'); |
| 47 | |
| 48 | // Now show the menu |
| 49 | menu.showSelected(); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 50 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 51 | expect(menu.item(0).active()).toBe(true); |
| 52 | expect(menu.item(0).noMore()).toBe(true); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 53 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 54 | // TODO: Improve lcfield!!!!!! |
| 55 | expect(menu.shownItem(0).lcField()).toEqual(' poliqarp'); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 56 | }); |
Akron | 7f613e0 | 2016-11-07 02:50:44 +0100 | [diff] [blame] | 57 | |
| 58 | it('should first show the selected value', function () { |
| 59 | var div = document.createElement('div'); |
| 60 | var element = div.appendChild(document.createElement('select')); |
| 61 | for (i in list) { |
| 62 | var opt = element.appendChild(document.createElement('option')); |
| 63 | opt.setAttribute('value', list[i].value); |
| 64 | opt.appendChild(document.createTextNode(list[i].content)); |
| 65 | }; |
| 66 | |
| 67 | expect(element.selectedIndex).toEqual(0); |
| 68 | |
| 69 | // Select annis |
| 70 | element.children[2].selected = true; |
| 71 | |
| 72 | expect(element.selectedIndex).toEqual(2); |
| 73 | |
| 74 | var menu = selectMenuClass.create(div); |
| 75 | menu.show(3); |
| 76 | expect(menu._title.textContent).toEqual('Annis'); |
| 77 | }); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 78 | }); |
| 79 | } |
| 80 | ); |