Skip to content

Commit

Permalink
Merge pull request #2363 from woocommerce/dev/e2e-classic-product-editor
Browse files Browse the repository at this point in the history
Add E2E tests for the integration in the classic product editor
  • Loading branch information
eason9487 authored Apr 15, 2024
2 parents 7f6c4a4 + b36f43f commit 33c35a8
Show file tree
Hide file tree
Showing 6 changed files with 981 additions and 100 deletions.
3 changes: 3 additions & 0 deletions tests/e2e/bin/test-env-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ wp-env run tests-cli wp wc payment_gateway update cod --enabled=1 --user=admin

echo -e 'Set the tour of product block editor to not display \n'
wp-env run tests-cli wp option update woocommerce_block_product_tour_shown 'yes'

echo -e 'Set the variable product tour of classic product editor to not display \n'
wp-env run tests-cli wp user meta update admin woocommerce_admin_variable_product_tour_shown '"yes"'
3 changes: 3 additions & 0 deletions tests/e2e/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"variations": [
{
"menu_order": 1,
"regular_price": "19.99",
"attributes": [
{
Expand All @@ -61,6 +62,7 @@
]
},
{
"menu_order": 2,
"regular_price": "18.99",
"attributes": [
{
Expand All @@ -74,6 +76,7 @@
]
},
{
"menu_order": 3,
"regular_price": "17.99",
"attributes": [
{
Expand Down
90 changes: 28 additions & 62 deletions tests/e2e/specs/product-editor/block-integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,45 +567,10 @@ test.describe( 'Product Block Editor integration', () => {
await editorUtils.fillProductName();
await editorUtils.clickPluginTab();

const {
gtin,
mpn,
brand,
condition,
gender,
size,
sizeSystem,
sizeType,
color,
material,
pattern,
ageGroup,
multipack,
isBundle,
availabilityDate,
availabilityTime,
adultContent,
} = editorUtils.getAllProductAttributes();

const pairs = [
[ gtin, '3234567890126' ],
[ mpn, 'GO12345OOGLE' ],
[ brand, 'e2e_test_woocommerce_brands' ],
[ condition, 'new' ],
[ gender, 'unisex' ],
[ size, 'Good for everybody' ],
[ sizeSystem, 'JP' ],
[ sizeType, 'regular' ],
[ color, 'Cherry blossom' ],
[ material, 'Titanium alloy' ],
[ pattern, 'Cyberpunk' ],
[ ageGroup, 'kids' ],
[ multipack, '9999' ],
[ isBundle, 'no' ],
[ availabilityDate, '2024-02-29' ],
[ availabilityTime, '23:59' ],
[ adultContent, 'no' ],
];
const pairs =
await editorUtils.getAvailableProductAttributesWithTestValues();

expect( pairs ).toHaveLength( 17 );

/*
* Assert:
Expand Down Expand Up @@ -639,35 +604,22 @@ test.describe( 'Product Block Editor integration', () => {
}
} );

test( 'Save product attributes to variation product', async () => {
test( 'Save all product attributes to variation product', async () => {
await editorUtils.gotoEditVariableProductPage();
await editorUtils.gotoEditVariationProductPage();
await editorUtils.clickPluginTab();

/*
* Since the testing of all attributes is already covered in the simple product test case above.
* This case only tests a few key attributes to ensure the data saving works for variation product.
*/
const {
condition,
color,
multipack,
availabilityDate,
availabilityTime,
} = editorUtils.getAllProductAttributes();
const pairs =
await editorUtils.getAvailableProductAttributesWithTestValues();

const pairs = [
[ condition, 'new' ],
[ color, 'Cherry blossom' ],
[ multipack, '9999' ],
[ availabilityDate, '2024-02-29' ],
[ availabilityTime, '23:59' ],
];

for ( const [ attribute ] of pairs ) {
await expect( attribute ).toHaveValue( '' );
}
expect( pairs ).toHaveLength( 16 );

/*
* Assert:
* - All attributes are empty or default
* - Save all attributes
* - After saving, attribute values remain the same
*/
for ( const [ attribute, value ] of pairs ) {
await expect( attribute ).toHaveValue( '' );
await editorUtils.setAttributeValue( attribute, value );
Expand All @@ -678,6 +630,20 @@ test.describe( 'Product Block Editor integration', () => {
for ( const [ attribute, value ] of pairs ) {
await expect( attribute ).toHaveValue( value );
}

/*
* Assert:
* - It allows to save all attributes to empty or default
*/
for ( const [ attribute ] of pairs ) {
await editorUtils.setAttributeValue( attribute, '' );
}

await editorUtils.save();

for ( const [ attribute ] of pairs ) {
await expect( attribute ).toHaveValue( '' );
}
} );

test.afterEach( async () => {
Expand Down
Loading

0 comments on commit 33c35a8

Please sign in to comment.