This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E tests for Product Archive Template and Legacy Block (#5748)
Also: * Refactors the function to add a custom paragraph * Add front-end test for archive template * Use WordPress data to guarantee block presence * Use WordPress data instead of selectors to match blocks
- Loading branch information
1 parent
e1e8511
commit bdfd2cb
Showing
4 changed files
with
192 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
tests/e2e/specs/backend/__snapshots__/site-editing-templates.test.js.snap
This file contains 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 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 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 { URL } from 'url'; | ||
import { activateTheme } from '@wordpress/e2e-test-utils'; | ||
|
||
import { BASE_URL } from '../../utils'; | ||
|
||
const SELECTORS = { | ||
productArchivePage: { | ||
paginationUI: '.woocommerce-pagination', | ||
productContainers: '.products .product', | ||
productsList: '.products', | ||
resultsCount: '.woocommerce-result-count', | ||
}, | ||
}; | ||
|
||
describe( 'Legacy Template blocks', () => { | ||
beforeAll( async () => { | ||
await activateTheme( 'emptytheme' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwentyone' ); | ||
} ); | ||
|
||
describe( 'Product Archive block', () => { | ||
it( 'renders a list of products with their count and pagination', async () => { | ||
const { productArchivePage } = SELECTORS; | ||
|
||
await page.goto( new URL( '/?post_type=product', BASE_URL ) ); | ||
|
||
await page.waitForSelector( productArchivePage.productsList ); | ||
await page.waitForSelector( productArchivePage.resultsCount ); | ||
|
||
const { displayedCount, shouldHavePaginationUI } = await page.$eval( | ||
productArchivePage.resultsCount, | ||
( $el ) => { | ||
const resultsCountRegEx = /1–(\d+)|\d+/; | ||
const matches = $el.textContent.match( resultsCountRegEx ); | ||
|
||
// Depending on pagination, string can be either: | ||
// a) 'Showing x–y of z results' | ||
// b) 'Showing all x results' | ||
return { | ||
displayedCount: matches[ 1 ] || matches[ 0 ], | ||
shouldHavePaginationUI: !! matches[ 1 ], | ||
}; | ||
} | ||
); | ||
|
||
if ( shouldHavePaginationUI ) { | ||
await expect( page ).toMatchElement( | ||
productArchivePage.paginationUI | ||
); | ||
} | ||
|
||
const $productElements = await page.$$( | ||
productArchivePage.productContainers | ||
); | ||
|
||
expect( $productElements ).toHaveLength( Number( displayedCount ) ); | ||
} ); | ||
} ); | ||
} ); |
This file contains 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