@@ -4,7 +4,8 @@ const { initLabelStudio } = require("./helpers");
44
55Feature ( "Test required param" ) ; 
66
7- const  config  =  ` 
7+ const  createConfig  =  ( {  visibleWhen =  "choice-selected"  }  =  { } )  =>  { 
8+   return  ` 
89  <View> 
910    <Text name="text" value="$text"></Text> 
1011    <Choices name="validation-label" required="true" toName="text"> 
@@ -16,7 +17,7 @@ const config = `
1617      <Choice value="Me neither" alias="neither"></Choice> 
1718    </Choices> 
1819    <Choices name="easter-egg" required="true" toName="text" 
19-       visibleWhen="choice-selected " 
20+       visibleWhen="${ visibleWhen }  " 
2021      whenTagName="second" 
2122      whenChoiceValue="Me neither" 
2223    > 
@@ -25,6 +26,8 @@ const config = `
2526    </Choices> 
2627  </View> 
2728` ; 
29+ } ; 
30+ 
2831
2932const  complex  =  ` 
3033  <View> 
@@ -85,7 +88,7 @@ const result = {
8588const  annotations  =  [ {  id : "1" ,  result : [ result ]  } ] ; 
8689
8790Scenario ( "Check required param" ,  async  function ( {  I } )  { 
88-   const  params  =  {  config,  data : {  text }  } ; 
91+   const  params  =  {  config :  createConfig ( ) ,  data : {  text }  } ; 
8992
9093  const  waitForError  =  name  =>  { 
9194    I . waitForText ( "OK" ) ; 
@@ -204,3 +207,57 @@ Scenario("Check required param in complex config", async function({ I }) {
204207  I . dontSee ( "Submit" ) ; 
205208  I . see ( "Update" ) ; 
206209} ) ; 
210+ 
211+ Scenario ( "Check required param with visibleWhen='choice-unselected'" ,  async  function ( {  I,  LabelStudio } )  { 
212+   const  params  =  {  config : createConfig ( {  visibleWhen : 'choice-unselected'  } ) ,  data : {  text }  } ; 
213+   const  waitForError  =  name  =>  { 
214+     I . waitForText ( "OK" ) ; 
215+     I . see ( "Warning" ) ; 
216+     I . see ( 'Checkbox "'  +  name  +  '" is required' ) ; 
217+     I . seeElement ( ".ant-modal" ) ; 
218+     I . click ( "OK" ) ; 
219+     I . waitToHide ( ".ant-modal" ) ; 
220+   } ; 
221+ 
222+   I . amOnPage ( "/" ) ; 
223+   LabelStudio . setFeatureFlags ( { 
224+     ff_front_dev_1372_visible_when_choice_unselected_11022022_short : true , 
225+   } ) ; 
226+   LabelStudio . init ( params ) ; 
227+ 
228+   // Add new Annotation to be able to submit it 
229+   I . click ( '[aria-label="Annotations List Toggle"]' ) ; 
230+   I . click ( '[aria-label="Create Annotation"]' ) ; 
231+ 
232+   // Select one from each choices groups, except the one with visibleWhen condition 
233+   I . click ( "Valid" ) ; 
234+   I . click ( "Don't select me" ) ; 
235+ 
236+   // We should get error, cause "easter-egg" is visible and required 
237+   I . click ( "Submit" ) ; 
238+   waitForError ( "easter-egg" ) ; 
239+ 
240+   // Select the "Me neither" option to make the "easter-egg" block not required 
241+   I . click ( "Me neither" ) ; 
242+   I . click ( "Submit" ) ; 
243+   // Annotation is submitted, so now we can only update it 
244+   I . dontSee ( "Submit" ) ; 
245+   I . see ( "Update" ) ; 
246+ 
247+   // Reset to check another scenario 
248+   LabelStudio . init ( params ) ; 
249+   // LabelStudio is reloaded, there are no new annotation from prev steps 
250+   I . dontSee ( "New annotation" ) ; 
251+   I . click ( '[aria-label="Annotations List Toggle"]' ) ; 
252+   I . click ( '[aria-label="Create Annotation"]' ) ; 
253+ 
254+   // Select all required options we have 
255+   I . click ( "Valid" ) ; 
256+   I . click ( "Don't select me" ) ; 
257+   I . click ( "Secret level" ) ; 
258+ 
259+   I . click ( "Submit" ) ; 
260+   // Annotation is submitted, so now we can only update it 
261+   I . dontSee ( "Submit" ) ; 
262+   I . see ( "Update" ) ; 
263+ } ) ; 
0 commit comments