[e2e tests] Enhance product reviews tests (#44644)

* Rename test

* Updated tests to use work with more reviews

* Add changelog

* Add new test: can filter the reviews by product

* Fix lint errors and warnings
This commit is contained in:
Adrian Moldovan 2024-02-15 23:30:47 +02:00 committed by GitHub
parent fce80c40c0
commit ddf908d7fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 122 additions and 85 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
E2E tests: update product review tests to work with more reviews

View File

@ -3,79 +3,118 @@ const { test: baseTest, expect } = require( '../../fixtures' );
baseTest.describe( 'Product Reviews > Edit Product Review', () => {
const test = baseTest.extend( {
storageState: process.env.ADMINSTATE,
testData: async ( { api }, use ) => {
reviews: async ( { api }, use ) => {
const timestamp = Date.now().toString();
let product = {};
let review = {};
const products = [];
const reviews = [];
// Create the product
await api
.post( 'products', {
name: `Review me ${ timestamp }`,
type: 'simple',
regular_price: '9.99',
} )
.then( ( response ) => {
product = response.data;
} );
// Create the products
for ( let i = 0; i < 2; i++ ) {
await api
.post( 'products', {
name: `Product ${ i } ${ timestamp }`,
type: 'simple',
regular_price: '9.99',
} )
.then( ( response ) => {
products.push( response.data );
} );
}
// Create the product review
await api
.post( 'products/reviews', {
product_id: product.id,
review: `Nice one, Playwright! ${ timestamp }`,
reviewer: 'John Doe',
reviewer_email: `john.doe.${ timestamp }@example.com`,
rating: ( Math.random() * ( 5 - 1 ) + 1 ).toFixed( 0 ),
} )
.then( ( response ) => {
review = response.data;
} );
// Create the product reviews
for ( const product of products ) {
await api
.post( 'products/reviews', {
product_id: product.id,
review: `Nice product ${ product.name }, at ${ timestamp }`,
reviewer: 'John Doe',
reviewer_email: `john.doe.${ timestamp }@example.com`,
rating: ( Math.random() * ( 5 - 1 ) + 1 ).toFixed( 0 ),
} )
.then( ( response ) => {
reviews.push( response.data );
} );
}
await use( { product, review } );
await use( reviews );
// Cleanup
await api.delete( `products/reviews/${ review.id }`, {
force: true,
await api.delete( `products/reviews/batch`, {
delete: reviews.map( ( review ) => review.id ),
} );
await api.delete( `products/${ product.id }`, {
force: true,
await api.post( `products/batch`, {
delete: products.map( ( product ) => product.id ),
} );
},
} );
test( 'can view product review', async ( { page, testData } ) => {
test( 'can view products reviews list', async ( { page, reviews } ) => {
await page.goto(
`wp-admin/edit.php?post_type=product&page=product-reviews`
);
await expect(
page.getByRole( 'cell', { name: testData.review.review } )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: testData.product.name } )
).toBeVisible();
await expect(
page.getByLabel( `${ testData.review.rating } out of 5` )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: testData.review.reviewer_email } )
).toBeVisible();
for ( const review of reviews ) {
const reviewRow = page.locator( `#comment-${ review.id }` );
await expect(
reviewRow.locator( '[data-colname="Author"]' )
).toContainText( review.reviewer_email );
await expect(
reviewRow
.locator( '[data-colname="Rating"]' )
.getByLabel( `${ review.rating } out of 5` )
).toBeVisible();
await expect(
reviewRow.locator( '[data-colname="Review"]' )
).toContainText( review.review );
await expect(
reviewRow
.locator( '[data-colname="Product"]' )
.getByRole( 'link' )
.first()
).toContainText( review.product_name );
}
} );
test( 'can quick edit product review', async ( { page, testData } ) => {
test( 'can filter the reviews by product', async ( { page, reviews } ) => {
await page.goto(
`wp-admin/edit.php?post_type=product&page=product-reviews`
);
await expect(
page.getByRole( 'cell', { name: testData.review.review } )
).toBeVisible();
//Hover over the product review to have 'Quick Edit' displayed
await page.hover( `#comment-${ testData.review.id }` );
const review = reviews[ 0 ];
await page.getByText( 'Search for a product' ).click();
await page.locator( '.select2-search__field' ).click();
await page
.locator( `#comment-${ testData.review.id }` )
.getByRole( 'button', { name: 'Quick Edit' } )
.click();
.locator( '.select2-search__field' )
.fill( review.product_name );
await page.getByRole( 'option', { name: review.product_name } ).click();
await page.getByRole( 'button', { name: 'Filter' } ).click();
// Flakiness warning: if the filtering is too slow, some other reviews might still be displayed
// We need to find something to assess filtering is ready
const rows = await page.locator( '#the-comment-list tr' ).all();
for ( const reviewRow of rows ) {
await expect(
reviewRow
.locator( '[data-colname="Product"]' )
.getByRole( 'link' )
.first()
).toContainText( review.product_name );
}
} );
test( 'can quick edit a product review', async ( { page, reviews } ) => {
const review = reviews[ 0 ];
await page.goto(
`wp-admin/edit.php?post_type=product&page=product-reviews`
);
const reviewRow = page.locator( `#comment-${ review.id }` );
await reviewRow.hover();
await reviewRow.getByRole( 'button', { name: 'Quick Edit' } ).click();
// Create new review, Quick Edit it and save
const updatedQuickReview = `(quickly edited ${ Date.now() })`;
@ -86,20 +125,15 @@ baseTest.describe( 'Product Reviews > Edit Product Review', () => {
await page.getByRole( 'button', { name: 'Update Comment' } ).click();
// Verify that the edited comment is there
await expect( page.getByText( updatedQuickReview ) ).toBeVisible();
await expect( reviewRow.getByText( updatedQuickReview ) ).toBeVisible();
} );
test( 'can edit product review', async ( { page, testData } ) => {
await page.goto(
`wp-admin/edit.php?post_type=product&page=product-reviews`
);
await expect(
page.getByRole( 'cell', { name: testData.review.review } )
).toBeVisible();
test( 'can edit a product review', async ( { page, reviews } ) => {
const review = reviews[ 0 ];
//Go to the Edit page of the review
// Go to the Edit page of the review
await page.goto(
`wp-admin/comment.php?action=editcomment&c=${ testData.review.id }`
`wp-admin/comment.php?action=editcomment&c=${ review.id }`
);
await expect( page.getByText( 'Edit Review' ) ).toBeVisible();
@ -119,15 +153,18 @@ baseTest.describe( 'Product Reviews > Edit Product Review', () => {
await page.goto(
`wp-admin/edit.php?post_type=product&page=product-reviews`
);
const reviewRow = page.locator( `#comment-${ review.id }` );
await expect(
page.getByRole( 'cell', { name: updatedReview } )
reviewRow.getByRole( 'cell', { name: updatedReview } )
).toBeVisible();
await expect(
page.getByLabel( `${ updatedRating } out of 5` )
reviewRow.getByLabel( `${ updatedRating } out of 5` )
).toBeVisible();
// Verify that the edited comment is in the shop's product page
await page.locator( 'a.comments-view-item-link' ).click();
await reviewRow.locator( 'a.comments-view-item-link' ).click();
await page.click( '#tab-reviews' );
await expect(
page.locator( '.comment_container' ).first()
@ -137,51 +174,47 @@ baseTest.describe( 'Product Reviews > Edit Product Review', () => {
).toBeVisible();
} );
test( 'can delete product review', async ( { page, testData } ) => {
test( 'can delete a product review', async ( { page, reviews } ) => {
const review = reviews[ 0 ];
await page.goto(
`wp-admin/edit.php?post_type=product&page=product-reviews`
);
await expect(
page.getByRole( 'cell', { name: testData.review.review } )
).toBeVisible();
const reviewerName = testData.review.reviewer;
//Hover over the product review to have 'Edit' displayed
await page.hover( `#comment-${ testData.review.id }` );
const reviewRow = page.locator( `#comment-${ review.id }` );
await reviewRow.hover();
// Select Trash action, check confirmation prompt and undo
await page
.locator( `#comment-${ testData.review.id }` )
.getByRole( 'button', { name: 'Trash' } )
.click();
await reviewRow.getByRole( 'button', { name: 'Trash' } ).click();
await expect(
page.getByText( `Comment by ${ reviewerName } moved to the Trash` )
page.getByText(
`Comment by ${ review.reviewer } moved to the Trash`
)
).toBeVisible();
await page.getByRole( 'button', { name: 'Undo' } ).click();
// Verify that the review has been restored
await expect(
page.getByRole( 'cell', { name: testData.review.review } )
reviewRow.getByRole( 'cell', { name: review.review } )
).toBeVisible();
// Select Trash action and delete it permanently
await page
.locator( `#comment-${ testData.review.id }` )
.getByRole( 'button', { name: 'Trash' } )
.click();
await reviewRow.getByRole( 'button', { name: 'Trash' } ).click();
await expect(
page.getByText( `Comment by ${ reviewerName } moved to the Trash` )
page.getByText(
`Comment by ${ review.reviewer } moved to the Trash`
)
).toBeVisible();
// Verify that the review in the trash
await page.click( 'a[href*="comment_status=trash"]' );
await expect(
page.getByRole( 'cell', { name: testData.review.review } )
reviewRow.getByRole( 'cell', { name: review.review } )
).toBeVisible();
// Check that the review is in the trash via URL
await page.goto(
`wp-admin/comment.php?action=editcomment&c=${ testData.review.id }`
`wp-admin/comment.php?action=editcomment&c=${ review.id }`
);
await expect(
page.getByText(