Skip to content

Commit 205c3b6

Browse files
committed
additional testing of alternative text search
1 parent ba24e83 commit 205c3b6

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

test/basic.spec.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,45 @@ describe('basic suite', function() {
8080
expect(select.val()).toBe('banana');
8181
});
8282

83+
it('should not search a disabled option', function() {
84+
select.find('option:eq(4)').prop('disabled', 'disabled');
85+
select.selectric('refresh');
86+
$('.selectric-input').val('banana').trigger('input');
87+
$('.selectric-items').find('.highlighted').lenght;
88+
expect($('.selectric-items').find('.highlighted').length).toBe(0);
89+
});
90+
8391
it('should search alternative text', function () {
84-
$('.selectric-input').val('alt banana').trigger('input');
92+
select.find('option:eq(6)').attr('data-alt', 'alt blackberry');
93+
select.selectric('refresh');
94+
$('.selectric-input').val('alt blackberry').trigger('input');
8595
$('.selectric-items').find('.highlighted').click();
86-
expect(select.val()).toBe('banana');
96+
expect(select.val()).toBe('blackberry');
8797
});
8898

8999
it('should search alternative text with separator', function () {
90-
$('.selectric-input').val('altberry').trigger('input');
100+
select.find('option:eq(6)').attr('data-alt', 'alt blackberry | another berry');
101+
select.selectric('refresh');
102+
$('.selectric-input').val('alt blackberry').trigger('input');
91103
$('.selectric-items').find('.highlighted').click();
92-
expect(select.val()).toBe('bilberry');
104+
expect(select.val()).toBe('blackberry');
93105
});
94106

95107
it('should search alternative text with separator 2', function () {
108+
select.find('option:eq(6)').attr('data-alt', 'alt blackberry | another berry');
109+
select.selectric('refresh');
96110
$('.selectric-input').val('another berry').trigger('input');
97111
$('.selectric-items').find('.highlighted').click();
98-
expect(select.val()).toBe('bilberry');
112+
expect(select.val()).toBe('blackberry');
99113
});
100114

115+
it('should skip blank alternative text', function () {
116+
select.find('option:eq(6)').attr('data-alt', '');
117+
select.selectric('refresh');
118+
$('.selectric-input').val('a text that does not exist').trigger('input');
119+
expect($('.selectric-items').find('.highlighted').length).toBe(0);
120+
});
121+
101122
it('highlight() should return undefined if index is undefined', function () {
102123
expect(select.data('selectric').highlight(undefined)).toBe(undefined);
103124
});

test/fixtures/basic.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<option value="loooooooooooooong-option">Loooooooooooooong option</option>
55
<option value="apple">Apple</option>
66
<option selected value="apricot">Apricot</option>
7-
<option class="customOptionClass" value="banana"data-alt="alt banana">Banana</option>
8-
<option value="bilberry" data-alt="altberry | another berry">Bilberry</option>
7+
<option class="customOptionClass" value="banana">Banana</option>
8+
<option value="bilberry">Bilberry</option>
99
<option value="blackberry">Blackberry</option>
1010
<option value="blackcurrant">Blackcurrant</option>
1111
<option value="blueberry">Blueberry</option>

0 commit comments

Comments
 (0)