-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7702af9
commit 0f5c713
Showing
1 changed file
with
99 additions
and
4 deletions.
There are no files selected for viewing
103 changes: 99 additions & 4 deletions
103
packages/beeq/src/components/accordion/__tests__/bq-accordion.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,114 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
import { computedStyle } from '../../../shared/test-utils'; | ||
|
||
describe('bq-accordion', () => { | ||
it('should render', async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent('<bq-accordion></bq-accordion>'); | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion></bq-accordion>`, | ||
}); | ||
|
||
const element = await page.find('bq-accordion'); | ||
expect(element).toHaveClass('hydrated'); | ||
}); | ||
|
||
it('should have shadow root', async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent('<bq-accordion></bq-accordion>'); | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion></bq-accordion>`, | ||
}); | ||
|
||
const element = await page.find('bq-accordion'); | ||
expect(element.shadowRoot).not.toBeNull(); | ||
}); | ||
|
||
it('should display header text', async () => { | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion><span slot="header">Test text</span></bq-accordion>`, | ||
}); | ||
|
||
const headerText = await page.$eval('bq-accordion >>> slot[name="header"]', (element) => { | ||
return element.assignedElements({ flatten: true })[0].textContent; | ||
}); | ||
|
||
expect(headerText).toEqualText('Test text'); | ||
expect(headerText).not.toBeNull(); | ||
}); | ||
|
||
it('should render prefix', async () => { | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion><span slot="header">Test text</span> <span slot="prefix">Test prefix</span></bq-accordion>`, | ||
}); | ||
|
||
const headerText = await page.$eval('bq-accordion >>> slot[name="prefix"]', (element) => { | ||
return element.assignedElements({ flatten: true })[0].textContent; | ||
}); | ||
|
||
expect(headerText).toEqualText('Test prefix'); | ||
expect(headerText).not.toBeNull(); | ||
}); | ||
|
||
it('should render suffix', async () => { | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion><span slot="header">Test text</span> <span slot="suffix">Test suffix</span></bq-accordion>`, | ||
}); | ||
|
||
const headerText = await page.$eval('bq-accordion >>> slot[name="suffix"]', (element) => { | ||
return element.assignedElements({ flatten: true })[0].textContent; | ||
}); | ||
|
||
expect(headerText).toEqualText('Test suffix'); | ||
expect(headerText).not.toBeNull(); | ||
}); | ||
|
||
it('should be open if expanded prop is provided', async () => { | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion expanded><span slot="header">Test text</span></bq-accordion>`, | ||
}); | ||
|
||
const details = await page.find('bq-accordion >>> [part="base"]'); | ||
|
||
expect(await details.getProperty('open')).toBe(true); | ||
}); | ||
|
||
it('should be collapsed when disabled', async () => { | ||
const page = await newE2EPage({ | ||
html: `<bq-accordion expanded disabled><span slot="header">Test text</span></bq-accordion>`, | ||
}); | ||
|
||
const details = await page.find('bq-accordion >>> [part="base"]'); | ||
|
||
expect(await details.getProperty('open')).toBe(false); | ||
}); | ||
|
||
it('should respect design style', async () => { | ||
const page = await newE2EPage({ | ||
html: ` | ||
<bq-accordion size="small"><span slot="header">Test text</span></bq-accordion> | ||
<bq-accordion size="medium"><span slot="header">Test text</span></bq-accordion> | ||
`, | ||
}); | ||
|
||
const smallHeaderStyle = await computedStyle(page, 'bq-accordion[size="small"] >>> summary', [ | ||
'borderRadius', | ||
'padding', | ||
]); | ||
const smallPanelStyle = await computedStyle(page, 'bq-accordion[size="small"] >>> [part="panel"]', [ | ||
'borderRadius', | ||
'padding', | ||
]); | ||
|
||
const mediumHeaderStyle = await computedStyle(page, 'bq-accordion[size="medium"] >>> summary', [ | ||
'borderRadius', | ||
'padding', | ||
]); | ||
const mediumPanelStyle = await computedStyle(page, 'bq-accordion[size="medium"] >>> [part="panel"]', [ | ||
'borderRadius', | ||
'padding', | ||
]); | ||
|
||
expect(smallHeaderStyle).toEqual({ borderRadius: '4px', padding: '8px 12px' }); | ||
expect(smallPanelStyle).toEqual({ borderRadius: '0px 0px 4px 4px', padding: '12px' }); | ||
expect(mediumHeaderStyle).toEqual({ borderRadius: '4px', padding: '12px 16px' }); | ||
expect(mediumPanelStyle).toEqual({ borderRadius: '0px 0px 4px 4px', padding: '16px' }); | ||
}); | ||
}); |