-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(tooltip): Added tests for gux-tooltip-title component #471
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is backwards compatible.