delete coupons instead of trashing them

This commit is contained in:
Ron Rennick 2021-09-10 15:30:09 -03:00
parent a6e4cf2023
commit 20cb447204
8 changed files with 2825 additions and 23 deletions

2732
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,9 @@
# Unreleased
## Changed
- New coupon test deletes the coupon instead of trashing it.
# 0.1.6
## Fixed

View File

@ -1,12 +1,13 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests */
/**
* Internal dependencies
*/
const {
merchant,
clickTab,
verifyPublishAndTrash
AdminEdit,
factories,
} = require( '@woocommerce/e2e-utils' );
const { Coupon } = require( '@woocommerce/api' );
/**
* External dependencies
@ -39,14 +40,18 @@ const runCreateCouponTest = () => {
await expect(page).toSelect('#discount_type', 'Fixed cart discount');
await expect(page).toFill('#coupon_amount', '100');
// Publish coupon, verify that it was published. Trash coupon, verify that it was trashed.
await verifyPublishAndTrash(
// Publish coupon, verify that it was published.
await AdminEdit.verifyPublish(
'#publish',
'.notice',
'Coupon updated.',
'1 coupon moved to the Trash.'
);
// Delete the coupon
const couponId = await AdminEdit.getId();
if ( couponId ) {
const repository = Coupon.restRepository( factories.api.withDefaultPermalinks );
await repository.delete( couponId );
}
});
});
}

View File

@ -1,5 +1,10 @@
# Unreleased
## Added
- `utils.waitForTimeout( delay )` pause processing for `delay` milliseconds
- `AdminEdit`, `OrderEdit` classes with utility functions for the respctive edit screens
# 0.1.6
## Added

View File

@ -1,6 +1,7 @@
/**
* Take a string name and generate the slug for it.
* Example: 'My plugin' => 'my-plugin'
* @param text string to convert to a slug
*
* Sourced from: https://gist.github.com/spyesx/561b1d65d4afb595f295
**/
@ -31,3 +32,12 @@ export const describeIf = ( condition ) =>
// Conditionally determine whether or not to skip a test case
export const itIf = ( condition ) =>
condition ? it : it.skip;
/**
* Wait for a timeout in milliseconds
* @param timeout delay time in milliseconds
* @returns {Promise<void>}
*/
export const waitForTimeout = async ( timeout ) => {
await new Promise( ( resolve ) => setTimeout( resolve, timeout ) );
}

View File

@ -12,3 +12,4 @@ export * from './old-flows';
export * from './components';
export * from './page-utils';
export * from './system-environment';
export * from './pages/admin-edit';

View File

@ -3,6 +3,11 @@
*/
import { pressKeyWithModifier } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { AdminEdit, OrderEdit } from './pages/admin-edit';
/**
* Perform a "select all" and then fill a input.
*
@ -117,23 +122,10 @@ export const waitForSelectorWithoutThrow = async ( selector, timeoutInSeconds =
* @param {string} trashVerification
*/
export const verifyPublishAndTrash = async ( button, publishNotice, publishVerification, trashVerification ) => {
// Wait for auto save
await page.waitFor( 2000 );
// Publish
await expect( page ).toClick( button );
await page.waitForSelector( publishNotice );
// Verify
await expect( page ).toMatchElement( publishNotice, { text: publishVerification } );
if ( button === '.order_actions li .save_order' ) {
await expect( page ).toMatchElement( '#select2-order_status-container', { text: 'Processing' } );
await expect( page ).toMatchElement(
'#woocommerce-order-notes .note_content',
{
text: 'Order status changed from Pending payment to Processing.',
}
);
await OrderEdit.verifyPublish( button, publishNotice, publishVerification );
} else {
await AdminEdit.verifyPublish( button, publishNotice, publishVerification );
}
// Trash

View File

@ -0,0 +1,55 @@
import { utils } from '../flows';
export class AdminEdit {
/**
* Publish the object being edited and verify published status
*
* @param button Publish button selector
* @param publishNotice Publish notice selector
* @param publishVerification Expected notice on successful publish
* @returns {Promise<void>}
*/
async verifyPublish( button, publishNotice, publishVerification ) {
// Wait for auto save
await utils.waitForTimeout( 2000 );
// Publish and verify
await expect( page ).toClick( button );
await page.waitForSelector( publishNotice );
await expect( page ).toMatchElement( publishNotice, { text: publishVerification } );
}
/**
* Get the ID of the object being edited
*
* @returns {Promise<*>}
*/
async getId() {
let postId = await page.$( '#post_ID' );
let objectID = await page.evaluate( element => element.value, postId );
return objectID;
}
}
export class OrderEdit extends AdminEdit {
/**
* Publish the object being edited and verify published status
*
* @param button Publish button selector
* @param publishNotice Publish notice selector
* @param publishVerification Expected notice on successful publish
* @returns {Promise<void>}
*/
async verifyPublish( button, publishNotice, publishVerification ) {
AdminEdit.verifyPublish( button, publishNotice, publishVerification );
await expect( page ).toMatchElement( '#select2-order_status-container', { text: 'Processing' } );
await expect( page ).toMatchElement(
'#woocommerce-order-notes .note_content',
{
text: 'Order status changed from Pending payment to Processing.',
}
);
}
}