|
| 1 | +import { selectComponent, getProps } from '@pictogrammers/element'; |
| 2 | + |
| 3 | +import './inputNumber'; |
| 4 | +import PgInputText from './inputNumber'; |
| 5 | + |
| 6 | +const PG_INPUT_TEXT = 'pg-input-text'; |
| 7 | + |
| 8 | +describe('pg-input-text', () => { |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + var c = document.createElement(PG_INPUT_TEXT); |
| 12 | + document.body.appendChild(c); |
| 13 | + }); |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + while (document.body.firstChild) { |
| 17 | + document.body.removeChild(document.body.firstChild); |
| 18 | + } |
| 19 | + }); |
| 20 | + |
| 21 | + it('should be registered', () => { |
| 22 | + expect(customElements.get(PG_INPUT_TEXT)).toBeDefined(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should only expose known props', () => { |
| 26 | + const props = getProps(PG_INPUT_TEXT); |
| 27 | + expect(props.length).toBe(3); |
| 28 | + expect(props).toContain('name'); |
| 29 | + expect(props).toContain('value'); |
| 30 | + expect(props).toContain('placeholder'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should default value to empty', () => { |
| 34 | + const component = selectComponent<PgInputText>(PG_INPUT_TEXT); |
| 35 | + const { $input } = component; |
| 36 | + expect($input.value).toEqual(''); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should set value to "Hello World!"', () => { |
| 40 | + const component = selectComponent<PgInputText>(PG_INPUT_TEXT); |
| 41 | + component.value = 'Hello World!'; |
| 42 | + const { $input } = component; |
| 43 | + expect($input.value).toEqual('Hello World!'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should default placeholder to empty', () => { |
| 47 | + const component = selectComponent<PgInputText>(PG_INPUT_TEXT); |
| 48 | + const { $input } = component; |
| 49 | + expect($input.placeholder).toEqual(''); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should set placeholder to "Hello World!"', () => { |
| 53 | + const component = selectComponent<PgInputText>(PG_INPUT_TEXT); |
| 54 | + component.placeholder = 'Hello World!'; |
| 55 | + const { $input } = component; |
| 56 | + expect($input.placeholder).toEqual('Hello World!'); |
| 57 | + }); |
| 58 | + |
| 59 | +}); |
0 commit comments