22 * Tests for the checkPage module functionality
33 */
44
5+ /* eslint-disable no-undef */
6+
57// Mock the helper functions
6- jest . mock ( '../../../src/editorApp/helpers' , ( ) => ( {
8+ jest . mock ( '../../../src/editorApp/helpers' , ( ) => ( {
79 info : jest . fn ( ) ,
810 debug : jest . fn ( ) ,
9- } ) ) ;
11+ } ) ) ;
1012
11- jest . mock ( '../../../src/common/helpers' , ( ) => ( {
13+ jest . mock ( '../../../src/common/helpers' , ( ) => ( {
1214 showNotice : jest . fn ( ) ,
13- } ) ) ;
15+ } ) ) ;
1416
15- describe ( 'checkPage functionality' , ( ) => {
17+ describe ( 'checkPage functionality' , ( ) => {
1618 let originalEdacEditorApp ;
1719 let originalFetch ;
18- let mockInjectIframe ;
1920
20- beforeEach ( ( ) => {
21+ beforeEach ( ( ) => {
2122 // Store original values
2223 originalEdacEditorApp = global . edac_editor_app ;
2324 originalFetch = global . fetch ;
@@ -26,184 +27,178 @@ describe('checkPage functionality', () => {
2627 global . edac_editor_app = {
2728 postID : '123' ,
2829 postStatus : 'draft' ,
29- scannablePostStatuses : [ 'publish' , 'future' , 'draft' , 'pending' , 'private' ] ,
30+ scannablePostStatuses : [ 'publish' , 'future' , 'draft' , 'pending' , 'private' ] ,
3031 scanUrl : 'http://example.com/preview?post=123' ,
3132 active : true ,
3233 } ;
3334
3435 // Mock fetch
35- global . fetch = jest . fn ( ( ) =>
36- Promise . resolve ( {
37- json : ( ) => Promise . resolve ( { success : true } ) ,
38- } )
36+ global . fetch = jest . fn ( ( ) =>
37+ Promise . resolve ( {
38+ json : ( ) => Promise . resolve ( { success : true } ) ,
39+ } )
3940 ) ;
4041
41- // Mock the injectIframe function since it manipulates DOM
42- mockInjectIframe = jest . fn ( ) ;
43-
4442 // Clear document body
4543 document . body . innerHTML = '' ;
46- } ) ;
44+ } ) ;
4745
48- afterEach ( ( ) => {
46+ afterEach ( ( ) => {
4947 // Restore original values
5048 global . edac_editor_app = originalEdacEditorApp ;
5149 global . fetch = originalFetch ;
5250 jest . clearAllMocks ( ) ;
53- } ) ;
51+ } ) ;
5452
55- describe ( 'post status validation' , ( ) => {
56- test ( 'should not scan posts with auto-draft status' , async ( ) => {
53+ describe ( 'post status validation' , ( ) => {
54+ test ( 'should not scan posts with auto-draft status' , async ( ) => {
5755 // Set post status to auto-draft (unsaved new post)
5856 global . edac_editor_app . postStatus = 'auto-draft' ;
5957
60- // Mock the module to test the isPostScannable function
61- const checkPageModule = require ( '../../../src/editorApp/checkPage' ) ;
62-
6358 // Get the module content as text to extract the isPostScannable function
64- const fs = require ( 'fs' ) ;
65- const path = require ( 'path' ) ;
59+ const fs = require ( 'fs' ) ;
60+ const path = require ( 'path' ) ;
6661 const checkPageContent = fs . readFileSync (
67- path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
62+ path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
6863 'utf8'
6964 ) ;
7065
7166 // Extract and evaluate the isPostScannable function
7267 const isPostScannableMatch = checkPageContent . match (
7368 / c o n s t i s P o s t S c a n n a b l e = \( \) = > \{ [ \s \S ] * ?\} ; /
7469 ) ;
75-
76- expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
77-
70+
71+ expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
72+
7873 // Create a function to test the logic
79- const testFunction = new Function ( `
74+ const testFunction = new Function ( `
8075 const edac_editor_app = arguments[0];
81- ${ isPostScannableMatch [ 0 ] }
76+ ${ isPostScannableMatch [ 0 ] }
8277 return isPostScannable();
83- ` ) ;
78+ ` ) ;
8479
85- const result = testFunction ( global . edac_editor_app ) ;
86- expect ( result ) . toBe ( false ) ;
87- } ) ;
80+ const result = testFunction ( global . edac_editor_app ) ;
81+ expect ( result ) . toBe ( false ) ;
82+ } ) ;
8883
89- test ( 'should scan posts with draft status' , async ( ) => {
84+ test ( 'should scan posts with draft status' , async ( ) => {
9085 // Set post status to draft (saved post)
9186 global . edac_editor_app . postStatus = 'draft' ;
9287
9388 // Get the module content as text to extract the isPostScannable function
94- const fs = require ( 'fs' ) ;
95- const path = require ( 'path' ) ;
89+ const fs = require ( 'fs' ) ;
90+ const path = require ( 'path' ) ;
9691 const checkPageContent = fs . readFileSync (
97- path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
92+ path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
9893 'utf8'
9994 ) ;
10095
10196 // Extract and evaluate the isPostScannable function
10297 const isPostScannableMatch = checkPageContent . match (
10398 / c o n s t i s P o s t S c a n n a b l e = \( \) = > \{ [ \s \S ] * ?\} ; /
10499 ) ;
105-
106- expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
107-
100+
101+ expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
102+
108103 // Create a function to test the logic
109- const testFunction = new Function ( `
104+ const testFunction = new Function ( `
110105 const edac_editor_app = arguments[0];
111- ${ isPostScannableMatch [ 0 ] }
106+ ${ isPostScannableMatch [ 0 ] }
112107 return isPostScannable();
113- ` ) ;
108+ ` ) ;
114109
115- const result = testFunction ( global . edac_editor_app ) ;
116- expect ( result ) . toBe ( true ) ;
117- } ) ;
110+ const result = testFunction ( global . edac_editor_app ) ;
111+ expect ( result ) . toBe ( true ) ;
112+ } ) ;
118113
119- test ( 'should scan posts with publish status' , async ( ) => {
114+ test ( 'should scan posts with publish status' , async ( ) => {
120115 // Set post status to publish
121116 global . edac_editor_app . postStatus = 'publish' ;
122117
123118 // Get the module content as text to extract the isPostScannable function
124- const fs = require ( 'fs' ) ;
125- const path = require ( 'path' ) ;
119+ const fs = require ( 'fs' ) ;
120+ const path = require ( 'path' ) ;
126121 const checkPageContent = fs . readFileSync (
127- path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
122+ path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
128123 'utf8'
129124 ) ;
130125
131126 // Extract and evaluate the isPostScannable function
132127 const isPostScannableMatch = checkPageContent . match (
133128 / c o n s t i s P o s t S c a n n a b l e = \( \) = > \{ [ \s \S ] * ?\} ; /
134129 ) ;
135-
136- expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
137-
130+
131+ expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
132+
138133 // Create a function to test the logic
139- const testFunction = new Function ( `
134+ const testFunction = new Function ( `
140135 const edac_editor_app = arguments[0];
141- ${ isPostScannableMatch [ 0 ] }
136+ ${ isPostScannableMatch [ 0 ] }
142137 return isPostScannable();
143- ` ) ;
138+ ` ) ;
144139
145- const result = testFunction ( global . edac_editor_app ) ;
146- expect ( result ) . toBe ( true ) ;
147- } ) ;
140+ const result = testFunction ( global . edac_editor_app ) ;
141+ expect ( result ) . toBe ( true ) ;
142+ } ) ;
148143
149- test ( 'should not scan posts with empty or missing status' , async ( ) => {
144+ test ( 'should not scan posts with empty or missing status' , async ( ) => {
150145 // Set post status to empty
151146 global . edac_editor_app . postStatus = '' ;
152147
153148 // Get the module content as text to extract the isPostScannable function
154- const fs = require ( 'fs' ) ;
155- const path = require ( 'path' ) ;
149+ const fs = require ( 'fs' ) ;
150+ const path = require ( 'path' ) ;
156151 const checkPageContent = fs . readFileSync (
157- path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
152+ path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
158153 'utf8'
159154 ) ;
160155
161156 // Extract and evaluate the isPostScannable function
162157 const isPostScannableMatch = checkPageContent . match (
163158 / c o n s t i s P o s t S c a n n a b l e = \( \) = > \{ [ \s \S ] * ?\} ; /
164159 ) ;
165-
166- expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
167-
160+
161+ expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
162+
168163 // Create a function to test the logic
169- const testFunction = new Function ( `
164+ const testFunction = new Function ( `
170165 const edac_editor_app = arguments[0];
171- ${ isPostScannableMatch [ 0 ] }
166+ ${ isPostScannableMatch [ 0 ] }
172167 return isPostScannable();
173- ` ) ;
168+ ` ) ;
174169
175- const result = testFunction ( global . edac_editor_app ) ;
176- expect ( result ) . toBe ( false ) ;
177- } ) ;
170+ const result = testFunction ( global . edac_editor_app ) ;
171+ expect ( result ) . toBe ( false ) ;
172+ } ) ;
178173
179- test ( 'should not scan when scannablePostStatuses is missing' , async ( ) => {
174+ test ( 'should not scan when scannablePostStatuses is missing' , async ( ) => {
180175 // Remove scannablePostStatuses
181176 delete global . edac_editor_app . scannablePostStatuses ;
182177
183178 // Get the module content as text to extract the isPostScannable function
184- const fs = require ( 'fs' ) ;
185- const path = require ( 'path' ) ;
179+ const fs = require ( 'fs' ) ;
180+ const path = require ( 'path' ) ;
186181 const checkPageContent = fs . readFileSync (
187- path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
182+ path . join ( __dirname , '../../../src/editorApp/checkPage.js' ) ,
188183 'utf8'
189184 ) ;
190185
191186 // Extract and evaluate the isPostScannable function
192187 const isPostScannableMatch = checkPageContent . match (
193188 / c o n s t i s P o s t S c a n n a b l e = \( \) = > \{ [ \s \S ] * ?\} ; /
194189 ) ;
195-
196- expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
197-
190+
191+ expect ( isPostScannableMatch ) . toBeTruthy ( ) ;
192+
198193 // Create a function to test the logic
199- const testFunction = new Function ( `
194+ const testFunction = new Function ( `
200195 const edac_editor_app = arguments[0];
201- ${ isPostScannableMatch [ 0 ] }
196+ ${ isPostScannableMatch [ 0 ] }
202197 return isPostScannable();
203- ` ) ;
198+ ` ) ;
204199
205- const result = testFunction ( global . edac_editor_app ) ;
206- expect ( result ) . toBe ( false ) ;
207- } ) ;
208- } ) ;
209- } ) ;
200+ const result = testFunction ( global . edac_editor_app ) ;
201+ expect ( result ) . toBe ( false ) ;
202+ } ) ;
203+ } ) ;
204+ } ) ;
0 commit comments