diff --git a/js/src/select.js b/js/src/select.js index 7d5bac0..5804ceb 100644 --- a/js/src/select.js +++ b/js/src/select.js @@ -64,16 +64,16 @@ export default class uSelect { } this.hasAllOption = true; const index = this.hasHead ? 1 : 0; - this.element.add(new Option(this.allText, 'all'), index); + this.element.add(new Option(this.allText, uSelect.allValue), index); } hideAllOption() { this.hasAllOption = false; - this.remove('all'); + this.remove(uSelect.allValue); } addHead() { - const head = new Option(this.headText, '0', true, true); + const head = new Option(this.headText, uSelect.headValue, true, true); head.disabled = true; this.element.options.add(head, 0); } @@ -115,10 +115,18 @@ export default class uSelect { this.addHead(); } if (this.hasAllOption) { - this.element.add(new Option(this.allText, 'all', false, selected === 'all')); + this.element.add(new Option(this.allText, uSelect.allValue, false, selected === uSelect.allValue)); } for (const option of options) { this.element.add(new Option(option.listText, option.listValue, false, selected === option.listValue)); } } + + static get allValue() { + return 'all'; + } + + static get headValue() { + return '0'; + } } diff --git a/js/test/select.test.js b/js/test/select.test.js index a5b96dc..2d11e5a 100644 --- a/js/test/select.test.js +++ b/js/test/select.test.js @@ -67,7 +67,7 @@ describe('Select tests', () => { expect(select.element.options[0].defaultSelected).toBe(true); expect(select.element.options[0].selected).toBe(true); expect(select.element.options[0].text).toBe(head); - expect(select.element.options[0].value).toBe('0'); + expect(select.element.options[0].value).toBe(uSelect.headValue); }); it('should construct class instance and set options', () => { @@ -119,7 +119,7 @@ describe('Select tests', () => { expect(select.element.options[0].defaultSelected).toBe(true); expect(select.element.options[0].selected).toBe(true); expect(select.element.options[0].text).toBe(head); - expect(select.element.options[0].value).toBe('0'); + expect(select.element.options[0].value).toBe(uSelect.headValue); expect(select.element.options[1].disabled).toBe(false); expect(select.element.options[1].defaultSelected).toBe(false); expect(select.element.options[1].selected).toBe(false); @@ -143,7 +143,7 @@ describe('Select tests', () => { expect(select.element.options[0].defaultSelected).toBe(true); expect(select.element.options[0].selected).toBe(false); expect(select.element.options[0].text).toBe(head); - expect(select.element.options[0].value).toBe('0'); + expect(select.element.options[0].value).toBe(uSelect.headValue); expect(select.element.options[1].disabled).toBe(false); expect(select.element.options[1].defaultSelected).toBe(false); expect(select.element.options[1].selected).toBe(false); @@ -179,7 +179,7 @@ describe('Select tests', () => { select.setOptions(options, options[1].listValue); // then expect(select.element.options.length).toBe(3); - expect(select.element.options[0].value).toBe('all'); + expect(select.element.options[0].value).toBe(uSelect.allValue); expect(select.element.options[0].text).toBe(allText); expect(select.element.options[2].selected).toBe(true); }); @@ -195,7 +195,7 @@ describe('Select tests', () => { select.showAllOption(allText); // then expect(select.element.options.length).toBe(3); - expect(select.element.options[0].value).toBe('all'); + expect(select.element.options[0].value).toBe(uSelect.allValue); expect(select.element.options[0].text).toBe(allText); expect(select.element.options[2].selected).toBe(true); // when @@ -219,9 +219,9 @@ describe('Select tests', () => { select.setOptions(options, options[1].listValue); // then expect(select.element.options.length).toBe(4); - expect(select.element.options[0].value).toBe('0'); + expect(select.element.options[0].value).toBe(uSelect.headValue); expect(select.element.options[0].text).toBe(head); - expect(select.element.options[1].value).toBe('all'); + expect(select.element.options[1].value).toBe(uSelect.allValue); expect(select.element.options[1].text).toBe(allText); expect(select.element.options[3].selected).toBe(true); }); @@ -237,7 +237,7 @@ describe('Select tests', () => { select.showAllOption(allText); // then expect(select.element.options.length).toBe(4); - expect(select.element.options[1].value).toBe('all'); + expect(select.element.options[1].value).toBe(uSelect.allValue); expect(select.element.options[1].text).toBe(allText); expect(select.element.options[3].selected).toBe(true); // when