Implement it.each on wp-admin-order-status-filters.test.js
This commit is contained in:
parent
c25b23aafc
commit
ad139d821b
|
@ -12,50 +12,28 @@ const {
|
||||||
const statusColumnTextSelector = 'mark.order-status > span';
|
const statusColumnTextSelector = 'mark.order-status > span';
|
||||||
|
|
||||||
// Define order statuses to filter against
|
// Define order statuses to filter against
|
||||||
const orderStatus = {
|
const orderStatus = [
|
||||||
pending: {
|
['Pending payment', 'wc-pending'],
|
||||||
name: 'wc-pending',
|
['Processing', 'wc-processing'],
|
||||||
description: { text: 'Pending payment' },
|
['On hold', 'wc-on-hold'],
|
||||||
},
|
['Completed', 'wc-completed'],
|
||||||
processing: {
|
['Cancelled', 'wc-cancelled'],
|
||||||
name: 'wc-processing',
|
['Refunded', 'wc-refunded'],
|
||||||
description: { text: 'Processing' },
|
['Failed', 'wc-failed']
|
||||||
},
|
];
|
||||||
onHold: {
|
|
||||||
name: 'wc-on-hold',
|
|
||||||
description: { text: 'On hold' },
|
|
||||||
},
|
|
||||||
completed: {
|
|
||||||
name: 'wc-completed',
|
|
||||||
description: { text: 'Completed' },
|
|
||||||
},
|
|
||||||
cancelled: {
|
|
||||||
name: 'wc-cancelled',
|
|
||||||
description: { text: 'Cancelled' },
|
|
||||||
},
|
|
||||||
refunded: {
|
|
||||||
name: 'wc-refunded',
|
|
||||||
description: { text: 'Refunded' },
|
|
||||||
},
|
|
||||||
failed: {
|
|
||||||
name: 'wc-failed',
|
|
||||||
description: { text: 'Failed' },
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const runOrderStatusFiltersTest = () => {
|
const runOrderStatusFiltersTest = () => {
|
||||||
describe('WooCommerce Orders > Filter Orders by Status', () => {
|
describe('WooCommerce Orders > Filter Orders by Status', () => {
|
||||||
beforeAll(async () => {
|
beforeAll( async () => {
|
||||||
// First, let's create some orders we can filter against
|
// First, let's create some orders we can filter against
|
||||||
const statuses = Object.entries(orderStatus).map((entryPair) => {
|
const statuses = orderStatus.map(
|
||||||
const statusName = entryPair[1].name;
|
(pair) => pair[1].substring(3) // remove the 'wc-' part
|
||||||
|
);
|
||||||
return statusName.replace('wc-', '');
|
|
||||||
});
|
|
||||||
await batchCreateOrders(statuses);
|
await batchCreateOrders(statuses);
|
||||||
|
|
||||||
// Next, let's login
|
// Next, let's login and navigate to the Orders page
|
||||||
await merchant.login();
|
await merchant.login();
|
||||||
|
await merchant.openAllOrdersView();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll( async () => {
|
afterAll( async () => {
|
||||||
|
@ -64,117 +42,33 @@ const runOrderStatusFiltersTest = () => {
|
||||||
await moveAllItemsToTrash();
|
await moveAllItemsToTrash();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should filter by Pending payment', async () => {
|
it.each(orderStatus)('should filter by %s', async (statusText, statusClassName) => {
|
||||||
await merchant.openAllOrdersView();
|
// Identify which statuses should be shown or hidden
|
||||||
await clickFilter('.' + orderStatus.pending.name);
|
const shownStatus = { text: statusText };
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
const hiddenStatuses = orderStatus
|
||||||
|
.filter((pair) => !pair.includes(statusText))
|
||||||
|
.map(([statusText]) => {
|
||||||
|
return { text: statusText };
|
||||||
|
});
|
||||||
|
|
||||||
|
// Click the status filter and verify that only the matching order is shown
|
||||||
|
await clickFilter('.' + statusClassName);
|
||||||
|
await expect(page).toMatchElement(statusColumnTextSelector, shownStatus);
|
||||||
|
|
||||||
// Verify other statuses don't show
|
// Verify other statuses don't show
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
for (const hiddenStatus of hiddenStatuses) {
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
await expect(page).not.toMatchElement(statusColumnTextSelector, hiddenStatus);
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
}
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter by Processing', async () => {
|
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
await clickFilter('.' + orderStatus.processing.name);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
|
|
||||||
// Verify other statuses don't show
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter by On hold', async () => {
|
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
await clickFilter('.' + orderStatus.onHold.name);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
|
|
||||||
// Verify other statuses don't show
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter by Completed', async () => {
|
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
await clickFilter('.' + orderStatus.completed.name);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
|
|
||||||
// Verify other statuses don't show
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter by Cancelled', async () => {
|
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
await clickFilter('.' + orderStatus.cancelled.name);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
|
|
||||||
// Verify other statuses don't show
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter by Refunded', async () => {
|
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
await clickFilter('.' + orderStatus.refunded.name);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
|
|
||||||
// Verify other statuses don't show
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should filter by Failed', async () => {
|
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
await clickFilter('.' + orderStatus.failed.name);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
|
|
||||||
// Verify other statuses don't show
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).not.toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should filter by All', async () => {
|
it('should filter by All', async () => {
|
||||||
await merchant.openAllOrdersView();
|
|
||||||
// Make sure all the order statuses that were created show in this list
|
// Make sure all the order statuses that were created show in this list
|
||||||
await clickFilter('.all');
|
await clickFilter('.all');
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.pending.description);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.processing.description);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.completed.description);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.cancelled.description);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.refunded.description);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.onHold.description);
|
|
||||||
await expect(page).toMatchElement(statusColumnTextSelector, orderStatus.failed.description);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
for (const [statusText] of orderStatus) {
|
||||||
|
await expect(page).toMatchElement(statusColumnTextSelector, { text: statusText });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue