-
Notifications
You must be signed in to change notification settings - Fork 84
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
test(icon-button): add playwright tests #6369
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit dff1b79:
|
const element = await iconLocator; | ||
await element.focus(); | ||
await expect(element).toHaveCSS( | ||
"box-shadow", |
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 don't think the line const element = await iconLocator;
is necessary? The following should do the same:
const iconLocator = page.getByTestId("icon").locator("..");
await iconLocator.focus();
await expect(iconLocator).toHaveCSS(
import { HooksConfig } from "../../../playwright"; | ||
import { checkAccessibility } from "../../../playwright/support/helper"; | ||
|
||
test.describe("when focused", () => { |
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.
This describe should probably be changed to something more meaningful like:
test.describe("check IconButton component focus outlines and border radius", () => {
); | ||
|
||
const iconLocator = page.getByTestId("icon").locator(".."); | ||
const element = await iconLocator; |
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.
Same as previous comment, const element = await iconLocator;
is unnecessary.
"aria-label", | ||
CHARACTERS.STANDARD | ||
); | ||
await iconLocator.isVisible(); |
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 think await expect(iconLocator).toBeVisible()
is more reliable than this.
await mount(<IconButtonComponent />); | ||
|
||
const iconLocator = page.getByTestId("icon"); | ||
await iconLocator.isVisible(); |
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.
Same as previous comment.
|
||
const iconLocator = page.getByTestId("icon").locator(".."); | ||
await iconLocator.isDisabled(); | ||
await iconLocator.getAttribute("disabled"); |
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.
This would be preferable:
await expect(iconLocator).toBeDisabled()
await expect(iconLocator).toHaveAttribute("disabled", /.*/);
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); | ||
await iconLocator.focus(); | ||
await iconLocator.blur(); |
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.
This line await iconLocator.blur();
is not needed.
}); | ||
}); | ||
|
||
test(`render with the expected border radius`, async ({ mount, page }) => { |
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.
You could move this test to the first describe, with the border radius tests.
}) => { | ||
await mount(<IconButtonComponent aria-label={CHARACTERS.STANDARD} />); | ||
|
||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
This const is used several times. Can it be declared once outside of the tests?
} | ||
); | ||
|
||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times. Can it be declared once earlier then just iconLocator called where needed?
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.
Hi Sian, IMO we can't do this as we are using page to create this locator inside the test.
}) => { | ||
await mount(<IconButtonComponent aria-label={CHARACTERS.STANDARD} />); | ||
|
||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}) => { | ||
await mount(<IconButtonComponent disabled />); | ||
|
||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}} | ||
/> | ||
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}} | ||
/> | ||
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}} | ||
/> | ||
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}} | ||
/> | ||
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}} | ||
/> | ||
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
}} | ||
/> | ||
); | ||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
As above, this const is used several times.
21cd3ac
to
e7a227c
Compare
e7a227c
to
4db9127
Compare
}) => { | ||
await mount(<IconButtonComponent aria-label={CHARACTERS.STANDARD} />); | ||
|
||
const iconLocator = page.getByTestId("icon").locator(".."); |
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.
suggestion: instead of page.getByTestId("icon").locator("..");
could we not just add a general button index/locator? Infact there already is one in locators.ts (line 18), you'd just have to import the index into the file and do iconButton = button(page)
etc. I won't comment this on every instance you've used the above locator but if I were you i'd think about replacing it with this approach.
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.
Also, as the new button(page)
locator is fairly short and simple you can probably move away from the const approach
and just do await button(page).focus()
and then your two expects expect(button(page)...)
if you do this test by test we can cut out a good fair few lines and reduce complexity
); | ||
|
||
test.describe("check props for IconButton component", () => { | ||
test(`should render IconButton with aria-label prop`, async ({ |
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.
suggestion: we've already informed future readers what component is being tested via the describe on the line above, I don't think it's necessary to include the component name on every test description within this describe block.
test.describe( | ||
"check IconButton component focus outlines and border radius", | ||
() => { | ||
test(`should have the expected styling when the focusRedesignOptOut is false`, async ({ |
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.
praise: I like that you've combined the focus/radius tests into one describe here, makes things a lot clearer
await checkAccessibility(page); | ||
}); | ||
|
||
test(`should pass accessibility tests for children prop`, async ({ |
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.
suggestion (non-blocking): i know it was written like this in the cypress test, but i'd change this test description. There is no children
prop and in the test there's only one child. Something like should pass accessibility tests when rendered with a child
should do
await expect(iconLocator).toBeVisible(); | ||
}); | ||
|
||
test(`should render IconButton with children prop`, async ({ |
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.
suggestion (non-blocking): i know it was written like this in the cypress test, but i'd change this test description. There is no children
prop and in the test there's only one child. Something like should render with a child
should do
|
||
const iconLocator = page.getByTestId("icon").locator(".."); | ||
await expect(iconLocator).toBeDisabled(); | ||
await expect(iconLocator).toHaveAttribute("disabled", /.*/); |
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.
suggestion: I think the expect above should be enough for this, instead of the attribute tests
mount, | ||
page, | ||
}) => { | ||
await mount(<IconButtonComponent aria-label={CHARACTERS.STANDARD} />); |
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.
question (non-blocking): I can see we're passing an aria-label
for these focus and radius tests, is there a specific reason for this, or can they be removed. I can see we do this in the cypress test too btw, so I understand why you've included them. Just could get rid if they're not neccessary
4db9127
to
30da757
Compare
playwright/components/index.ts
Outdated
@@ -25,6 +26,10 @@ export const commonDataElementInputPreview = (page: Page) => { | |||
return page.locator(COMMMON_DATA_ELEMENT_INPUT); | |||
}; | |||
|
|||
export const iconButton = (page: Page) => { |
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.
suggestion: this can just be called button
instead of iconButton
as the locator is just finding type="button"
and has no overlap with the IconButton
component, i'd rename this here at least 👍
import React from "react"; | ||
import { test, expect } from "@playwright/experimental-ct-react17"; | ||
import IconButtonComponent from "./component.test-pw"; | ||
import { iconButton } from "../../../playwright/components/index"; |
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.
suggestion: if you've changed the index/locator name from iconButton
to button
you can then do this for the import import { button as iconButton } from "../../../playwright/components/index"
. This way you can keep the name of the locator in your tests and ensure they're still clear what's being tested etc.
}); | ||
|
||
test.describe("check accessibility tests for IconButton component", () => { | ||
test(`should render aria-label prop for accessibility`, async ({ |
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.
suggestion: I think these test descriptions have been changed and i'm not 100% sure why, I think they should all follow something like should pass accessibility tests when rendered with an aria-label
, should pass accessibility tests when rendered with a child
, should pass accessibility tests when disabled
etc.
30da757
to
6dc0a93
Compare
🎉 This PR is included in version 123.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Proposed behaviour
Current behaviour
Checklist
d.ts
file added or updated if requiredQA
Additional context
N/A
Testing instructions