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 | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame^] | 30 | |
| 31 | function _selectE() { |
| 32 | var div = document.createElement('div'); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 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 | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame^] | 39 | return div; |
| 40 | }; |
| 41 | |
| 42 | it('should replace a select element', function () { |
| 43 | var div = _selectE(); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 44 | var menu = selectMenuClass.create(div); |
Akron | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame^] | 45 | var element = div.firstChild; |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 46 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 47 | expect(element.style.display).toEqual('none'); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 48 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 49 | // This selects the first item |
| 50 | expect(menu.select()).toEqual(0); |
| 51 | expect(menu._title.textContent).toEqual('Poliqarp'); |
| 52 | |
| 53 | // Now show the menu |
| 54 | menu.showSelected(); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 55 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 56 | expect(menu.item(0).active()).toBe(true); |
| 57 | expect(menu.item(0).noMore()).toBe(true); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 58 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 59 | // TODO: Improve lcfield!!!!!! |
| 60 | expect(menu.shownItem(0).lcField()).toEqual(' poliqarp'); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 61 | }); |
Akron | 7f613e0 | 2016-11-07 02:50:44 +0100 | [diff] [blame] | 62 | |
Akron | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame^] | 63 | |
Akron | 7f613e0 | 2016-11-07 02:50:44 +0100 | [diff] [blame] | 64 | it('should first show the selected value', function () { |
Akron | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame^] | 65 | var div = _selectE(); |
| 66 | var element = div.firstChild; |
Akron | 7f613e0 | 2016-11-07 02:50:44 +0100 | [diff] [blame] | 67 | |
| 68 | expect(element.selectedIndex).toEqual(0); |
| 69 | |
| 70 | // Select annis |
| 71 | element.children[2].selected = true; |
| 72 | |
| 73 | expect(element.selectedIndex).toEqual(2); |
| 74 | |
| 75 | var menu = selectMenuClass.create(div); |
| 76 | menu.show(3); |
| 77 | expect(menu._title.textContent).toEqual('Annis'); |
| 78 | }); |
Akron | 086fe5d | 2017-11-13 14:01:45 +0100 | [diff] [blame^] | 79 | |
| 80 | it('should be selectable via method', function () { |
| 81 | var div = _selectE(); |
| 82 | var element = div.firstChild; |
| 83 | var menu = selectMenuClass.create(div); |
| 84 | |
| 85 | expect(element.selectedIndex).toEqual(0); |
| 86 | menu.selectValue('annis'); |
| 87 | expect(element.selectedIndex).toEqual(2); |
| 88 | }); |
Akron | ad89483 | 2016-06-08 18:24:48 +0200 | [diff] [blame] | 89 | }); |
| 90 | } |
| 91 | ); |