Blame view

bower_components/Materialize/tests/spec/select/selectSpec.js 8.28 KB
a1a3bc73   Luigi Serra   graphs updates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  describe("Select Plugin", function () {
    beforeEach(function() {
      loadFixtures('select/selectFixture.html');
      $('select').not('.disabled').material_select();
    });
  
    describe("Select", function () {
      var browserSelect, normalInput, normalDropdown;
  
      beforeEach(function() {
        browserSelect = $('select.normal');
      });
  
      it("should open dropdown and select option", function (done) {
        normalInput = browserSelect.parent().find('input.select-dropdown');
        normalDropdown = browserSelect.parent().find('ul.select-dropdown');
  
        expect(normalInput).toExist('Should dynamically generate select dropdown structure.');
        expect(normalDropdown).toExist('Should dynamically generate select dropdown structure.');
        expect(normalInput).toBeVisible('Should be hidden before dropdown is opened.');
        expect(normalDropdown).toBeHidden('Should be hidden before dropdown is opened.');
  
        normalInput.click();
  
        setTimeout(function() {
          expect(normalDropdown).toBeVisible('Should be visible after opening.');
          var firstOption = normalDropdown.find('li:not(.disabled)').first();
          firstOption.click();
          normalInput.blur();
  
          setTimeout(function() {
            expect(normalDropdown).toBeHidden('Should be hidden after choosing item.');
            expect(normalInput.val()).toEqual(firstOption[0].innerText, 'Value should equal chosen option.');
            done();
          }, 400);
        }, 400);
      });
  
      it("should have pre-selected value", function () {
        normalInput = browserSelect.parent().find('input.select-dropdown');
        normalDropdown = browserSelect.parent().find('ul.select-dropdown');
  
        var firstOption = browserSelect.find('option[selected]');
        expect(normalInput.val()).toEqual(firstOption.text(), 'Value should be equal to preselected option.');
      });
    });
  
    describe("Multiple Select", function () {
      var browserSelect, multipleInput, multipleDropdown;
  
      beforeEach(function() {
        browserSelect = $('select.multiple');
      });
  
      it("should open dropdown and select multiple options", function(done) {
        multipleInput = browserSelect.parent().find('input.select-dropdown');
        multipleDropdown = browserSelect.parent().find('ul.select-dropdown');
  
        expect(multipleInput).toExist('Should dynamically generate select dropdown structure.');
        expect(multipleDropdown).toExist('Should dynamically generate select dropdown structure.');
        expect(multipleInput).toBeVisible('Should be hidden before dropdown is opened.');
        expect(multipleDropdown).toBeHidden('Should be hidden before dropdown is opened.');
  
        multipleInput.click();
  
        setTimeout(function() {
          expect(multipleDropdown).toBeVisible('Should be visible after opening.');
          var firstOption = multipleDropdown.find('li:not(.disabled)').first();
          var secondOption = multipleDropdown.find('li:not(.disabled)').eq(1);
          var thirdOption = multipleDropdown.find('li:not(.disabled)').eq(2);
          firstOption.click();
          $('body').click();
  
          setTimeout(function() {
            expect(multipleDropdown).toBeHidden('Should be hidden after choosing item.');
            expect(browserSelect.val()).toEqual(['1', '2', '3'], 'Actual select should have correct selected values.');
            expect(multipleInput.val()).toEqual(secondOption[0].innerText + ', ' + thirdOption[0].innerText + ', ' + firstOption[0].innerText, 'Value should equal chosen multiple options.');
            done();
          }, 400);
        }, 400);
      });
  
      it("should open dropdown and deselect multiple options", function(done) {
        multipleInput = browserSelect.parent().find('input.select-dropdown');
        multipleDropdown = browserSelect.parent().find('ul.select-dropdown');
  
        expect(multipleInput).toExist('Should dynamically generate select dropdown structure.');
        expect(multipleDropdown).toExist('Should dynamically generate select dropdown structure.');
        expect(multipleInput).toBeVisible('Should be hidden before dropdown is opened.');
        expect(multipleDropdown).toBeHidden('Should be hidden before dropdown is opened.');
  
        multipleInput.click();
  
        setTimeout(function() {
          expect(multipleDropdown).toBeVisible('Should be visible after opening.');
          var disabledOption = multipleDropdown.find('li.disabled');
          var secondOption = multipleDropdown.find('li:not(.disabled)').eq(1);
          var thirdOption = multipleDropdown.find('li:not(.disabled)').eq(2);
          secondOption.click();
          thirdOption.click();
          $('body').click();
  
          setTimeout(function() {
            expect(multipleDropdown).toBeHidden('Should be hidden after choosing item.');
            expect(browserSelect.val()).toEqual(null, 'Actual select element should be empty because none chosen.');
            expect(multipleInput.val()).toEqual(disabledOption[0].innerText, 'Value should equal default because none chosen.');
            done();
          }, 400);
        }, 400);
      });
  
      it("should have multiple pre-selected values", function () {
        multipleInput = browserSelect.parent().find('input.select-dropdown');
        multipleDropdown = browserSelect.parent().find('ul.select-dropdown');
  
        var secondOption = browserSelect.find('option[selected]').eq(0);
        var thirdOption = browserSelect.find('option[selected]').eq(1);
        expect(multipleInput.val()).toEqual(secondOption.text() + ', ' + thirdOption.text(), 'Value should be equal to preselected option.');
      });
    });
  
    describe("Optgroup Select", function () {
      var browserSelect, optInput, optDropdown;
  
      beforeEach(function() {
        browserSelect = $('select.optgroup');
      });
  
      it("should open dropdown and select options", function(done) {
        optInput = browserSelect.parent().find('input.select-dropdown');
        optDropdown = browserSelect.parent().find('ul.select-dropdown');
  
        var optgroups = optDropdown.find('li.optgroup');
        browserSelect.find('optgroup').each(function(i) {
          expect($(this).attr('label')).toEqual(optgroups.eq(i)[0].innerText, 'should generate optgroup structure.');
        });
  
        expect(optInput).toExist('Should dynamically generate select dropdown structure.');
        expect(optDropdown).toExist('Should dynamically generate select dropdown structure.');
        expect(optInput).toBeVisible('Should be hidden before dropdown is opened.');
        expect(optDropdown).toBeHidden('Should be hidden before dropdown is opened.');
  
        optInput.click();
  
        setTimeout(function() {
          expect(optDropdown).toBeVisible('Should be visible after opening.');
          var secondOption = optDropdown.find('li:not(.disabled):not(.optgroup)').eq(1);
          secondOption.click();
          optInput.blur();
  
          setTimeout(function() {
            expect(optDropdown).toBeHidden('Should be hidden after choosing item.');
            expect(optInput.val()).toEqual(secondOption[0].innerText, 'Value should be equal to selected option.');
            done();
          }, 400);
        }, 400);
      });
  
      it("should not do anything when optgroup li clicked", function(done) {
        optInput = browserSelect.parent().find('input.select-dropdown');
        optDropdown = browserSelect.parent().find('ul.select-dropdown');
        var originalVal = optInput.val();
  
        var optgroups = optDropdown.find('li.optgroup');
        browserSelect.find('optgroup').each(function(i) {
          expect($(this).attr('label')).toEqual(optgroups.eq(i)[0].innerText, 'should generate optgroup structure.');
        });
  
        expect(optInput).toExist('Should dynamically generate select dropdown structure.');
        expect(optDropdown).toExist('Should dynamically generate select dropdown structure.');
        expect(optInput).toBeVisible('Should be hidden before dropdown is opened.');
        expect(optDropdown).toBeHidden('Should be hidden before dropdown is opened.');
  
        optInput.click();
  
        setTimeout(function() {
          expect(optDropdown).toBeVisible('Should be visible after opening.');
          var optgroup = optDropdown.find('li.optgroup').first();
          optgroup.click();
          optInput.blur();
  
          setTimeout(function() {
            expect(optDropdown).toBeHidden('Should be hidden after choosing invalid item.');
            expect(optInput.val()).toEqual(originalVal, 'Value should be equal to original option.');
            done();
          }, 400);
        }, 400);
      });
  
    });
  });