@@ -722,3 +722,240 @@ Scenario('Taxonomy maxUsages', async ({ I, LabelStudio, AtTaxonomy }) => {
722
722
AtTaxonomy . dontSeeCheckedItemByText ( 'One' ) ;
723
723
AtTaxonomy . dontSeeSelectedValues ( 'One' ) ;
724
724
} ) ;
725
+
726
+ Scenario ( 'Taxonomy visibleWhen' , async ( { I, LabelStudio, AtTaxonomy } ) => {
727
+ const createConfig = ( { showFullPath = false , visibleWhen = 'choice-selected' , whenChoiceValue = 'Four' } = { } ) => `
728
+ <View>
729
+ <Text name="text" value="$text"/>
730
+ <Taxonomy required="true" name="taxonomy" toName="text" leafsOnly="true" placeholder="Select something..." showFullPath="${ showFullPath } ">
731
+ <Choice value="One to three">
732
+ <Choice value="One" />
733
+ <Choice value="Two" />
734
+ <Choice value="Three" />
735
+ </Choice>
736
+ <Choice value="Four to seven">
737
+ <Choice value="Four" />
738
+ <Choice value="Five" />
739
+ <Choice value="Six" />
740
+ <Choice value="Seven" />
741
+ </Choice>
742
+ </Taxonomy>
743
+ <Choices name="other" toName="text"
744
+ showInline="true"
745
+ visibleWhen="${ visibleWhen } "
746
+ whenTagName="taxonomy"
747
+ whenChoiceValue="${ whenChoiceValue } "
748
+ >
749
+ <Choice value="Eight" />
750
+ <Choice value="Nine" />
751
+ </Choices>
752
+ </View>
753
+ ` ;
754
+
755
+ I . amOnPage ( '/' ) ;
756
+ LabelStudio . init ( {
757
+ config : createConfig ( ) ,
758
+ data : {
759
+ text : 'A text' ,
760
+ } ,
761
+ } ) ;
762
+ I . say ( 'Should see values of choices and work with them' ) ;
763
+ AtTaxonomy . clickTaxonomy ( ) ;
764
+ AtTaxonomy . toggleGroupWithText ( 'One to three' ) ;
765
+ AtTaxonomy . toggleGroupWithText ( 'Four to seven' ) ;
766
+ AtTaxonomy . seeItemByText ( 'Two' ) ;
767
+ AtTaxonomy . seeItemByText ( 'Five' ) ;
768
+ AtTaxonomy . clickItemByText ( 'Three' ) ;
769
+ AtTaxonomy . clickItemByText ( 'Four' ) ;
770
+ AtTaxonomy . seeSelectedValues ( [ 'Three' , 'Four' ] ) ;
771
+ AtTaxonomy . clickTaxonomy ( ) ;
772
+ I . click ( 'Eight' ) ; // click on the choice
773
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
774
+ I . say ( 'Should get results for taxonomy and choices' ) ;
775
+
776
+ let result = await LabelStudio . serialize ( ) ;
777
+
778
+ assert . deepStrictEqual ( result [ 0 ] . value . taxonomy , [ [ 'One to three' , 'Three' ] , [ 'Four to seven' , 'Four' ] ] ) ;
779
+ assert . deepStrictEqual ( result [ 1 ] . value . choices , [ 'Eight' ] ) ;
780
+
781
+ I . say ( 'Should get results for only taxonomy when visibleWhen is not met' ) ;
782
+ AtTaxonomy . clickTaxonomy ( ) ;
783
+ AtTaxonomy . clickItemByText ( 'Four' ) ;
784
+ AtTaxonomy . clickTaxonomy ( ) ;
785
+ I . dontSeeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
786
+
787
+ result = await LabelStudio . serialize ( ) ;
788
+
789
+ assert . deepStrictEqual ( result [ 0 ] . value . taxonomy , [ [ 'One to three' , 'Three' ] ] ) ;
790
+ assert . deepStrictEqual ( result ?. [ 1 ] ?. value ?. choices , undefined ) ;
791
+
792
+ I . say ( 'Should get results for taxonomy and choices when visibleWhen is met' ) ;
793
+ AtTaxonomy . clickTaxonomy ( ) ;
794
+ AtTaxonomy . clickItemByText ( 'Four' ) ;
795
+ AtTaxonomy . clickTaxonomy ( ) ;
796
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
797
+
798
+ result = await LabelStudio . serialize ( ) ;
799
+
800
+ assert . deepStrictEqual ( result [ 0 ] . value . taxonomy , [ [ 'One to three' , 'Three' ] , [ 'Four to seven' , 'Four' ] ] ) ;
801
+ assert . deepStrictEqual ( result [ 1 ] . value . choices , [ 'Eight' ] ) ;
802
+
803
+ await session ( 'Deserialization' , async ( ) => {
804
+ I . amOnPage ( '/' ) ;
805
+ LabelStudio . init ( {
806
+ config : createConfig ( ) ,
807
+ data : {
808
+ text : 'A text' ,
809
+ } ,
810
+ annotations : [ {
811
+ id : 'test' ,
812
+ result,
813
+ } ] ,
814
+ } ) ;
815
+ I . say ( 'Should see the same result' ) ;
816
+ AtTaxonomy . clickTaxonomy ( ) ;
817
+ AtTaxonomy . toggleGroupWithText ( 'One to three' ) ;
818
+ AtTaxonomy . toggleGroupWithText ( 'Four to seven' ) ;
819
+ AtTaxonomy . seeCheckedItemByText ( 'Three' ) ;
820
+ AtTaxonomy . seeCheckedItemByText ( 'Four' ) ;
821
+ AtTaxonomy . seeSelectedValues ( [ 'Three' , 'Four' ] ) ;
822
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
823
+ } ) ;
824
+
825
+ await session ( 'ShowFullPath' , async ( ) => {
826
+ //showFullPath
827
+ I . amOnPage ( '/' ) ;
828
+ LabelStudio . init ( {
829
+ config : createConfig ( { showFullPath : true } ) ,
830
+ data : {
831
+ text : 'A text' ,
832
+ } ,
833
+ annotations : [ {
834
+ id : 'test' ,
835
+ result,
836
+ } ] ,
837
+ } ) ;
838
+ I . say ( 'Should see the full paths' ) ;
839
+ AtTaxonomy . clickTaxonomy ( ) ;
840
+ AtTaxonomy . seeSelectedValues ( [ 'One to three / Three' , 'Four to seven / Four' ] ) ;
841
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
842
+ } ) ;
843
+ } ) ;
844
+
845
+ Scenario ( 'Taxonomy visibleWhen with aliases' , async ( { I, LabelStudio, AtTaxonomy } ) => {
846
+ const createConfig = ( { showFullPath = false , visibleWhen = 'choice-selected' , whenChoiceValue = 'Four' } = { } ) => `
847
+ <View>
848
+ <Text name="text" value="$text"/>
849
+ <Taxonomy required="true" name="taxonomy" toName="text" leafsOnly="true" placeholder="Select something..." showFullPath="${ showFullPath } ">
850
+ <Choice alias="1-3" value="One to three">
851
+ <Choice alias="1" value="One" />
852
+ <Choice alias="2" value="Two" />
853
+ <Choice alias="3" value="Three" />
854
+ </Choice>
855
+ <Choice alias="4-7" value="Four to seven">
856
+ <Choice alias="4" value="Four" />
857
+ <Choice alias="5" value="Five" />
858
+ <Choice alias="6" value="Six" />
859
+ <Choice alias="7" value="Seven" />
860
+ </Choice>
861
+ </Taxonomy>
862
+ <Choices name="choices" toName="text"
863
+ visibleWhen="${ visibleWhen } "
864
+ whenTagName="taxonomy"
865
+ whenChoiceValue="${ whenChoiceValue } "
866
+ >
867
+ <Choice alias="8" value="Eight"></Choice>
868
+ <Choice alias="9" value="Nine"></Choice>
869
+ </Choices>
870
+ </View>
871
+ ` ;
872
+
873
+ I . amOnPage ( '/' ) ;
874
+ LabelStudio . init ( {
875
+ config : createConfig ( ) ,
876
+ data : {
877
+ text : 'A text' ,
878
+ } ,
879
+ } ) ;
880
+ I . say ( 'Should see values of choices and work with them' ) ;
881
+ AtTaxonomy . clickTaxonomy ( ) ;
882
+ AtTaxonomy . toggleGroupWithText ( 'One to three' ) ;
883
+ AtTaxonomy . toggleGroupWithText ( 'Four to seven' ) ;
884
+ AtTaxonomy . seeItemByText ( 'Two' ) ;
885
+ AtTaxonomy . seeItemByText ( 'Five' ) ;
886
+ AtTaxonomy . clickItemByText ( 'Three' ) ;
887
+ AtTaxonomy . clickItemByText ( 'Four' ) ;
888
+ AtTaxonomy . seeSelectedValues ( [ 'Three' , 'Four' ] ) ;
889
+ AtTaxonomy . clickTaxonomy ( ) ;
890
+ I . click ( 'Eight' ) ; // click on the choice
891
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
892
+ I . say ( 'Should get aliases as results' ) ;
893
+
894
+ let result = await LabelStudio . serialize ( ) ;
895
+
896
+ assert . deepStrictEqual ( result [ 0 ] . value . taxonomy , [ [ '1-3' , '3' ] , [ '4-7' , '4' ] ] ) ;
897
+ assert . deepStrictEqual ( result [ 1 ] . value . choices , [ '8' ] ) ;
898
+
899
+ I . say ( 'Should get alias results for only taxonomy when visibleWhen is not met' ) ;
900
+ AtTaxonomy . clickTaxonomy ( ) ;
901
+ AtTaxonomy . clickItemByText ( 'Four' ) ;
902
+ AtTaxonomy . clickTaxonomy ( ) ;
903
+ I . dontSeeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
904
+
905
+ result = await LabelStudio . serialize ( ) ;
906
+
907
+ assert . deepStrictEqual ( result [ 0 ] . value . taxonomy , [ [ '1-3' , '3' ] ] ) ;
908
+ assert . deepStrictEqual ( result ?. [ 1 ] ?. value ?. choices , undefined ) ;
909
+
910
+ I . say ( 'Should get alias results for taxonomy and choices when visibleWhen is met' ) ;
911
+ AtTaxonomy . clickTaxonomy ( ) ;
912
+ AtTaxonomy . clickItemByText ( 'Four' ) ;
913
+ AtTaxonomy . clickTaxonomy ( ) ;
914
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
915
+
916
+ result = await LabelStudio . serialize ( ) ;
917
+
918
+ assert . deepStrictEqual ( result [ 0 ] . value . taxonomy , [ [ '1-3' , '3' ] , [ '4-7' , '4' ] ] ) ;
919
+ assert . deepStrictEqual ( result [ 1 ] . value . choices , [ '8' ] ) ;
920
+
921
+ await session ( 'Deserialization' , async ( ) => {
922
+ I . amOnPage ( '/' ) ;
923
+ LabelStudio . init ( {
924
+ config : createConfig ( ) ,
925
+ data : {
926
+ text : 'A text' ,
927
+ } ,
928
+ annotations : [ {
929
+ id : 'test' ,
930
+ result,
931
+ } ] ,
932
+ } ) ;
933
+ I . say ( 'Should see the same result' ) ;
934
+ AtTaxonomy . clickTaxonomy ( ) ;
935
+ AtTaxonomy . toggleGroupWithText ( 'One to three' ) ;
936
+ AtTaxonomy . toggleGroupWithText ( 'Four to seven' ) ;
937
+ AtTaxonomy . seeCheckedItemByText ( 'Three' ) ;
938
+ AtTaxonomy . seeCheckedItemByText ( 'Four' ) ;
939
+ AtTaxonomy . seeSelectedValues ( [ 'Three' , 'Four' ] ) ;
940
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
941
+ } ) ;
942
+
943
+ await session ( 'ShowFullPath' , async ( ) => {
944
+ //showFullPath
945
+ I . amOnPage ( '/' ) ;
946
+ LabelStudio . init ( {
947
+ config : createConfig ( { showFullPath : true } ) ,
948
+ data : {
949
+ text : 'A text' ,
950
+ } ,
951
+ annotations : [ {
952
+ id : 'test' ,
953
+ result,
954
+ } ] ,
955
+ } ) ;
956
+ I . say ( 'Should see the full paths' ) ;
957
+ AtTaxonomy . clickTaxonomy ( ) ;
958
+ AtTaxonomy . seeSelectedValues ( [ 'One to three / Three' , 'Four to seven / Four' ] ) ;
959
+ I . seeElement ( '.ant-checkbox-checked [name=\'Eight\']' ) ;
960
+ } ) ;
961
+ } ) ;
0 commit comments