Skip to content

Commit c2ae5b0

Browse files
committed
add test for preselected value
1 parent ca47650 commit c2ae5b0

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

_SpecRunner.html

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
<script src="bin/materialize.js"></script>
3232

33+
<script src="tests/spec/cards/cardsSpec.js"></script>
34+
35+
<script src="tests/spec/collapsible/collapsibleSpec.js"></script>
36+
3337
<script src="tests/spec/select/selectSpec.js"></script>
3438

3539
<script src=".grunt/grunt-contrib-jasmine/reporter.js"></script>

tests/spec/select/selectFixture.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="row">
22
<div class="input-field col s12">
33
<select class="normal">
4-
<option value="" disabled selected>Choose your option</option>
4+
<option value="" disabled>Choose your option</option>
55
<option value="1">Option 1</option>
66
<option value="2">Option 2</option>
7-
<option value="3">Option 3</option>
7+
<option value="3" selected>Option 3</option>
88
</select>
99
<label>Materialize Select</label>
1010
</div>

tests/spec/select/selectSpec.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("Select Plugin", function () {
1313
$('select').not('.disabled').material_select();
1414
});
1515

16-
it("should open select dropdown", function (done) {
16+
it("should open dropdown and select option", function (done) {
1717
normalInput = browserSelect.parent().find('input.select-dropdown');
1818
normalDropdown = browserSelect.parent().find('ul.select-dropdown');
1919

@@ -26,8 +26,25 @@ describe("Select Plugin", function () {
2626

2727
setTimeout(function() {
2828
expect(normalDropdown).toBeVisible('Should be visible after opening.');
29-
done();
29+
var firstOption = normalDropdown.find('li:not(.disabled)').first();
30+
firstOption.click();
31+
normalInput.blur();
32+
33+
setTimeout(function() {
34+
expect(normalDropdown).toBeHidden('Should be hidden after choosing item.');
35+
expect(normalInput.val()).toEqual(firstOption[0].innerText, 'Value should equal chosen option.');
36+
done();
37+
}, 400);
3038
}, 400);
3139
});
40+
41+
it("should have pre-selected value", function () {
42+
normalInput = browserSelect.parent().find('input.select-dropdown');
43+
normalDropdown = browserSelect.parent().find('ul.select-dropdown');
44+
45+
var firstOption = browserSelect.find('option[selected]');
46+
console.log(normalInput.val(), firstOption.text());
47+
expect(normalInput.val()).toEqual(firstOption.text(), 'Value should be equal to preselected option.');
48+
});
3249
});
3350
});

0 commit comments

Comments
 (0)