-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Dataviews: Add first e2e tests #56634
Conversation
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.
Great start for me. 👍
I'm wondering if there's a way to have some integrations tests for the DataViews in isolation, but that's probably for later, that way we can cover all features as we add them (regardless of context).
Size Change: 0 B Total Size: 1.7 MB ℹ️ View Unchanged
|
Flaky tests detected in d469a97. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7030758518
|
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
async function getRows( page ) { | ||
return page.locator( 'table.dataviews-list-view tbody tr' ); |
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.
Prefer getByRole
so that we can also make sure the rows are accessible.
This is also just a single line that can be inlined rather than making yet a helper (the function should be sync too).
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.
How do you get the tr
s by role?
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.
Considering we just want to grab the template titles for assertions. We can use something like - page.getByRole( 'region', { name: 'Template' } ).getByRole( 'heading', { level: 3 } )
.
Then you can make assertions with toHaveText
or toContainText
.
P.S. The table has no accessible label at the moment.
d469a97
to
16702b1
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.
Thank you! The comments are not blocking and serve more like suggestions for future PRs. :)
const firstTitle = page | ||
.getByRole( 'region', { | ||
name: 'Template', | ||
includeHidden: true, |
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.
Any reason why we need includeHidden
?
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.
The table's first row is hidden from view when we have the dropdown menu open.
name: 'Template', | ||
includeHidden: true, | ||
} ) | ||
.getByRole( 'heading', { |
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 it's also beneficial to include row
to indicate that we're selecting the title of the first row of the table. This could be rewritten into something like:
const firstRowTitle = page.getByRole( 'region', { name: 'Templates' } )
.getByRole( 'table' )
.getByRole( 'row' )
.first()
.getByRole( 'heading', { level: 3 } );
test( 'Sorting', async ( { admin, page } ) => { | ||
await admin.visitSiteEditor( { path: '/wp_template/all' } ); | ||
// Descending by title. | ||
await page.getByRole( 'button', { name: 'Template' } ).click(); |
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.
It's a bit unclear to me at first glance that we're clicking on the column header. Perhaps this is clearer?
const table = page.getByRole( 'region', { name: 'Templates' } )
.getByRole( 'table' );
await table
.getByRole( 'columnheader', { name: 'Template' } )
.getByRole( 'button', { name: 'Template' } )
.click();
await admin.visitSiteEditor( { path: '/wp_template/all' } ); | ||
// Descending by title. | ||
await page.getByRole( 'button', { name: 'Template' } ).click(); | ||
await page.getByRole( 'menuitem', { name: 'Sort descending' } ).click(); |
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 just nitpicking but we can also scope it under a menu to make this slightly clearer that we're clicking inside a dropdown:
await page
.getByRole( 'menu', { name: 'Template' } )
.getByRole( 'menuitem', { name: 'Sort descending' } )
.click();
.click(); | ||
await expect( titles ).toHaveCount( 2 ); | ||
|
||
await requestUtils.deleteAllTemplates( 'wp_template' ); |
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.
We can put the cleaning up code inside afterEach
and afterAll
so that when the test fails it still runs.
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 has proven good advice sooner than expected. Thanks, Kai!
* Dataviews: Add first e2e tests * refactor tests and add `createTemplate` util
What?
Part of: #55083
This PR adds some initial e2e tests for DataViews