Skip to content

Commit ef79221

Browse files
chore: fix E2E
1 parent b190eee commit ef79221

File tree

3 files changed

+154
-134
lines changed

3 files changed

+154
-134
lines changed

tests/e2e/specs/feed.spec.js

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,50 @@
33
*/
44
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
55
import {
6-
tryCloseTourModal,
7-
deleteAllFeedImports,
8-
addFeeds,
9-
runFeedImport
6+
tryCloseTourModal,
7+
deleteAllFeedImports,
8+
addFeeds,
9+
runFeedImport,
1010
} from '../utils';
1111

12-
test.describe( 'Feed Settings', () => {
12+
test.describe('Feed Settings', () => {
13+
const FEED_URL =
14+
'https://s3.amazonaws.com/verti-utils/sample-feed-import.xml';
1315

14-
const FEED_URL = 'https://s3.amazonaws.com/verti-utils/sample-feed-import.xml';
16+
test.beforeEach(async ({ requestUtils }) => {
17+
await deleteAllFeedImports(requestUtils);
18+
await requestUtils.deleteAllPosts();
19+
await requestUtils.deleteAllMedia();
20+
});
1521

16-
test.beforeEach( async ( { requestUtils } ) => {
17-
await deleteAllFeedImports( requestUtils );
18-
await requestUtils.deleteAllPosts();
19-
await requestUtils.deleteAllMedia();
20-
} );
22+
test('adding an URL feed', async ({ editor, page }) => {
23+
const importName = 'Test Title: adding an URL feed';
2124

22-
test( 'adding an URL feed', async({ editor, page }) => {
25+
await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports');
26+
await tryCloseTourModal(page);
2327

24-
const importName = 'Test Title: adding an URL feed';
28+
await page
29+
.getByPlaceholder('Add a name for your import')
30+
.fill(importName);
2531

26-
await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports');
27-
await tryCloseTourModal( page );
32+
// Add feed URL via tag input.
33+
await addFeeds(page, [FEED_URL]);
2834

29-
await page.getByPlaceholder('Add a name for your import').fill(importName);
35+
await page
36+
.getByRole('button', { name: 'Save', exact: true })
37+
.click({ force: true, clickCount: 1 });
3038

31-
// Add feed URL via tag input.
32-
await addFeeds( page, [FEED_URL] );
39+
await expect(
40+
page.getByRole('cell', { name: importName })
41+
).toBeVisible();
3342

34-
await page.getByRole('button', { name: 'Save', exact: true }).click({ force: true, clickCount: 1 });
43+
await page.getByRole('cell', { name: importName }).hover(); // Display the actions.
44+
await page.getByLabel(`Edit “${importName}`).click();
3545

36-
await expect( page.getByRole('cell', { name: importName }) ).toBeVisible();
37-
38-
await page.getByRole('cell', { name: importName }).hover(); // Display the actions.
39-
await page.getByLabel(`Edit “${importName}`).click();
40-
41-
expect( await page.getByPlaceholder('Add a name for your import').inputValue() ).toBe(importName);
42-
await expect( page.getByText( FEED_URL ) ).toBeVisible();
43-
});
46+
expect(
47+
await page
48+
.getByPlaceholder('Add a name for your import')
49+
.inputValue()
50+
).toBe(importName);
51+
});
4452
});

tests/e2e/specs/import.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ test.describe('Feed Import', () => {
179179
.getByPlaceholder('Add a name for your import')
180180
.fill(importName);
181181
await addFeeds(page, [FEED_URL]);
182-
await setItemLimit(page, 1);
183182
await page
184183
.getByRole('button', { name: 'Save & Activate importing' })
185184
.click({ force: true });
@@ -204,7 +203,6 @@ test.describe('Feed Import', () => {
204203
.fill(importName);
205204
await addFeeds(page, [FEED_URL]);
206205
await addFeaturedImage(page, '[#item_image]');
207-
await setItemLimit(page, 1);
208206
await page
209207
.getByRole('button', { name: 'Save & Activate importing' })
210208
.click({ force: true });
@@ -257,7 +255,6 @@ test.describe('Feed Import', () => {
257255
)
258256
);
259257
await addFeaturedImage(page, getEmptyChainedActions('item_image'));
260-
await setItemLimit(page, 1);
261258

262259
await page
263260
.getByRole('button', { name: 'Save & Activate importing' })

tests/e2e/utils.js

Lines changed: 119 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import {expect} from "@wordpress/e2e-test-utils-playwright";
1+
import { expect } from '@wordpress/e2e-test-utils-playwright';
22

33
/**
44
* WordPress dependencies
55
*/
6-
const {RequestUtils } = require( '@wordpress/e2e-test-utils-playwright' )
6+
const { RequestUtils } = require('@wordpress/e2e-test-utils-playwright');
77

88
/**
99
* Close the tour modal if it is visible.
1010
*
1111
* @param {import('playwright').Page} page The page object.
1212
*/
13-
export async function tryCloseTourModal( page ) {
13+
export async function tryCloseTourModal(page) {
1414
if (await page.getByRole('button', { name: 'Skip' }).isVisible()) {
1515
await page.getByRole('button', { name: 'Skip' }).click();
1616
await page.waitForTimeout(500);
@@ -20,160 +20,175 @@ export async function tryCloseTourModal( page ) {
2020
/**
2121
* Add feeds to the import on Feed Edit page.
2222
*
23-
* @param {import('playwright').Page} page The page object.
24-
* @param {string[]} feedURLs The feed URLs to add in the input.
25-
* @returns {Promise<void>} The promise that resolves when the feeds are added.
23+
* @param {import('playwright').Page} page The page object.
24+
* @param {string[]} feedURLs The feed URLs to add in the input.
25+
* @return {Promise<void>} The promise that resolves when the feeds are added.
2626
*/
27-
export async function addFeeds( page, feedURLs ) {
28-
await page.evaluate( ( urls ) => {
29-
document.querySelector( 'input[name="feedzy_meta_data[source]"]' ).value = urls?.join(', ');
30-
}, feedURLs );
27+
export async function addFeeds(page, feedURLs) {
28+
await page.evaluate((urls) => {
29+
document.querySelector('input[name="feedzy_meta_data[source]"]').value =
30+
urls?.join(', ');
31+
}, feedURLs);
3132
}
3233

3334
/**
3435
* Add tags to the Featured Image on Feed Edit page.
3536
*
36-
* @param {import('playwright').Page} page The page object.
37-
* @param {string} feedTag The tag that import the image from the feed.
38-
* @returns {Promise<void>} The promise that resolves when the tags are added.
37+
* @param {import('playwright').Page} page The page object.
38+
* @param {string} feedTag The tag that import the image from the feed.
39+
* @return {Promise<void>} The promise that resolves when the tags are added.
3940
*/
40-
export async function addFeaturedImage( page, feedTag ) {
41-
await page.evaluate( ( feedTag ) => {
42-
document.querySelector( 'input[name="feedzy_meta_data[import_post_featured_img]"]' ).value = feedTag;
43-
}, feedTag );
41+
export async function addFeaturedImage(page, feedTag) {
42+
await page.evaluate((feedTag) => {
43+
document.querySelector(
44+
'input[name="feedzy_meta_data[import_post_featured_img]"]'
45+
).value = feedTag;
46+
}, feedTag);
4447
}
4548

4649
/**
4750
* Add content mapping to the import on Feed Edit page.
48-
* @param page The page object.
49-
* @param mapping The content mapping to add.
50-
* @returns {Promise<void>}
51+
* @param page The page object.
52+
* @param mapping The content mapping to add.
53+
* @return {Promise<void>}
5154
*/
52-
export async function addContentMapping( page, mapping ) {
53-
await page.evaluate( ( mapping ) => {
54-
document.querySelector( 'textarea[name="feedzy_meta_data[import_post_content]"]' ).value = mapping;
55-
}, mapping );
55+
export async function addContentMapping(page, mapping) {
56+
await page.evaluate((mapping) => {
57+
document.querySelector(
58+
'textarea[name="feedzy_meta_data[import_post_content]"]'
59+
).value = mapping;
60+
}, mapping);
5661
}
5762

5863
/**
5964
* Set the item limit on the Feed Edit page.
60-
* @param {import('playwright').Page} page The page object.
61-
* @param {number} limit The limit to set.
62-
* @returns {Promise<void>}
65+
* @param {import('playwright').Page} page The page object.
66+
* @param {number} limit The limit to set.
67+
* @return {Promise<void>}
6368
*/
64-
export async function setItemLimit( page, limit ) {
65-
await page.evaluate( ( limit ) => {
66-
document.querySelector( 'input[name="feedzy_meta_data[import_feed_limit]"]' ).value = limit;
67-
} , limit );
69+
export async function setItemLimit(page, limit) {
70+
await page.evaluate((limit) => {
71+
document.querySelector(
72+
'input[name="feedzy_meta_data[import_feed_limit]"]'
73+
).value = limit;
74+
}, limit);
6875
}
6976

7077
/**
7178
* Create an empty chained actions.
7279
* @param {string} defaultFeedTag The default feed tag.
73-
* @returns {string} The empty chained actions.
80+
* @return {string} The empty chained actions.
7481
*/
75-
export function getEmptyChainedActions( defaultFeedTag ) {
76-
return wrapSerializedChainedActions(serializeChainedActions([ { id: '', tag: defaultFeedTag, data: {} } ] ) );
82+
export function getEmptyChainedActions(defaultFeedTag) {
83+
return wrapSerializedChainedActions(
84+
serializeChainedActions([{ id: '', tag: defaultFeedTag, data: {} }])
85+
);
7786
}
7887

7988
/**
8089
* Serialize the chained actions.
8190
* @param {any[]} actions The actions to serialize.
82-
* @returns {string} The serialized actions.
91+
* @return {string} The serialized actions.
8392
*/
84-
export function serializeChainedActions( actions ) {
85-
return encodeURIComponent( JSON.stringify( actions ) );
93+
export function serializeChainedActions(actions) {
94+
return encodeURIComponent(JSON.stringify(actions));
8695
}
8796

8897
/**
8998
* Wrap the serialized chained actions to match the format used in the input.
9099
* @param {string} actions The serialized actions.
91-
* @returns {string} The wrapped actions.
100+
* @return {string} The wrapped actions.
92101
*/
93-
export function wrapSerializedChainedActions( actions ) {
94-
return `[[{"value":"${actions}"}]]`;
102+
export function wrapSerializedChainedActions(actions) {
103+
return `[[{"value":"${actions}"}]]`;
95104
}
96105

97106
/**
98107
* Run the feed import.
99108
*
100109
* @param {import('playwright').Page} page The page object.
101-
* @returns {Promise<void>} The promise that resolves when the feed is imported.
110+
* @return {Promise<void>} The promise that resolves when the feed is imported.
102111
*/
103-
export async function runFeedImport( page ) {
104-
await page.goto('/wp-admin/edit.php?post_type=feedzy_imports');
105-
await page.waitForSelector('.feedzy-import-status-row');
106-
107-
await page.getByRole('button', { name: 'Run Now' }).click();
108-
109-
const runNowResponse = await page.waitForResponse(
110-
response => (
111-
response.url().includes('/wp-admin/admin-ajax.php')&&
112-
response.request().method() === 'POST' &&
113-
response.request().postData().includes('action=feedzy&_action=run_now')
114-
)
115-
);
116-
117-
expect( runNowResponse ).not.toBeNull();
118-
const responseBody = await runNowResponse.json();
119-
expect( responseBody.success ).toBe(true);
120-
expect( responseBody.data.import_success ).toBe(true);
121-
122-
// Reload the page to check the status.
123-
await page.reload();
124-
await page.waitForSelector('.feedzy-items');
125-
126-
// We should have some imported posts in the stats.
127-
const feedzyCumulative = parseInt(await page.$eval('.feedzy-items a', (element) => element.innerText));
128-
expect(feedzyCumulative).toBeGreaterThan(0);
129-
130-
// Open the dialog with the imported feeds.
131-
await page.locator('.feedzy-items a').click();
132-
await expect( page.locator('#ui-id-2').locator('li a').count() ).resolves.toBeGreaterThan(0);
133-
await page.getByRole('button', { name: 'Ok' }).click();
112+
export async function runFeedImport(page) {
113+
await page.goto('/wp-admin/edit.php?post_type=feedzy_imports');
114+
await page.waitForSelector('.feedzy-import-status-row');
115+
116+
await page.getByRole('button', { name: 'Run Now' }).click();
117+
118+
const runNowResponse = await page.waitForResponse(
119+
(response) =>
120+
response.url().includes('/wp-admin/admin-ajax.php') &&
121+
response.request().method() === 'POST' &&
122+
response
123+
.request()
124+
.postData()
125+
.includes('action=feedzy&_action=run_now')
126+
);
127+
128+
expect(runNowResponse).not.toBeNull();
129+
const responseBody = await runNowResponse.json();
130+
expect(responseBody.success).toBe(true);
131+
expect(responseBody.data.import_success).toBe(true);
132+
133+
// Reload the page to check the status.
134+
await page.reload();
135+
await page.waitForSelector('.feedzy-items');
136+
137+
// We should have some imported posts in the stats.
138+
const feedzyCumulative = parseInt(
139+
await page.$eval('.feedzy-items a', (element) => element.innerText)
140+
);
141+
expect(feedzyCumulative).toBeGreaterThan(0);
142+
143+
// Open the dialog with the imported feeds.
144+
await page.locator('.feedzy-items a').click();
145+
await expect(
146+
page.locator('#ui-id-1').locator('li a').count()
147+
).resolves.toBeGreaterThan(0);
148+
await page.getByRole('button', { name: 'Ok' }).click();
134149
}
135150

136151
/**
137152
* Delete all feed imports.
138153
*
139154
* @param {RequestUtils} requestUtils The request utils object.
140155
*/
141-
export async function deleteAllFeedImports( requestUtils ) {
142-
const feeds = await requestUtils.rest( {
143-
path: '/wp/v2/feedzy_imports',
144-
params: {
145-
per_page: 100,
146-
status: 'publish,future,draft,pending,private,trash',
147-
},
148-
} );
149-
150-
await Promise.all(
151-
feeds.map( ( post ) =>
152-
requestUtils.rest( {
153-
method: 'DELETE',
154-
path: `/wp/v2/feedzy_imports/${ post.id }`,
155-
params: {
156-
force: true,
157-
},
158-
} )
159-
)
160-
);
156+
export async function deleteAllFeedImports(requestUtils) {
157+
const feeds = await requestUtils.rest({
158+
path: '/wp/v2/feedzy_imports',
159+
params: {
160+
per_page: 100,
161+
status: 'publish,future,draft,pending,private,trash',
162+
},
163+
});
164+
165+
await Promise.all(
166+
feeds.map((post) =>
167+
requestUtils.rest({
168+
method: 'DELETE',
169+
path: `/wp/v2/feedzy_imports/${post.id}`,
170+
params: {
171+
force: true,
172+
},
173+
})
174+
)
175+
);
161176
}
162177

163178
/**
164179
* Get post created with Feedzy.
165180
* @param {RequestUtils} requestUtils The request utils object.
166-
* @returns {Promise<*>}
181+
* @return {Promise<*>}
167182
*/
168-
export async function getPostsByFeedzy( requestUtils ) {
169-
return await requestUtils.rest({
170-
path: '/wp/v2/posts',
171-
params: {
172-
per_page: 100,
173-
status: 'publish',
174-
meta_key: 'feedzy',
175-
meta_value: 1,
176-
meta_compare: '=',
177-
},
178-
});
183+
export async function getPostsByFeedzy(requestUtils) {
184+
return await requestUtils.rest({
185+
path: '/wp/v2/posts',
186+
params: {
187+
per_page: 100,
188+
status: 'publish',
189+
meta_key: 'feedzy',
190+
meta_value: 1,
191+
meta_compare: '=',
192+
},
193+
});
179194
}

0 commit comments

Comments
 (0)