-
Notifications
You must be signed in to change notification settings - Fork 29
Add e2e test for sorting #2883
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
base: main
Are you sure you want to change the base?
Add e2e test for sorting #2883
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
7757281
to
bdda7c4
Compare
7db8aa1
to
3763bcc
Compare
3763bcc
to
a5702a9
Compare
a5702a9
to
234fb89
Compare
234fb89
to
396cc20
Compare
|
||
test('Sorting works', { tag: ['@ce', '@aws', '@docker'] }, async ({ page }) => { | ||
const rolesPage = new RolesPage(page); | ||
rolesPage.goToRolesPage({ scope: org.id }); |
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.
When running the tests locally, it got stuck at this line. Is the function goToRolesPage
supposed to be defined in pages/roles.js
?
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.
396cc20
to
f48d01c
Compare
f48d01c
to
ab20230
Compare
@@ -249,6 +250,8 @@ After all the steps pass, you should see a `Enos operations finished!`. | |||
### Test names and tagging | |||
For admin tests, it's important to tag the test with the correct tags to denote which enos scenario is supported by the test. The test tags should have at least specifying the edition (`@ce`, `@ent`) and at least one specifying the enos test infrastructure (`@aws`, or `@docker`). | |||
|
|||
The `@ent` and `@ce` tags should be added to *all* and *any* test cases that are supported by the respective editions. If a test case can be ran in both editions it should have both tags. |
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 everyone else understood this. Hopefully this helps future me
const rolesPage = new RolesPage(page); | ||
rolesPage.goToRolesPage({ scope: org.id }); | ||
|
||
const table = page.locator('table'); |
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.
Is it possible to update some of these locators to use the recommended locator methods (https://playwright.dev/docs/locators)?
const table = page.locator('table'); | |
const table = page.getByRole('table'); |
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.
Updated the locators, the only ones I kept as selectors were for tbody
since aria doesn't have a role for the rowgroup
belonging to the body separately from the rowgroup
belonging to thead
. I felt like tbody
was better than getByRole('rowgroup').nth(2)
since knowing the 2nd rowgroup is the thead
is less obvious.
It seems like the w3c is aware of this limitation in the current spec:
This role does not differentiate between types of row groups (e.g., thead vs. tbody), but an issue has been raised for WAI-ARIA 2.0.
And there's an open issue around the usefulness of rowgroup
in practice
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.
Would something like this work?
const rowCount = await page
.getByRole('table')
.getByRole('row')
.filter({ hasNot: page.getByRole('columnheader') })
.count();
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 also generally do it this way in desktop when counting table rows
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.
That works great
const columnHeadersOrder = { | ||
name: 0, | ||
id: 2, | ||
}; |
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.
In some other tests, I had the test find the index of the column based on the name. I don't really have a strong opinion and not sure which approach is preferred, but I wanted to just share.
let headersCount = await page
.getByRole('table')
.getByRole('columnheader')
.count();
let fullNameIndex;
let emailIndex;
for (let i = 0; i < headersCount; i++) {
const header = await page
.getByRole('table')
.getByRole('columnheader')
.nth(i)
.innerText();
if (header == 'Full Name') {
fullNameIndex = i;
} else if (header == 'Email') {
emailIndex = i;
}
}
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.
None blocking comment: for learning purposes, I found interesting how to select columns for e2e tests.
I checked both ways, and I do not have a strong opinion either. But I will aim for consistency within.
I do think the suggested way by moduli, seems more semantic, since we pass the column name and the code does the rest. Chad's we pass the index, therefore the user needs to know the index beforehand (not a big deal), but "less computation cost" if that makes any sense.
I think the semantic way seems more resilient, in case we add a column or change the table, the test will need no changes.
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 is definitely more flexible if the column headers ever change. I kept what I had, but after seeing this I did add an assertion to check that the column header labels matched
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 commented before reading your comment @calcaide. Check my most recent push. I think what I was missing was asserting the label which then brings these two implementations much closer together with the main difference being a static assertion vs dynamic references
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.
Yeah I saw it, I think it was like seconds of difference lol all good π
ab20230
to
4bde3b8
Compare
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 left a none blocking comment, mostly for learning purposes.
Run the sorting.spec isolated test successfully!! looks awesome, full coverage of the sorting together with the unit tests.
Thank you for the work πͺ π π
1d2e465
to
9e7b15b
Compare
|
||
const roleNamesToCreate = ['Alpha', 'Beta', 'Delta', 'Gamma', 'Zeta']; | ||
|
||
export const columnHeaderSortButton = (tableLocator, nth) => |
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 haven't ran these yet so I might just be missing something but is there a reason we can't just do something like getByRole('columnheader', { name }).getByRole('button')
instead of using indices?
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.
Yup, that works! Updated
expect( | ||
tableLocator.locator(`thead`).getByRole('columnheader').nth(nth), | ||
).toHaveAttribute('aria-sort', 'ascending'); |
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 here, any reason we couldn't have just grabbed by name directly?
expect( | |
tableLocator.locator(`thead`).getByRole('columnheader').nth(nth), | |
).toHaveAttribute('aria-sort', 'ascending'); | |
expect( | |
getByRole('columnheader', { name })).toHaveAttribute('aria-sort', 'ascending'); |
const rolesPage = new RolesPage(page); | ||
rolesPage.goToRolesPage({ scope: org.id }); | ||
|
||
const table = page.locator('table'); |
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 also generally do it this way in desktop when counting table rows
9e7b15b
to
a131fad
Compare
a131fad
to
3f8ab62
Compare
Description
This pr adds a e2e test for the sorting capability in our tables. The roles resource was chosen because it has support for custom sorting and regular attribute sorting.
ποΈ Jira ticket
Checklist
- [ ] I have added before and after screenshots for UI changes- [ ] I have added JSON response output for API changes- [ ] I have added steps to reproduce and test for bug fixes in the description