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