1
+ import { checkPageVisibility , FormValues , GroupsType } from "../formContext" ;
2
+ import type { PublicFormRecord , FormElement } from "../types" ;
3
+
4
+ describe ( "checkPageVisibility" , ( ) => {
5
+ const baseElement : FormElement = {
6
+ id : 1 ,
7
+ type : "textField" ,
8
+ properties : { conditionalRules : [ ] }
9
+ } as unknown as FormElement ;
10
+
11
+ it ( "returns true if form has no groups" , ( ) => {
12
+ const formRecord = {
13
+ form : {
14
+ elements : [ baseElement ]
15
+ }
16
+ } as PublicFormRecord ;
17
+ expect ( checkPageVisibility ( formRecord , baseElement , { } ) ) . toBe ( true ) ;
18
+ } ) ;
19
+
20
+ it ( "returns true if element's group is in groupHistory (array)" , ( ) => {
21
+ const groups : GroupsType = {
22
+ groupA : { name : "A" , titleEn : "" , titleFr : "" , elements : [ "1" ] }
23
+ } ;
24
+ const formRecord = {
25
+ form : {
26
+ elements : [ baseElement ] ,
27
+ groups
28
+ }
29
+ } as PublicFormRecord ;
30
+ const values : FormValues = { groupHistory : [ "groupA" ] } ;
31
+ expect ( checkPageVisibility ( formRecord , baseElement , values ) ) . toBe ( true ) ;
32
+ } ) ;
33
+
34
+ it ( "returns true if element's group is in groupHistory (string)" , ( ) => {
35
+ const groups : GroupsType = {
36
+ groupA : { name : "A" , titleEn : "" , titleFr : "" , elements : [ "1" ] }
37
+ } ;
38
+ const formRecord = {
39
+ form : {
40
+ elements : [ baseElement ] ,
41
+ groups
42
+ }
43
+ } as PublicFormRecord ;
44
+ const values : FormValues = { groupHistory : "groupA" } ;
45
+ expect ( checkPageVisibility ( formRecord , baseElement , values ) ) . toBe ( true ) ;
46
+ } ) ;
47
+
48
+ it ( "returns false if element's group is not in groupHistory" , ( ) => {
49
+ const groups : GroupsType = {
50
+ groupA : { name : "A" , titleEn : "" , titleFr : "" , elements : [ "1" ] }
51
+ } ;
52
+ const formRecord = {
53
+ form : {
54
+ elements : [ baseElement ] ,
55
+ groups
56
+ }
57
+ } as PublicFormRecord ;
58
+ const values : FormValues = { groupHistory : [ "groupB" ] } ;
59
+ expect ( checkPageVisibility ( formRecord , baseElement , values ) ) . toBe ( false ) ;
60
+ } ) ;
61
+
62
+ it ( "returns false if element is not in any group" , ( ) => {
63
+ const groups : GroupsType = {
64
+ groupA : { name : "A" , titleEn : "" , titleFr : "" , elements : [ "2" ] }
65
+ } ;
66
+ const formRecord = {
67
+ form : {
68
+ elements : [ baseElement ] ,
69
+ groups
70
+ }
71
+ } as PublicFormRecord ;
72
+ const values : FormValues = { groupHistory : [ "groupA" ] } ;
73
+ expect ( checkPageVisibility ( formRecord , baseElement , values ) ) . toBe ( false ) ;
74
+ } ) ;
75
+ } ) ;
0 commit comments