@@ -6,6 +6,8 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright';
66import {
77 addNewField ,
88 addNewOptionInModal ,
9+ attachGroupToProduct ,
10+ clearCart ,
911 enableConditionsInModal ,
1012 fillFieldNameAndId ,
1113 fillOptionNameAndValue ,
@@ -15,6 +17,8 @@ import {
1517 switchToConditionsModalTab ,
1618} from '../utils' ;
1719
20+ const RUN_SUFFIX = Date . now ( ) ;
21+
1822test . describe ( 'Conditions' , ( ) => {
1923 /***
2024 * Create two select fields (with two options each) and one text field. Display the text field if the second option of the second select is selected.
@@ -105,21 +109,10 @@ test.describe( 'Conditions', () => {
105109 await page . waitForLoadState ( 'networkidle' ) ;
106110
107111 await page . reload ( ) ;
108- await page . getByText ( 'Attach to Products' ) . click ( { force : true } ) ;
109- await page . waitForLoadState ( 'networkidle' ) ;
110-
111- const productSelector = page . locator (
112- 'select[name="ppom-attach-to-products\\[\\]"]'
113- ) ;
114- await page . waitForLoadState ( 'networkidle' ) ;
115112
116- await productSelector . selectOption ( { index : 0 } ) ;
117- const selectedOption = await productSelector . inputValue ( ) ;
118- console . log ( 'Selected option value:' , selectedOption ) ;
119- await page . getByRole ( 'button' , { name : 'Save' , exact : true } ) . click ( ) ;
113+ const productId = await attachGroupToProduct ( page , 'Product 1' ) ;
120114
121- await page . waitForLoadState ( 'networkidle' ) ;
122- await page . goto ( `/?p=${ selectedOption } ` ) ;
115+ await page . goto ( `/?p=${ productId } ` ) ;
123116
124117 await expect ( page . getByLabel ( 'Output' ) ) . toBeHidden ( ) ;
125118
@@ -131,4 +124,119 @@ test.describe( 'Conditions', () => {
131124
132125 await expect ( page . getByLabel ( 'Output' ) ) . toBeVisible ( ) ;
133126 } ) ;
127+
128+ test ( '@critical hidden required fields stop blocking only after the condition hides them' , async ( {
129+ page,
130+ admin,
131+ } ) => {
132+ const selectFieldId = `condition_gate_${ RUN_SUFFIX } ` ;
133+ const outputFieldId = `conditional_output_${ RUN_SUFFIX } ` ;
134+ const outputError = 'Please enter the revealed value' ;
135+
136+ await clearCart ( page ) ;
137+ await admin . visitAdminPage ( 'admin.php?page=ppom' ) ;
138+
139+ await page . getByRole ( 'link' , { name : 'Add New Group' } ) . click ( ) ;
140+ await page
141+ . getByRole ( 'textbox' )
142+ . fill ( `Required Conditions ${ RUN_SUFFIX } ` ) ;
143+
144+ await addNewField ( page ) ;
145+ await pickFieldTypeInModal ( page , 'select' ) ;
146+ await fillFieldNameAndId ( page , 1 , 'Visibility Gate' , selectFieldId ) ;
147+
148+ await page
149+ . locator ( '#ppom_field_model_1' )
150+ . getByText ( 'Add Options' , { exact : true } )
151+ . click ( ) ;
152+ await fillOptionNameAndValue ( page , 1 , 0 , 'Hide output' , 'hide_output' ) ;
153+ await addNewOptionInModal ( page , 1 ) ;
154+ await fillOptionNameAndValue ( page , 1 , 1 , 'Show output' , 'show_output' ) ;
155+ await saveFieldInModal ( page , 1 ) ;
156+
157+ await addNewField ( page ) ;
158+ await pickFieldTypeInModal ( page , 'text' ) ;
159+ await fillFieldNameAndId ( page , 2 , 'Conditional Output' , outputFieldId ) ;
160+ await page
161+ . locator ( 'input[name="ppom\\[2\\]\\[error_message\\]"]' )
162+ . fill ( outputError ) ;
163+ await page
164+ . locator ( 'input[name="ppom\\[2\\]\\[required\\]"]' )
165+ . check ( { force : true } ) ;
166+ await saveFieldInModal ( page , 2 ) ;
167+
168+ await saveFields ( page ) ;
169+ await page . waitForLoadState ( 'networkidle' ) ;
170+ await page . reload ( ) ;
171+
172+ await page . locator ( '#ppom_sort_id_2 .ppom-edit-field' ) . click ( ) ;
173+ await switchToConditionsModalTab ( page , 2 ) ;
174+ await enableConditionsInModal ( page , 2 ) ;
175+
176+ await page
177+ . locator (
178+ 'select[name="ppom\\[2\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[elements\\]"]'
179+ )
180+ . selectOption ( selectFieldId ) ;
181+ await page
182+ . locator (
183+ 'select[name="ppom\\[2\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[operators\\]"]'
184+ )
185+ . selectOption ( { index : 0 } ) ;
186+ await page
187+ . locator (
188+ 'select[name="ppom\\[2\\]\\[conditions\\]\\[rules\\]\\[0\\]\\[element_values\\]"]'
189+ )
190+ . selectOption ( { index : 1 } ) ;
191+
192+ await saveFieldInModal ( page , 2 ) ;
193+ await saveFields ( page ) ;
194+ await page . waitForLoadState ( 'networkidle' ) ;
195+ await page . reload ( ) ;
196+
197+ const productId = await attachGroupToProduct ( page , 'Product 1' ) ;
198+
199+ await page . goto ( `/?p=${ productId } ` ) ;
200+ await expect ( page . getByLabel ( 'Conditional Output' ) ) . toBeHidden ( ) ;
201+
202+ const addToCartButton = page . locator ( 'form.cart' ) . getByRole (
203+ 'button' ,
204+ {
205+ name : 'Add to cart' ,
206+ exact : true ,
207+ }
208+ ) ;
209+
210+ await addToCartButton . click ( ) ;
211+ await page . waitForLoadState ( 'networkidle' ) ;
212+ await page . goto ( '/cart/' ) ;
213+ await expect ( page . getByText ( 'Product 1' ) ) . toBeVisible ( ) ;
214+ await expect ( page . locator ( 'body' ) ) . not . toContainText ( outputError ) ;
215+
216+ await clearCart ( page ) ;
217+ await page . goto ( `/?p=${ productId } ` ) ;
218+ await page
219+ . locator ( `select[name="ppom[fields][${ selectFieldId } ]"]` )
220+ . selectOption ( { index : 1 } ) ;
221+
222+ const outputInput = page . locator (
223+ `input[name="ppom[fields][${ outputFieldId } ]"]`
224+ ) ;
225+
226+ await expect ( outputInput ) . toBeVisible ( ) ;
227+ await addToCartButton . click ( ) ;
228+ await expect ( page . locator ( 'body' ) ) . toContainText (
229+ `Conditional Output: ${ outputError } `
230+ ) ;
231+
232+ await outputInput . fill ( 'Condition satisfied' ) ;
233+ await addToCartButton . click ( ) ;
234+ await page . waitForLoadState ( 'networkidle' ) ;
235+ await page . goto ( '/cart/' ) ;
236+
237+ await expect ( page . getByText ( 'Product 1' ) ) . toBeVisible ( ) ;
238+ await expect ( page . locator ( 'body' ) ) . toContainText (
239+ 'Condition satisfied'
240+ ) ;
241+ } ) ;
134242} ) ;
0 commit comments