@@ -16,79 +16,161 @@ describe('Input box', () => {
16
16
args : [ '--incognito' , '--disable-web-security' ] ,
17
17
devtools : false ,
18
18
} ) ;
19
- page = await browser . newPage ( ) ;
20
19
21
- await page . setRequestInterception ( true ) ;
22
-
23
- page . on ( 'request' , ( interceptedRequest ) => {
24
- const url = interceptedRequest . url ( ) ;
25
- if ( url === `${ STAGING_API_URL } /levels` ) {
26
- interceptedRequest . respond ( {
27
- status : 200 ,
28
- contentType : 'application/json' ,
29
- headers : {
30
- 'Access-Control-Allow-Origin' : '*' ,
31
- 'Access-Control-Allow-Methods' : 'GET, POST, PUT, DELETE, OPTIONS' ,
32
- 'Access-Control-Allow-Headers' : 'Content-Type, Authorization' ,
33
- } ,
34
- body : JSON . stringify ( levels ) ,
35
- } ) ;
36
- } else if ( url === `${ STAGING_API_URL } /users` ) {
37
- interceptedRequest . respond ( {
38
- status : 200 ,
39
- contentType : 'application/json' ,
40
- headers : {
41
- 'Access-Control-Allow-Origin' : '*' ,
42
- 'Access-Control-Allow-Methods' : 'GET, POST, PUT, DELETE, OPTIONS' ,
43
- 'Access-Control-Allow-Headers' : 'Content-Type, Authorization' ,
44
- } ,
45
- body : JSON . stringify ( users ) ,
46
- } ) ;
47
- } else if ( url === `${ STAGING_API_URL } /tags` ) {
48
- interceptedRequest . respond ( {
49
- status : 200 ,
50
- contentType : 'application/json' ,
51
- headers : {
52
- 'Access-Control-Allow-Origin' : '*' ,
53
- 'Access-Control-Allow-Methods' : 'GET, POST, PUT, DELETE, OPTIONS' ,
54
- 'Access-Control-Allow-Headers' : 'Content-Type, Authorization' ,
55
- } ,
56
- body : JSON . stringify ( tags ) ,
57
- } ) ;
58
- } else {
59
- interceptedRequest . continue ( ) ;
60
- }
61
- } ) ;
20
+ // Mock API response setup
21
+ const interceptAPI = async ( page ) => {
22
+ await page . setRequestInterception ( true ) ;
23
+ page . on ( 'request' , ( interceptedRequest ) => {
24
+ const url = interceptedRequest . url ( ) ;
25
+
26
+ const mockResponses = {
27
+ [ `${ STAGING_API_URL } /levels` ] : levels ,
28
+ [ `${ STAGING_API_URL } /users` ] : users ,
29
+ [ `${ STAGING_API_URL } /tags` ] : tags ,
30
+ } ;
31
+
32
+ if ( mockResponses [ url ] ) {
33
+ interceptedRequest . respond ( {
34
+ status : 200 ,
35
+ contentType : 'application/json' ,
36
+ headers : {
37
+ 'Access-Control-Allow-Origin' : '*' ,
38
+ } ,
39
+ body : JSON . stringify ( mockResponses [ url ] ) ,
40
+ } ) ;
41
+ } else {
42
+ interceptedRequest . continue ( ) ;
43
+ }
44
+ } ) ;
45
+ } ;
46
+
47
+ // Open a shared page instance and intercept API for all tests
48
+ page = await browser . newPage ( ) ;
49
+ await interceptAPI ( page ) ;
62
50
await page . goto ( 'http://localhost:8000/task' ) ;
63
51
await page . waitForNetworkIdle ( ) ;
64
52
} ) ;
65
53
66
54
afterAll ( async ( ) => {
67
55
await browser . close ( ) ;
68
56
} ) ;
69
- it ( 'DependsOn input box should exist' , async ( ) => {
70
- const inputBox = await page . evaluate ( ( ) =>
71
- document . querySelector ( '.inputBox' ) ,
72
- ) ;
73
- const linksDisplay = await page . evaluate ( ( ) =>
74
- document . querySelector ( '#linksDisplay' ) ,
75
- ) ;
57
+
58
+ // Form Presence Tests
59
+ describe ( 'Form Field Presence' , ( ) => {
60
+ it ( 'should display the title field' , async ( ) => {
61
+ const titleField = await page . $ ( '[data-testid="title"]' ) ;
62
+ expect ( titleField ) . toBeTruthy ( ) ;
63
+ } ) ;
64
+
65
+ it ( 'should display the status field' , async ( ) => {
66
+ const statusField = await page . $ ( '[data-testid="status"]' ) ;
67
+ expect ( statusField ) . toBeTruthy ( ) ;
68
+ } ) ;
69
+
70
+ it ( 'should display the priority field' , async ( ) => {
71
+ const priorityField = await page . $ ( '[data-testid="priority"]' ) ;
72
+ expect ( priorityField ) . toBeTruthy ( ) ;
73
+ } ) ;
74
+
75
+ it ( 'should display the isNoteworthy checkbox' , async ( ) => {
76
+ const noteworthyField = await page . $ ( '[data-testid="isNoteworthy"]' ) ;
77
+ expect ( noteworthyField ) . toBeTruthy ( ) ;
78
+ } ) ;
79
+
80
+ it ( 'should display the purpose field' , async ( ) => {
81
+ const purposeField = await page . $ ( '[data-testid="purpose"]' ) ;
82
+ expect ( purposeField ) . toBeTruthy ( ) ;
83
+ } ) ;
84
+
85
+ it ( 'should display the dependsOn field' , async ( ) => {
86
+ const dependsOnField = await page . $ ( '[data-testid="dependsOn"]' ) ;
87
+ expect ( dependsOnField ) . toBeTruthy ( ) ;
88
+ } ) ;
76
89
} ) ;
77
90
78
- it ( 'DependsOn input should have correct attributes' , async ( ) => {
79
- const input = await page . $ ( '#dependsOn' ) ;
80
- const type = await input . evaluate ( ( el ) => el . getAttribute ( 'type' ) ) ;
81
- const name = await input . evaluate ( ( el ) => el . getAttribute ( 'name' ) ) ;
82
- const id = await input . evaluate ( ( el ) => el . getAttribute ( 'id' ) ) ;
83
- const placeholder = await input . evaluate ( ( el ) =>
84
- el . getAttribute ( 'placeholder' ) ,
85
- ) ;
86
- const classList = await input . evaluate ( ( el ) => Array . from ( el . classList ) ) ;
87
-
88
- expect ( type ) . toBe ( 'text' ) ;
89
- expect ( name ) . toBe ( 'dependsOn' ) ;
90
- expect ( id ) . toBe ( 'dependsOn' ) ;
91
- expect ( placeholder ) . toBe ( 'Task ID separated with comma ' ) ;
92
- expect ( classList . includes ( 'notEditing' ) ) . toBeTruthy ( ) ;
91
+ // Status Field Behavior Tests
92
+ describe ( 'Status Field Behavior' , ( ) => {
93
+ beforeEach ( async ( ) => {
94
+ await page . goto ( 'http://localhost:8000/task' ) ;
95
+ await page . waitForNetworkIdle ( ) ;
96
+ } ) ;
97
+
98
+ it ( 'should have default status as "available"' , async ( ) => {
99
+ const defaultStatus = await page . $eval (
100
+ '[data-testid="status"] select' ,
101
+ ( el ) => el . value ,
102
+ ) ;
103
+ expect ( defaultStatus ) . toBe ( 'AVAILABLE' ) ;
104
+ } ) ;
105
+
106
+ it ( 'should show/hide fields based on "status" selection' , async ( ) => {
107
+ // Change status to "assigned"
108
+ await page . select ( '[data-testid="status"] select' , 'ASSIGNED' ) ;
109
+
110
+ const assigneeVisible = await page . $eval (
111
+ '[data-testid="assignee"]' ,
112
+ ( el ) => window . getComputedStyle ( el ) . display !== 'none' ,
113
+ ) ;
114
+ const endsOnVisible = await page . $eval (
115
+ '[data-testid="endsOn"]' ,
116
+ ( el ) => window . getComputedStyle ( el ) . display !== 'none' ,
117
+ ) ;
118
+ expect ( assigneeVisible ) . toBeTruthy ( ) ;
119
+ expect ( endsOnVisible ) . toBeTruthy ( ) ;
120
+
121
+ // Change status back to "available"
122
+ await page . select ( '[data-testid="status"] select' , 'available' ) ;
123
+
124
+ const assigneeHidden = await page . $eval (
125
+ '[data-testid="assignee"]' ,
126
+ ( el ) => window . getComputedStyle ( el ) . display === 'none' ,
127
+ ) ;
128
+ const endsOnHidden = await page . $eval (
129
+ '[data-testid="endsOn"]' ,
130
+ ( el ) => window . getComputedStyle ( el ) . display === 'none' ,
131
+ ) ;
132
+ expect ( assigneeHidden ) . toBeTruthy ( ) ;
133
+ expect ( endsOnHidden ) . toBeTruthy ( ) ;
134
+ } ) ;
135
+ } ) ;
136
+
137
+ // Dev Mode Tests
138
+ describe ( 'Dev Mode Behavior' , ( ) => {
139
+ beforeAll ( async ( ) => {
140
+ await page . goto ( 'http://localhost:8000/task?dev=true' ) ;
141
+ await page . waitForNetworkIdle ( ) ;
142
+ } ) ;
143
+
144
+ it ( 'should hide feature URL field in dev mode' , async ( ) => {
145
+ const featureUrlField = await page . $ ( '[data-testid="featureUrl"]' ) ;
146
+ const display = await page . $eval (
147
+ '[data-testid="featureUrl"]' ,
148
+ ( el ) => window . getComputedStyle ( el ) . display ,
149
+ ) ;
150
+ expect ( display ) . toBe ( 'none' ) ;
151
+ } ) ;
152
+
153
+ it ( 'should hide task level field in dev mode' , async ( ) => {
154
+ const taskLevelField = await page . $ ( '[data-testid="taskLevel"]' ) ;
155
+ const display = await page . $eval (
156
+ '[data-testid="taskLevel"]' ,
157
+ ( el ) => window . getComputedStyle ( el ) . display ,
158
+ ) ;
159
+ expect ( display ) . toBe ( 'none' ) ;
160
+ } ) ;
161
+
162
+ it ( 'should hide feature/group radio buttons in dev mode' , async ( ) => {
163
+ const radioButtons = await page . $ ( '[data-testid="radioButtons"]' ) ;
164
+ const display = await page . $eval (
165
+ '[data-testid="radioButtons"]' ,
166
+ ( el ) => window . getComputedStyle ( el ) . display ,
167
+ ) ;
168
+ expect ( display ) . toBe ( 'none' ) ;
169
+ } ) ;
170
+
171
+ it ( 'should display the dependsOn field in dev mode' , async ( ) => {
172
+ const dependsOnField = await page . $ ( '[data-testid="dependsOn"]' ) ;
173
+ expect ( dependsOnField ) . toBeTruthy ( ) ;
174
+ } ) ;
93
175
} ) ;
94
176
} ) ;
0 commit comments