Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit bb6a78c

Browse files
authored
Refactor E2E setup routine (#2544)
* skip test and delete unneeded ones * update comment
1 parent 6b603a4 commit bb6a78c

File tree

1 file changed

+30
-82
lines changed

1 file changed

+30
-82
lines changed

tests/e2e-tests/config/jest.setup.js

Lines changed: 30 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
import { get } from 'lodash';
55
import {
6-
clearLocalStorage,
76
enablePageDialogAccept,
87
isOfflineMode,
98
setBrowserViewport,
@@ -46,97 +45,48 @@ const OBSERVED_CONSOLE_MESSAGE_TYPES = {
4645
};
4746

4847
async function setupBrowser() {
49-
await clearLocalStorage();
5048
await setBrowserViewport( 'large' );
5149
}
5250

53-
/**
54-
* Navigates to the post listing screen and bulk-trashes any posts which exist.
55-
*
56-
* @return {Promise} Promise resolving once posts have been trashed.
57-
*/
58-
async function trashExistingPosts() {
59-
await switchUserToAdmin();
60-
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
61-
await visitAdminPage( 'edit.php' );
62-
63-
// If this selector doesn't exist there are no posts for us to delete.
64-
const bulkSelector = await page.$( '#bulk-action-selector-top' );
65-
if ( ! bulkSelector ) {
66-
return;
67-
}
68-
69-
// Select all posts.
70-
await page.waitForSelector( '#cb-select-all-1' );
71-
await page.click( '#cb-select-all-1' );
72-
// Select the "bulk actions" > "trash" option.
73-
await page.select( '#bulk-action-selector-top', 'trash' );
74-
// Submit the form to send all draft/scheduled/published posts to the trash.
75-
await page.click( '#doaction' );
76-
await page.waitForXPath(
77-
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
78-
);
79-
await switchUserToTest();
80-
}
81-
82-
/**
83-
* Navigates to the product listing screen and bulk-trashes any product which exist.
84-
*
85-
* @return {Promise} Promise resolving once products have been trashed.
86-
*/
87-
async function trashExistingProducts() {
88-
await switchUserToAdmin();
89-
// Visit `/wp-admin/edit.php?post_type=product` so we can see a list of products and delete them.
90-
await visitAdminPage( 'edit.php', 'post_type=product' );
91-
92-
// If this selector doesn't exist there are no products for us to delete.
93-
const bulkSelector = await page.$( '#bulk-action-selector-top' );
94-
if ( ! bulkSelector ) {
95-
return;
96-
}
97-
98-
// Select all products.
99-
await page.waitForSelector( '#cb-select-all-1' );
100-
await page.click( '#cb-select-all-1' );
101-
// Select the "bulk actions" > "trash" option.
102-
await page.select( '#bulk-action-selector-top', 'trash' );
103-
// Submit the form to send all draft/scheduled/published posts to the trash.
104-
await page.click( '#doaction' );
105-
await page.waitForXPath(
106-
'//*[contains(@class, "updated notice")]/p[contains(text(), "moved to the Trash.")]'
107-
);
108-
await switchUserToTest();
109-
}
110-
11151
/**
11252
* Navigates to woocommerce import page and imports sample products.
11353
*
11454
* @return {Promise} Promise resolving once products have been imported.
11555
*/
11656
async function importSampleProducts() {
11757
await switchUserToAdmin();
118-
// Visit Import Products page.
119-
await visitAdminPage(
120-
'edit.php',
121-
'post_type=product&page=product_importer'
122-
);
123-
await page.click( 'a.woocommerce-importer-toggle-advanced-options' );
124-
await page.focus( '#woocommerce-importer-file-url' );
125-
// local path for sample data that is included with woo.
126-
await page.keyboard.type(
127-
'wp-content/plugins/woocommerce/sample-data/sample_products.csv'
128-
);
129-
await page.click( '.wc-actions .button-next' );
130-
await page.waitForSelector( '.wc-importer-mapping-table' );
131-
await page.select(
132-
'.wc-importer-mapping-table tr:nth-child(29) select',
133-
''
58+
// Visit `/wp-admin/edit.php?post_type=product` so we can see a list of products and decide if we should import them or not.
59+
await visitAdminPage( 'edit.php', 'post_type=product' );
60+
const emptyState = await page.evaluate( () =>
61+
window.find( 'Ready to start selling something awesome' )
13462
);
135-
await page.click( '.wc-actions .button-next' );
136-
await page.waitForXPath(
137-
"//*[@class='woocommerce-importer-done' and contains(., 'Import complete! ')]"
63+
const noProduct = await page.evaluate( () =>
64+
window.find( 'No products found' )
13865
);
139-
await switchUserToTest();
66+
if ( emptyState || noProduct ) {
67+
// Visit Import Products page.
68+
await visitAdminPage(
69+
'edit.php',
70+
'post_type=product&page=product_importer'
71+
);
72+
await page.click( 'a.woocommerce-importer-toggle-advanced-options' );
73+
await page.focus( '#woocommerce-importer-file-url' );
74+
// local path for sample data that is included with woo.
75+
await page.keyboard.type(
76+
'wp-content/plugins/woocommerce/sample-data/sample_products.csv'
77+
);
78+
await page.click( '.wc-actions .button-next' );
79+
await page.waitForSelector( '.wc-importer-mapping-table' );
80+
await page.select(
81+
'.wc-importer-mapping-table tr:nth-child(29) select',
82+
''
83+
);
84+
await page.click( '.wc-actions .button-next' );
85+
await page.waitForXPath(
86+
"//*[@class='woocommerce-importer-done' and contains(., 'Import complete! ')]"
87+
);
88+
await switchUserToTest();
89+
}
14090
}
14191

14292
/**
@@ -256,8 +206,6 @@ beforeAll( async () => {
256206
capturePageEventsForTearDown();
257207
enablePageDialogAccept();
258208
observeConsoleLogging();
259-
await trashExistingPosts();
260-
await trashExistingProducts();
261209
await setupBrowser();
262210
await importSampleProducts();
263211
} );

0 commit comments

Comments
 (0)