|
| 1 | +import { h } from '@stencil/core'; |
| 2 | +import { render } from '@wdio/browser-runner/stencil'; |
| 3 | + |
| 4 | +import { defineCustomElement } from '../../test-components-no-external-runtime/custom-elements-form-associated.js'; |
| 5 | + |
| 6 | +describe('custome elements form associated', function () { |
| 7 | + beforeEach(() => { |
| 8 | + defineCustomElement(); |
| 9 | + render({ |
| 10 | + template: () => ( |
| 11 | + <form> |
| 12 | + <custom-elements-form-associated name="test-input"></custom-elements-form-associated> |
| 13 | + <input type="reset" value="Reset" /> |
| 14 | + </form> |
| 15 | + ), |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should render without errors', async () => { |
| 20 | + const elm = $('custom-elements-form-associated'); |
| 21 | + await expect(elm).toBePresent(); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('form associated custom element lifecycle callback', () => { |
| 25 | + it('should trigger "formAssociated"', async () => { |
| 26 | + const formEl = $('form'); |
| 27 | + await expect(formEl).toHaveProperty('ariaLabel', 'asdfasdf'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should trigger "formResetCallback"', async () => { |
| 31 | + const resetBtn = $('input[type="reset"]'); |
| 32 | + await resetBtn.click(); |
| 33 | + |
| 34 | + await resetBtn.waitForStable(); |
| 35 | + |
| 36 | + const formEl = $('form'); |
| 37 | + await expect(formEl).toHaveProperty('ariaLabel', 'formResetCallback called'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should trigger "formDisabledCallback"', async () => { |
| 41 | + const elm = document.body.querySelector('custom-elements-form-associated'); |
| 42 | + const formEl = $('form'); |
| 43 | + |
| 44 | + elm.setAttribute('disabled', 'disabled'); |
| 45 | + |
| 46 | + await formEl.waitForStable(); |
| 47 | + await expect(formEl).toHaveProperty('ariaLabel', 'formDisabledCallback called with true'); |
| 48 | + |
| 49 | + elm.removeAttribute('disabled'); |
| 50 | + await formEl.waitForStable(); |
| 51 | + await expect(formEl).toHaveProperty('ariaLabel', 'formDisabledCallback called with false'); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should link up to the surrounding form', async () => { |
| 56 | + // this shows that the element has, through the `ElementInternals` |
| 57 | + // interface, been able to set a value in the surrounding form |
| 58 | + await browser.waitUntil( |
| 59 | + async () => { |
| 60 | + const formEl = document.body.querySelector('form'); |
| 61 | + expect(new FormData(formEl).get('test-input')).toBe('my default value'); |
| 62 | + return true; |
| 63 | + }, |
| 64 | + { timeoutMsg: 'form associated value never changed' }, |
| 65 | + ); |
| 66 | + }); |
| 67 | +}); |
0 commit comments