@@ -5,14 +5,17 @@ import { expect } from '@wordpress/e2e-test-utils-playwright';
5
5
*/
6
6
const { RequestUtils } = require ( '@wordpress/e2e-test-utils-playwright' ) ;
7
7
8
+ export const CUSTOM_FEED_URL =
9
+ 'https://s3.amazonaws.com/verti-utils/sample-feed.xml' ;
10
+
8
11
/**
9
12
* Close the tour modal if it is visible.
10
13
*
11
14
* @param {import('playwright').Page } page The page object.
12
15
*/
13
16
export async function tryCloseTourModal ( page ) {
14
17
if ( await page . getByRole ( 'button' , { name : 'Skip' } ) . isVisible ( ) ) {
15
- await page . getByRole ( 'button' , { name : 'Skip' } ) . click ( ) ;
18
+ await page . getByRole ( 'button' , { name : 'Skip' } ) . click ( { force : true } ) ;
16
19
await page . waitForTimeout ( 500 ) ;
17
20
}
18
21
}
@@ -25,6 +28,9 @@ export async function tryCloseTourModal(page) {
25
28
* @return {Promise<void> } The promise that resolves when the feeds are added.
26
29
*/
27
30
export async function addFeeds ( page , feedURLs ) {
31
+ await page . waitForSelector ( 'input[name="feedzy_meta_data[source]"]' , {
32
+ state : 'attached' ,
33
+ } ) ;
28
34
await page . evaluate ( ( urls ) => {
29
35
document . querySelector ( 'input[name="feedzy_meta_data[source]"]' ) . value =
30
36
urls ?. join ( ', ' ) ;
@@ -67,11 +73,21 @@ export async function addContentMapping(page, mapping) {
67
73
* @return {Promise<void> }
68
74
*/
69
75
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 ) ;
76
+ try {
77
+ await page . waitForSelector (
78
+ 'input[name="feedzy_meta_data[import_feed_limit]"]' ,
79
+ {
80
+ state : 'attached' ,
81
+ }
82
+ ) ;
83
+ await page . evaluate ( ( importLimit ) => {
84
+ document . querySelector (
85
+ 'input[name="feedzy_meta_data[import_feed_limit]"]'
86
+ ) . value = importLimit ;
87
+ } , limit ) ;
88
+ } catch ( error ) {
89
+ // Element not found or not attached - ignore silently
90
+ }
75
91
}
76
92
77
93
/**
@@ -192,3 +208,29 @@ export async function getPostsByFeedzy(requestUtils) {
192
208
} ,
193
209
} ) ;
194
210
}
211
+
212
+ /**
213
+ * Create and run a sample import with the given feed URL.
214
+ *
215
+ * @param {import('playwright').Page } page
216
+ * @param {string } feedUrl
217
+ *
218
+ * @return {Promise<void> } The promise that resolves when the import is created and run.
219
+ */
220
+ export async function createAndRunSampleImport (
221
+ page ,
222
+ feedUrl = CUSTOM_FEED_URL
223
+ ) {
224
+ const importName = `Create and run sample import: ${ new Date ( ) . toISOString ( ) } ` ;
225
+
226
+ await page . goto ( '/wp-admin/post-new.php?post_type=feedzy_imports' ) ;
227
+ await tryCloseTourModal ( page ) ;
228
+
229
+ await page . getByPlaceholder ( 'Add a name for your import' ) . fill ( importName ) ;
230
+ await addFeeds ( page , [ feedUrl ] ) ;
231
+ await page
232
+ . getByRole ( 'button' , { name : 'Save & Activate importing' } )
233
+ . click ( { force : true } ) ;
234
+
235
+ await runFeedImport ( page ) ;
236
+ }
0 commit comments