|
| 1 | +import { mountThemedComponent } from '@shared/tests/utils'; |
| 2 | +import * as React from 'react'; |
| 3 | +import { Form } from '@ui5/webcomponents-react/lib/Form'; |
| 4 | +import { FormGroup } from '@ui5/webcomponents-react/lib/FormGroup'; |
| 5 | +import { FormItem } from '@ui5/webcomponents-react/lib/FormItem'; |
| 6 | +import { Input } from '../../webComponents/Input'; |
| 7 | +import { InputType } from '../..'; |
| 8 | + |
| 9 | +const SIZE_S = 200; |
| 10 | +const SIZE_M = 800; |
| 11 | +const SIZE_L = 1200; |
| 12 | +const SIZE_XL = 1600; |
| 13 | +const component = ( |
| 14 | + <Form title={'Test form'}> |
| 15 | + <FormGroup title={'Group 1'}> |
| 16 | + <FormItem labelText={'item 1'}> |
| 17 | + <Input type={InputType.Text}></Input> |
| 18 | + </FormItem> |
| 19 | + <FormItem labelText={'item 2'}> |
| 20 | + <Input type={InputType.Number}></Input> |
| 21 | + </FormItem> |
| 22 | + </FormGroup> |
| 23 | + <FormGroup title={'Group 2'}> |
| 24 | + <FormItem labelText={'item 1'}> |
| 25 | + <Input type={InputType.Text}></Input> |
| 26 | + </FormItem> |
| 27 | + <FormItem labelText={'item 2'}> |
| 28 | + <Input type={InputType.Number}></Input> |
| 29 | + </FormItem> |
| 30 | + </FormGroup> |
| 31 | + </Form> |
| 32 | +); |
| 33 | + |
| 34 | +describe('Create a Form', () => { |
| 35 | + test('size rate S; should create Label and Element with 100% width and display: block for top FormItem div', () => { |
| 36 | + window = Object.assign(window, { innerWidth: SIZE_S }); |
| 37 | + const wrapper = mountThemedComponent(component); |
| 38 | + expect(wrapper.render()).toMatchSnapshot(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('size rate M; should create Label and Element with 16% and 83% width respectively and display: flex for top FormItem div', () => { |
| 42 | + window = Object.assign(window, { innerWidth: SIZE_M }); |
| 43 | + const wrapper = mountThemedComponent(component); |
| 44 | + expect(wrapper.render()).toMatchSnapshot(); |
| 45 | + }); |
| 46 | + |
| 47 | + test('size rate L; should create Label and Element with 33% and 66% width respectively and display: flex for top FormItem div', () => { |
| 48 | + window = Object.assign(window, { innerWidth: SIZE_L }); |
| 49 | + const wrapper = mountThemedComponent(component); |
| 50 | + expect(wrapper.render()).toMatchSnapshot(); |
| 51 | + }); |
| 52 | + |
| 53 | + test('size rate XL; should create Label and Element with 33% and 66% width respectively and display: flex for top FormItem div', () => { |
| 54 | + window = Object.assign(window, { innerWidth: SIZE_XL }); |
| 55 | + const wrapper = mountThemedComponent(component); |
| 56 | + expect(wrapper.render()).toMatchSnapshot(); |
| 57 | + }); |
| 58 | + |
| 59 | + test('should create a FormGroup and put ungrouped FormItems into it', () => { |
| 60 | + const ungroupedChildren = ( |
| 61 | + <Form title={'Test form'}> |
| 62 | + <FormItem labelText={'item 1'}> |
| 63 | + <Input type={InputType.Text}></Input> |
| 64 | + </FormItem> |
| 65 | + <FormItem labelText={'item 2'}> |
| 66 | + <Input type={InputType.Number}></Input> |
| 67 | + </FormItem> |
| 68 | + </Form> |
| 69 | + ); |
| 70 | + const wrapper = mountThemedComponent(ungroupedChildren); |
| 71 | + expect(wrapper.render()).toMatchSnapshot(); |
| 72 | + }); |
| 73 | + |
| 74 | + test("should use a single FormGroup's title as a Form title if one is not set", () => { |
| 75 | + const ungroupedChildren = ( |
| 76 | + <Form> |
| 77 | + <FormGroup title={'To be Form title'}> |
| 78 | + <FormItem labelText={'item 1'}> |
| 79 | + <Input type={InputType.Text}></Input> |
| 80 | + </FormItem> |
| 81 | + <FormItem labelText={'item 2'}> |
| 82 | + <Input type={InputType.Number}></Input> |
| 83 | + </FormItem> |
| 84 | + </FormGroup> |
| 85 | + </Form> |
| 86 | + ); |
| 87 | + const wrapper = mountThemedComponent(ungroupedChildren); |
| 88 | + expect(wrapper.render()).toMatchSnapshot(); |
| 89 | + }); |
| 90 | +}); |
0 commit comments