|
1 | 1 | import { E2EElement, E2EPage, newE2EPage } from '@stencil/core/testing';
|
2 | 2 | import { OdsSearchBarAttributes, OdsComponentAttributes2StringAttributes, odsSearchBarDefaultAttributes } from '@ovhcloud/ods-core';
|
3 |
| -import { OdsCreateAttributes, OdsStringAttributes2Str, odsSearchBarBaseAttributes } from '@ovhcloud/ods-testing'; |
| 3 | +import { OdsCreateAttributes, OdsStringAttributes2Str } from '@ovhcloud/ods-testing'; |
4 | 4 |
|
5 | 5 | describe('e2e:osds-search-bar', () => {
|
6 | 6 | let page: E2EPage;
|
7 | 7 | let el: E2EElement;
|
| 8 | + let select: E2EElement; |
| 9 | + let button: E2EElement; |
| 10 | + let input: E2EElement; |
8 | 11 |
|
9 | 12 | async function setup({ attributes }: { attributes: Partial<OdsSearchBarAttributes> }) {
|
10 |
| - const minimalAttributes: OdsSearchBarAttributes = OdsCreateAttributes(attributes, odsSearchBarBaseAttributes); |
| 13 | + const minimalAttributes: OdsSearchBarAttributes = OdsCreateAttributes(attributes, odsSearchBarDefaultAttributes); |
11 | 14 | const stringAttributes = OdsComponentAttributes2StringAttributes<OdsSearchBarAttributes>(minimalAttributes, odsSearchBarDefaultAttributes);
|
12 | 15 |
|
13 | 16 | page = await newE2EPage();
|
14 | 17 | await page.setContent(`<osds-search-bar ${OdsStringAttributes2Str(stringAttributes)}></osds-search-bar>`);
|
15 | 18 | await page.evaluate(() => document.body.style.setProperty('margin', '0px'));
|
| 19 | + await page.waitForChanges(); |
16 | 20 |
|
17 | 21 | el = await page.find('osds-search-bar');
|
| 22 | + el.setProperty('options', attributes.options ?? []); |
| 23 | + |
| 24 | + await page.waitForChanges(); |
| 25 | + |
| 26 | + select = await page.find('osds-search-bar >>> osds-select'); |
| 27 | + input = await page.find('osds-search-bar >>> osds-input'); |
| 28 | + button = await page.find('osds-search-bar >>> osds-button'); |
| 29 | + |
| 30 | + await page.waitForChanges(); |
18 | 31 | }
|
19 | 32 |
|
20 | 33 | it('should render', async () => {
|
21 | 34 | await setup({ attributes: {} });
|
22 | 35 | expect(el).not.toBeNull();
|
23 | 36 | expect(el).toHaveClass('hydrated');
|
| 37 | + |
| 38 | + expect(input).not.toBeNull(); |
| 39 | + expect(input).toHaveClass('hydrated'); |
| 40 | + |
| 41 | + expect(button).not.toBeNull(); |
| 42 | + expect(button).toHaveClass('hydrated'); |
| 43 | + |
| 44 | + expect(select).toBeNull(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should get default attributes', async () => { |
| 48 | + await setup({ attributes: {} }); |
| 49 | + expect(await el.getProperty('contrasted')).toBe(odsSearchBarDefaultAttributes.contrasted); |
| 50 | + expect(await el.getProperty('disabled')).toBe(odsSearchBarDefaultAttributes.disabled); |
| 51 | + expect(await el.getProperty('value')).toBe(odsSearchBarDefaultAttributes.value); |
| 52 | + expect(await el.getProperty('loading')).toBe(odsSearchBarDefaultAttributes.loading); |
| 53 | + expect(await el.getProperty('options')).toEqual(odsSearchBarDefaultAttributes.options); |
| 54 | + expect(await el.getProperty('placeholder')).toBe(odsSearchBarDefaultAttributes.placeholder); |
| 55 | + }); |
24 | 56 |
|
25 |
| - // E2E testing |
| 57 | + it('should display select because of options', async () => { |
| 58 | + const options = [{ label: 'options1', value: '1' }, { label: 'options2', value: '2' }]; |
| 59 | + await setup({ attributes: { options } }); |
| 60 | + |
| 61 | + expect(select).not.toBeNull(); |
| 62 | + expect(select).toHaveClass('hydrated'); |
26 | 63 | });
|
27 | 64 |
|
| 65 | + describe('Event', () => { |
| 66 | + it('should receive event odsValueChange', async () => { |
| 67 | + await setup({ attributes: { } }); |
| 68 | + |
| 69 | + const odsValueChange = await el.spyOnEvent('odsValueChange'); |
| 70 | + |
| 71 | + await input.setProperty('value', '4'); |
| 72 | + await page.waitForChanges(); |
| 73 | + expect(odsValueChange).toHaveReceivedEventTimes(1); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should receive event odsSearchSubmit with current value', async () => { |
| 77 | + await setup({ attributes: { } }); |
| 78 | + |
| 79 | + const odsSearchSubmit = await el.spyOnEvent('odsSearchSubmit'); |
| 80 | + await input.setProperty('value', '4'); |
| 81 | + |
| 82 | + await page.waitForChanges(); |
| 83 | + await button.click(); |
| 84 | + |
| 85 | + expect(odsSearchSubmit).toHaveReceivedEventTimes(1); |
| 86 | + expect(odsSearchSubmit).toHaveReceivedEventDetail({ optionValue: '', inputValue: '4' }); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should receive event odsValueChange with options selected', async () => { |
| 90 | + const options = [{ label: 'options1', value: '1' }, { label: 'options2', value: '2' }]; |
| 91 | + await setup({ attributes: { options } }); |
| 92 | + |
| 93 | + const odsValueChange = await el.spyOnEvent('odsValueChange'); |
| 94 | + |
| 95 | + await select.click(); |
| 96 | + |
| 97 | + const optionElement = await page.find('osds-search-bar >>> osds-select > osds-select-option'); |
| 98 | + await optionElement.click(); |
| 99 | + |
| 100 | + await page.waitForChanges(); |
| 101 | + expect(odsValueChange).toHaveReceivedEventTimes(1); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should receive event odsSearchSubmit with options selected', async () => { |
| 105 | + const options = [{ label: 'options1', value: '1' }, { label: 'options2', value: '2' }]; |
| 106 | + await setup({ attributes: { options } }); |
| 107 | + |
| 108 | + const odsSearchSubmit = await el.spyOnEvent('odsSearchSubmit'); |
| 109 | + |
| 110 | + await select.click(); |
| 111 | + |
| 112 | + const optionElement = await page.find('osds-search-bar >>> osds-select > osds-select-option'); |
| 113 | + await optionElement.click(); |
| 114 | + await button.click(); |
| 115 | + |
| 116 | + await page.waitForChanges(); |
| 117 | + expect(odsSearchSubmit).toHaveReceivedEventTimes(1); |
| 118 | + expect(odsSearchSubmit).toHaveReceivedEventDetail({ optionValue: '1', inputValue: '' }); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + // describe.only('a11y', () => { |
| 123 | + // it('should navigate with tab', async () => { |
| 124 | + // const options = [{ label: 'options1', value: '1' }, { label: 'options2', value: '2' }]; |
| 125 | + // await setup({ attributes: { options } }); |
| 126 | + |
| 127 | + // await page.keyboard.press('Tab'); |
| 128 | + // await page.keyboard.press('Tab'); |
| 129 | + |
| 130 | + // const activeElement = await page.evaluateHandle(() => { |
| 131 | + // console.log('document.activeElementtagName', document.activeElement.tagName); |
| 132 | + // return document.activeElement; |
| 133 | + // }); |
| 134 | + // console.log('activeElement', await (await activeElement.asElement()).getProperty('tagName'), await activeElement.getProperty('tagName')); |
| 135 | + // expect(true).toBe(await select.getProperty('tagName')); |
| 136 | + // }); |
| 137 | + // }) |
28 | 138 | });
|
0 commit comments