|
| 1 | +import { html, fixture, expect } from '@open-wc/testing'; |
| 2 | + |
| 3 | +import '../../src/wizard-select.js'; |
| 4 | +import { WizardSelect } from '../../src/wizard-select.js'; |
| 5 | + |
| 6 | +describe('wizard-select', () => { |
| 7 | + let element: WizardSelect; |
| 8 | + const items = ['one', 'two', 'three']; |
| 9 | + beforeEach(async () => { |
| 10 | + element = await fixture( |
| 11 | + html`<wizard-select |
| 12 | + >${items.map( |
| 13 | + item => html`<mwc-list-item value="${item}">${item}</mwc-list-item>` |
| 14 | + )}</wizard-select |
| 15 | + >` |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + it('does not render a null value switch', () => |
| 20 | + expect(element.nullSwitch).to.not.exist); |
| 21 | + |
| 22 | + it('is enabled', () => expect(element).to.have.property('disabled', false)); |
| 23 | + |
| 24 | + it('returns the select value as its maybeValue', () => { |
| 25 | + element.value = 'two'; |
| 26 | + expect(element.maybeValue).to.equal(element.value); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('nullable', () => { |
| 30 | + beforeEach(async () => { |
| 31 | + element.nullable = true; |
| 32 | + element.value = 'one'; |
| 33 | + await element.updateComplete; |
| 34 | + }); |
| 35 | + |
| 36 | + it('renders a null value switch', async () => |
| 37 | + expect(element.nullSwitch).to.exist); |
| 38 | + |
| 39 | + it('disables itself on switch toggle', async () => { |
| 40 | + expect(element).to.have.property('maybeValue', 'one'); |
| 41 | + expect(element).to.have.property('disabled', false); |
| 42 | + element.nullSwitch!.click(); |
| 43 | + await element.updateComplete; |
| 44 | + expect(element).to.have.property('maybeValue', null); |
| 45 | + expect(element).to.have.property('disabled', true); |
| 46 | + }); |
| 47 | + |
| 48 | + it('remebers its previous value on switch toggle', async () => { |
| 49 | + element.maybeValue = 'three'; |
| 50 | + await element.updateComplete; |
| 51 | + element.nullSwitch!.click(); |
| 52 | + await element.updateComplete; |
| 53 | + element.nullSwitch!.click(); |
| 54 | + await element.updateComplete; |
| 55 | + expect(element).to.have.property('disabled', false); |
| 56 | + expect(element).to.have.property('maybeValue', 'three'); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('with a null value', () => { |
| 60 | + beforeEach(async () => { |
| 61 | + element.maybeValue = null; |
| 62 | + await element.updateComplete; |
| 63 | + }); |
| 64 | + |
| 65 | + it('enables itself on switch toggle', async () => { |
| 66 | + element.nullSwitch?.click(); |
| 67 | + await element.updateComplete; |
| 68 | + expect(element).to.have.property('disabled', false); |
| 69 | + }); |
| 70 | + |
| 71 | + it('has a disabled textfield', () => |
| 72 | + expect(element).to.have.property('disabled', true)); |
| 73 | + |
| 74 | + it('does not show anything in the textfield', () => |
| 75 | + expect(element).to.have.property('value', '')); |
| 76 | + |
| 77 | + it('returns null', () => |
| 78 | + expect(element).to.have.property('maybeValue', null)); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments