-
Notifications
You must be signed in to change notification settings - Fork 95
PoC for component testing #1137
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
import { html, fixture, expect } from "@open-wc/testing"; | ||
import { screen, waitForElementToBeRemoved } from "@testing-library/dom"; | ||
import userEvent from "@testing-library/user-event"; | ||
import "../ts/index"; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe("tooltip", () => { | ||
it("should make the tooltip element visible on hover (after a delay)", async () => { | ||
const trigger = await fixture(html` | ||
<button | ||
class="s-btn s-btn__filled" | ||
role="button" | ||
data-controller="s-tooltip" | ||
title="tooltip content" | ||
data-s-tooltip-placement="bottom-start" | ||
> | ||
Hover tooltip popover | ||
</button> | ||
`); | ||
|
||
expect(screen.queryByRole("tooltip")).to.be.null; | ||
|
||
await user.hover(trigger); | ||
const tooltip = await screen.findByRole("tooltip"); | ||
expect(tooltip).to.be.visible; | ||
|
||
await user.unhover(trigger); | ||
await waitForElementToBeRemoved(() => screen.queryByRole("tooltip")); | ||
}); | ||
|
||
it("should not flicker when the host contains an SVG and the user hover on it", async () => { | ||
await fixture(html` | ||
<button | ||
class="s-btn" | ||
role="button" | ||
title="tooltip content" | ||
data-controller="s-tooltip" | ||
data-s-tooltip-placement="bottom-start" | ||
> | ||
<svg | ||
data-testid="svg" | ||
aria-hidden="true" | ||
class="bg-red-500" | ||
width="18" | ||
height="18" | ||
viewBox="0 0 18 18" | ||
></svg> | ||
👈 Shouldn't flicker 🤷 | ||
</button> | ||
`); | ||
const button = screen.getByRole("button"); | ||
const svg = screen.getByTestId("svg"); | ||
|
||
await user.hover(button); | ||
const tooltip = await screen.findByRole("tooltip"); | ||
expect(tooltip).to.be.visible; | ||
|
||
await user.hover(svg); | ||
expect(tooltip).to.be.visible; | ||
}); | ||
}); |
This file contains hidden or 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,31 @@ | ||
import { html, fixture } from "@open-wc/testing"; | ||
import { screen } from "@testing-library/dom"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { visualDiff } from "@web/test-runner-visual-regression"; | ||
import "../ts/index"; | ||
|
||
const user = userEvent.setup(); | ||
|
||
describe("tooltip", () => { | ||
it("should not introduce visual regressions", async () => { | ||
const wrapper = await fixture(html` | ||
<div style="height: 100px; display: inline-block;"> | ||
<button | ||
class="s-btn s-btn__filled" | ||
role="button" | ||
data-controller="s-tooltip" | ||
title="tooltip content" | ||
data-s-tooltip-placement="bottom-start" | ||
> | ||
Hover tooltip popover | ||
</button> | ||
</div> | ||
`); | ||
|
||
const trigger = screen.getByRole("button"); | ||
await user.hover(trigger); | ||
await screen.findByRole("tooltip"); | ||
|
||
await visualDiff(wrapper, "tooltip"); | ||
}); | ||
}); |
This file contains hidden or 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,8 +1,21 @@ | ||
// export all controllers *with helpers* so they can be bulk re-exported by the package entry point | ||
export { ExpandableController } from './s-expandable-control'; | ||
export { hideModal, ModalController, showModal } from './s-modal'; | ||
export { TabListController } from './s-navigation-tablist'; | ||
export { attachPopover, detachPopover, hidePopover, BasePopoverController, PopoverController, showPopover } from './s-popover'; | ||
export { TableController } from './s-table'; | ||
export { setTooltipHtml, setTooltipText, TooltipController } from './s-tooltip'; | ||
export { UploaderController } from './s-uploader'; | ||
export { ExpandableController } from "./s-expandable-control"; | ||
export { hideModal, ModalController, showModal } from "./s-modal"; | ||
export { TabListController } from "./s-navigation-tablist"; | ||
export { | ||
attachPopover, | ||
detachPopover, | ||
hidePopover, | ||
BasePopoverController, | ||
PopoverController, | ||
showPopover, | ||
} from "./s-popover"; | ||
export { TableController } from "./s-table"; | ||
export { setTooltipHtml, setTooltipText, TooltipController } from "./s-tooltip"; | ||
// uncomment and comment the line above to run the tests against version 1.3.0 of the tooltip and see them failing | ||
// export { | ||
// setTooltipHtml, | ||
// setTooltipText, | ||
// TooltipController, | ||
// } from "./s-tooltip-1.3.0"; | ||
export { UploaderController } from "./s-uploader"; |
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 tested out both the
s-tooltip.ts
ands-tooltip-1.3.0.ts
being imported and looks like the tests pass/fail as we'd expect 🎉With that said, I'm not sure why this one fails when using
s-tooltip-1.3.0.ts
…I would expect tooltip to be visible under these circumstances. Can you help me understand why this fails? t's very likely that I'm missing something super obvious but I wanna make sure I understand this test and that it's behaving as we expect for the reasons we'd expect.
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.
If you look at the generated output you can spot that in this version we had another a11y bug where we were not updating correctly the
aria-hidden
attribute. When the user hovered on the tooltiparia-hidden
remained set totrue
: you can check this also in the code pen you shared with me.Perhaps this is a confirmation bias but this, in my opinion, highlights how powerful the testing library selectors are to spot a11y problems too.
This is the error output for me:
You can see there that the
aria-hidden
is set to true and it should not. This is the same exact behavior we had for users until your refactor I think. 🙂