blob: 5f0c909a8f8eff56820d802c6bdcea8171d1f3fd [file] [log] [blame]
Akronad894832016-06-08 18:24:48 +02001define(
2 ['selectMenu'],
3 function (selectMenuClass) {
4
Akronaba7a5a2016-08-15 21:58:33 +02005 /*
6 * Check for preselected values
7 */
8
Akronad894832016-06-08 18:24:48 +02009 describe('KorAP.SelectMenu', function () {
10 var list = [
Akronaba7a5a2016-08-15 21:58:33 +020011 {
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 }
Akronad894832016-06-08 18:24:48 +020029 ];
Akronaba7a5a2016-08-15 21:58:33 +020030
Akronad894832016-06-08 18:24:48 +020031 it('should replace a select element', function () {
Akronaba7a5a2016-08-15 21:58:33 +020032 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 };
Akronad894832016-06-08 18:24:48 +020039
Akronaba7a5a2016-08-15 21:58:33 +020040 var menu = selectMenuClass.create(div);
Akronad894832016-06-08 18:24:48 +020041
Akronaba7a5a2016-08-15 21:58:33 +020042 expect(element.style.display).toEqual('none');
Akronad894832016-06-08 18:24:48 +020043
Akronaba7a5a2016-08-15 21:58:33 +020044 // 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();
Akronad894832016-06-08 18:24:48 +020050
Akronaba7a5a2016-08-15 21:58:33 +020051 expect(menu.item(0).active()).toBe(true);
52 expect(menu.item(0).noMore()).toBe(true);
Akronad894832016-06-08 18:24:48 +020053
Akronaba7a5a2016-08-15 21:58:33 +020054 // TODO: Improve lcfield!!!!!!
55 expect(menu.shownItem(0).lcField()).toEqual(' poliqarp');
Akronad894832016-06-08 18:24:48 +020056 });
57 });
58 }
59);