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
E2E: Product Query: Popular filters presets #7749
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
42b9c13
wip: start working on popular filters
dinhtungdu 3b8d03e
test default preset
dinhtungdu 608aa8a
Merge branch 'trunk' into tests/popular-filters
dinhtungdu 6645dfa
Merge branch 'trunk' into tests/popular-filters
dinhtungdu 262f2ee
test file clean up
dinhtungdu 2646666
test products displayed in editor preview and block front end
dinhtungdu f71c166
give editor time to update after resetting content
dinhtungdu 0029728
restore the test name
dinhtungdu 34a7a6e
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu 1b1b260
try: fixing flaky test by waiting for suggestion items
dinhtungdu 09ceb7e
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu 2e9799d
use block.name when possible
dinhtungdu a0c2716
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu eb48d53
update atomic tests to reflect changes introduced in #7815
dinhtungdu c96efbc
wait for elements before assertion
dinhtungdu 8a65139
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu 34c21ad
update rating test as the default template removed rating block
dinhtungdu 90b9f8e
fix rating test
dinhtungdu ef76d5a
fix advanced filters flaky test
dinhtungdu b72e1ae
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu 2f353d4
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu 3ba8e28
migrate improvements from #7719
dinhtungdu 2cb26e7
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu ba03443
ensure the setting is applied in the editor before saving and checkin…
dinhtungdu c548d57
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu a0918ee
Merge branch 'trunk' into fix/flaky-test-interact-with-form-token-field
dinhtungdu 58f3741
Merge branch 'fix/flaky-test-interact-with-form-token-field' into tes…
dinhtungdu ce275b8
import const and utilities from common.ts
dinhtungdu c926aa8
test sorted by title preset
dinhtungdu 5724c57
extract common logic to utilites, Newest preset test
dinhtungdu 5622f56
best selling and top rated test
dinhtungdu 909cc7a
Merge branch 'trunk' into tests/popular-filters
dinhtungdu 66dafac
replace openBlockEditorSettings by ensureSidebarOpened
dinhtungdu 1f02fb1
fix flakiness of setting preset
dinhtungdu 277bd68
fix: shorter and faster way to reset the product query page
dinhtungdu cf8fb22
Merge branch 'trunk' into tests/popular-filters
dinhtungdu 7259f2d
try: not using beforeEeach
dinhtungdu fdbdd39
Revert "try: not using beforeEeach"
dinhtungdu 4832a0c
try: timeout
dinhtungdu 748d48b
use timeout after selecting the preset, giving the editor time to update
dinhtungdu 53960ec
verify the popular filter selection
dinhtungdu 1c79015
Merge branch 'trunk' into tests/popular-filters
dinhtungdu 3638cd2
Merge branch 'trunk' into tests/popular-filters
dinhtungdu e60cf03
use jest.each to avoid duplicated code
dinhtungdu f8ee1ab
Use ensureSidebarOpened from @wordpress/e2e-test-utils
dinhtungdu 691cfb9
move utilities for popular filter tests specifically to the test file.
dinhtungdu 8afad60
more explicit tests for on sale and stock status
dinhtungdu 12121b5
test default state once
dinhtungdu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
1 change: 0 additions & 1 deletion
1
tests/e2e/specs/backend/__fixtures__/product-query.fixture.json
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tests/e2e/specs/backend/__fixtures__/products-beta.fixture.json
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 @@ | ||
{"title":"Products (Beta) Block","pageContent":"<!-- wp:query {\"queryId\":1,\"query\":{\"perPage\":9,\"pages\":0,\"offset\":0,\"postType\":\"product\",\"order\":\"asc\",\"orderBy\":\"title\",\"author\":\"\",\"search\":\"\",\"exclude\":[],\"sticky\":\"\",\"inherit\":false,\"__woocommerceAttributes\":[],\"__woocommerceStockStatus\":[\"instock\",\"outofstock\",\"onbackorder\"]},\"displayLayout\":{\"type\":\"flex\",\"columns\":3},\"namespace\":\"woocommerce/product-query\"} --><div class=\"wp-block-query\"><!-- wp:post-template --><!-- wp:woocommerce/product-image {\"isDescendentOfQueryLoop\":true} /--><!-- wp:post-title {\"textAlign\":\"center\",\"level\":3,\"fontSize\":\"medium\",\"__woocommerceNamespace\":\"woocommerce/product-query/product-title\"} /--><!-- wp:woocommerce/product-price {\"isDescendentOfQueryLoop\":true,\"textAlign\":\"center\",\"fontSize\":\"small\"} /--><!-- wp:woocommerce/product-button {\"isDescendentOfQueryLoop\":true,\"textAlign\":\"center\",\"fontSize\":\"small\"} /--><!-- /wp:post-template --><!-- wp:query-pagination {\"layout\":{\"type\":\"flex\",\"justifyContent\":\"center\"}} --><!-- wp:query-pagination-previous /--><!-- wp:query-pagination-numbers /--><!-- wp:query-pagination-next /--><!-- /wp:query-pagination --><!-- wp:query-no-results --><!-- wp:paragraph {\"placeholder\":\"Add text or blocks that will display when a query returns no results.\"} --><p></p><!-- /wp:paragraph --><!-- /wp:query-no-results --></div><!-- /wp:query -->"} |
156 changes: 156 additions & 0 deletions
156
tests/e2e/specs/backend/product-query/advanced-filters.test.ts
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,156 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
saveOrPublish, | ||
selectBlockByName, | ||
findToolsPanelWithTitle, | ||
getFixtureProductsData, | ||
shopper, | ||
getToggleIdByLabel, | ||
} from '@woocommerce/blocks-test-utils'; | ||
import { ElementHandle } from 'puppeteer'; | ||
import { setCheckbox } from '@woocommerce/e2e-utils'; | ||
import { ensureSidebarOpened, canvas } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { GUTENBERG_EDITOR_CONTEXT, describeOrSkip } from '../../../utils'; | ||
import { | ||
block, | ||
SELECTORS, | ||
resetProductQueryBlockPage, | ||
toggleAdvancedFilter, | ||
getPreviewProducts, | ||
getFrontEndProducts, | ||
clearSelectedTokens, | ||
selectToken, | ||
} from './common'; | ||
|
||
describeOrSkip( GUTENBERG_EDITOR_CONTEXT === 'gutenberg' )( | ||
`${ block.name } > Advanced Filters`, | ||
() => { | ||
let $productFiltersPanel: ElementHandle< Node >; | ||
const defaultCount = getFixtureProductsData().length; | ||
const saleCount = getFixtureProductsData( 'sale_price' ).length; | ||
const outOfStockCount = getFixtureProductsData( 'stock_status' ).filter( | ||
( status: string ) => status === 'outofstock' | ||
).length; | ||
|
||
beforeEach( async () => { | ||
/** | ||
* Reset the block page before each test to ensure the block is | ||
* inserted in a known state. This is also needed to ensure each | ||
* test can be run individually. | ||
*/ | ||
await resetProductQueryBlockPage(); | ||
await ensureSidebarOpened(); | ||
await selectBlockByName( block.slug ); | ||
$productFiltersPanel = await findToolsPanelWithTitle( | ||
'Advanced Filters' | ||
); | ||
} ); | ||
|
||
/** | ||
* Reset the content of Product Query Block page after this test suite | ||
* to avoid breaking other tests. | ||
*/ | ||
afterAll( async () => { | ||
await resetProductQueryBlockPage(); | ||
} ); | ||
|
||
it( 'Editor preview shows all products by default', async () => { | ||
expect( await getPreviewProducts() ).toHaveLength( defaultCount ); | ||
} ); | ||
|
||
it( 'On the front end, blocks shows all products by default', async () => { | ||
expect( await getPreviewProducts() ).toHaveLength( defaultCount ); | ||
} ); | ||
|
||
describe( 'Sale Status', () => { | ||
it( 'Sale status is disabled by default', async () => { | ||
await expect( $productFiltersPanel ).not.toMatch( | ||
'Show only products on sale' | ||
); | ||
} ); | ||
|
||
it( 'Can add and remove Sale Status filter', async () => { | ||
await toggleAdvancedFilter( 'Sale status' ); | ||
await expect( $productFiltersPanel ).toMatch( | ||
'Show only products on sale' | ||
); | ||
await toggleAdvancedFilter( 'Sale status' ); | ||
await expect( $productFiltersPanel ).not.toMatch( | ||
'Show only products on sale' | ||
); | ||
} ); | ||
|
||
it( 'Enable Sale Status > Editor preview shows only on sale products', async () => { | ||
await toggleAdvancedFilter( 'Sale status' ); | ||
await setCheckbox( | ||
await getToggleIdByLabel( 'Show only products on sale' ) | ||
); | ||
expect( await getPreviewProducts() ).toHaveLength( saleCount ); | ||
} ); | ||
|
||
it( 'Enable Sale Status > On the front end, block shows only on sale products', async () => { | ||
await toggleAdvancedFilter( 'Sale status' ); | ||
await setCheckbox( | ||
await getToggleIdByLabel( 'Show only products on sale' ) | ||
); | ||
await canvas().waitForSelector( SELECTORS.productsGrid ); | ||
await saveOrPublish(); | ||
await shopper.block.goToBlockPage( block.name ); | ||
expect( await getFrontEndProducts() ).toHaveLength( saleCount ); | ||
} ); | ||
} ); | ||
|
||
describe( 'Stock Status', () => { | ||
it( 'Stock status is enabled by default', async () => { | ||
await expect( $productFiltersPanel ).toMatchElement( | ||
SELECTORS.formTokenField.label, | ||
{ text: 'Stock status' } | ||
); | ||
} ); | ||
|
||
it( 'Can add and remove Stock Status filter', async () => { | ||
await toggleAdvancedFilter( 'Stock status' ); | ||
await expect( $productFiltersPanel ).not.toMatchElement( | ||
SELECTORS.formTokenField.label, | ||
{ text: 'Stock status' } | ||
); | ||
await toggleAdvancedFilter( 'Stock status' ); | ||
await expect( $productFiltersPanel ).toMatchElement( | ||
SELECTORS.formTokenField.label, | ||
{ text: 'Stock status' } | ||
); | ||
} ); | ||
|
||
it( 'All statuses are enabled by default', async () => { | ||
await expect( $productFiltersPanel ).toMatch( 'In stock' ); | ||
await expect( $productFiltersPanel ).toMatch( 'Out of stock' ); | ||
await expect( $productFiltersPanel ).toMatch( 'On backorder' ); | ||
Comment on lines
+131
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal, but should this also be perhaps related to the fixture data? We could have a loop on something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} ); | ||
|
||
it( 'Set Stock status to Out of stock > Editor preview shows only out-of-stock products', async () => { | ||
await clearSelectedTokens( $productFiltersPanel ); | ||
await selectToken( 'Stock status', 'Out of stock' ); | ||
expect( await getPreviewProducts() ).toHaveLength( | ||
outOfStockCount | ||
); | ||
} ); | ||
|
||
it( 'Set Stock status to Out of stock > On the front end, block shows only out-of-stock products', async () => { | ||
await clearSelectedTokens( $productFiltersPanel ); | ||
await selectToken( 'Stock status', 'Out of stock' ); | ||
await canvas().waitForSelector( SELECTORS.productsGrid ); | ||
await saveOrPublish(); | ||
await shopper.block.goToBlockPage( block.name ); | ||
expect( await getFrontEndProducts() ).toHaveLength( | ||
outOfStockCount | ||
); | ||
} ); | ||
} ); | ||
} | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What do you think about reusing more code here by extracting common/duplicated lines into utility functions to make the tests easier to read and maintain?
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.
Can you suggest something here? At the moment, I don't have a good idea to refactor this further.
From the test code I can see the test perform these step:
I'm curious about what you read from the test. If we can do anything to increase the readability, I'm all in.
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 was thinking something along these lines (for the editor preview test, for example):
But that is super minor/a nit! The tests are now structured nicely, a-ok to keep them as-is :)