-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tooltip): Added tests for gux-tooltip-title component
✅ Closes: COMUI-1408 chore(truncate): Added tests for checking if tooltip is visible or not ✅ Closes: COMUI-1408 chore(tooltip): Added visibility tests for gux-tooltip within a gux-tooltip-text tag ✅ Closes: COMUI-1408 chore(truncate): Removed unneeded page is defined expect statement in tests ✅ Closes: COMUI-1408 chore(truncate): Added more tests ✅ Closes: COMUI-1408 chore(truncate): Removed console log statement ✅ Closes: COMUI-1408 chore(truncate): Added truncation text check test ✅ Closes: COMUI-1408 chore(tooltip): Added test for truncation for tooltip-title component ✅ Closes: COMUI-1408 chore(tooltip): Added more tests for tooltip-title component ✅ Closes: COMUI-1408 chore(tooltip): Fixed some snapshot tests for tooltip-title ✅ Closes: COMUI-1408
- Loading branch information
1 parent
0e09d4f
commit 2c256c2
Showing
5 changed files
with
177 additions
and
3 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...src/components/stable/gux-tooltip-title/tests/__snapshots__/gux-tooltip-title.e2e.ts.snap
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`gux-tooltip-title #render should render component as expected (1) 1`] = `"<gux-tooltip-title hydrated="" class="gux-overflow-hidden" aria-describedby="gux-tooltip-i"><!----><span class="gux-title-container"><span><slot aria-hidden="true" onslotchange="{this.onSlotChange.bind(this)}">Some long text to truncate and use a tooltip</slot></span></span><gux-tooltip aria-hidden="true" hidden="" id="gux-tooltip-i" role="tooltip" hydrated=""><div slot="content"></div></gux-tooltip></gux-tooltip-title>"`; | ||
|
||
exports[`gux-tooltip-title #render should render component as expected (2) 1`] = `"<gux-tooltip-title hydrated=""><!----><span class="gux-title-container"><div style="max-width: 200px;">Some short text</div></span></gux-tooltip-title>"`; |
107 changes: 107 additions & 0 deletions
107
...s-spark-components/src/components/stable/gux-tooltip-title/tests/gux-tooltip-title.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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { E2EPage, newE2EPage } from '@stencil/core/testing'; | ||
import { a11yCheck } from '../../../../test/e2eTestUtils'; | ||
|
||
async function newNonrandomE2EPage( | ||
{ | ||
html | ||
}: { | ||
html: string; | ||
}, | ||
lang: string = 'en' | ||
): Promise<E2EPage> { | ||
const page = await newE2EPage(); | ||
|
||
await page.evaluateOnNewDocument(() => { | ||
Math.random = () => 0.5; | ||
}); | ||
await page.setContent(`<div lang=${lang}>${html}</div>`); | ||
await page.waitForChanges(); | ||
await page.addScriptTag({ | ||
path: '../../node_modules/axe-core/axe.min.js' | ||
}); | ||
await page.waitForChanges(); | ||
|
||
return page; | ||
} | ||
|
||
describe('gux-tooltip-title', () => { | ||
describe('#render', () => { | ||
[ | ||
'<div style="max-width: 40px"><gux-tooltip-title><span><slot aria-hidden="true" onSlotchange={this.onSlotChange.bind(this)}>Some long text to truncate and use a tooltip</slot></span></gux-tooltip-title></div>', | ||
'<gux-tooltip-title><div style="max-width: 200px">Some short text</div></gux-tooltip-title>' | ||
].forEach((html, index) => { | ||
it(`should render component as expected (${index + 1})`, async () => { | ||
const page = await newNonrandomE2EPage({ html }); | ||
const element = await page.find('gux-tooltip-title'); | ||
|
||
await a11yCheck(page); | ||
|
||
expect(element.outerHTML).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should render a tooltip if the component text width is greater than the parent container', async () => { | ||
const page = await newNonrandomE2EPage({ | ||
html: ` | ||
<div style="max-width: 40px"> | ||
<gux-tooltip-title> | ||
<span> | ||
<slot aria-hidden="true" onSlotchange={this.onSlotChange.bind(this)}>Some long text to truncate and use a tooltip</slot> | ||
</span> | ||
</gux-tooltip-title> | ||
</div> | ||
` | ||
}); | ||
|
||
const tooltipElement = await page.find('pierce/gux-tooltip'); | ||
expect(tooltipElement).toBeDefined(); | ||
}); | ||
|
||
it('should not render a tooltip if the component text width is less than the parent container', async () => { | ||
const page = await newNonrandomE2EPage({ | ||
html: ` | ||
<gux-tooltip-title> | ||
<span>Some short text</span> | ||
</gux-tooltip-title> | ||
` | ||
}); | ||
|
||
const tooltipElement = await page.find('pierce/gux-tooltip'); | ||
expect(tooltipElement).toBeNull(); | ||
}); | ||
|
||
it('should truncate title text if tooltip is rendered', async () => { | ||
const page = await newNonrandomE2EPage({ | ||
html: ` | ||
<div style="max-width: 40px"> | ||
<gux-tooltip-title> | ||
<span> | ||
<slot aria-hidden="true" onSlotchange={this.onSlotChange.bind(this)}>Some long text to truncate and use a tooltip</slot> | ||
</span> | ||
</gux-tooltip-title> | ||
</div> | ||
` | ||
}); | ||
|
||
const element = await page.find('gux-tooltip-title'); | ||
expect(element).toHaveClass('gux-overflow-hidden'); | ||
}); | ||
|
||
it('Tooltip title text should match screenreader text if gux-icon is being used and no title text is set', async () => { | ||
const page = await newNonrandomE2EPage({ | ||
html: ` | ||
<div style="max-width: 40px"> | ||
<gux-tooltip-title> | ||
<span> | ||
<gux-icon icon-name="unknown" decorative screenreader-text="test screenreader text"></gux-icon> | ||
</span> | ||
</gux-tooltip-title> | ||
</div> | ||
` | ||
}); | ||
|
||
const tooltipElement = await page.find('gux-tooltip'); | ||
expect(tooltipElement.innerText).toBe('test screenreader text'); | ||
}); | ||
}); |
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
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
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