1
1
import { test , expect } from '@playwright/test' ;
2
2
import { ProjectPage } from './pages/project' ;
3
3
4
- let project ;
5
-
6
4
test . describe ( 'Advanced form' , function ( ) {
7
5
8
6
test . beforeEach ( async function ( { page } ) {
9
- project = new ProjectPage ( page , 'form_advanced' ) ;
7
+ const project = new ProjectPage ( page , 'form_advanced' ) ;
10
8
await project . open ( ) ;
11
9
12
10
const formRequest = await project . openEditingFormWithLayer ( 'form_advanced_point' ) ;
13
11
await formRequest . response ( ) ;
14
12
13
+ // Create the promise to wait for GetData response
14
+ const getDataPromise = page . waitForResponse ( / j e l i x \/ f o r m s \/ g e t d a t a / )
15
+
15
16
// Click on map as form needs a geometry
16
17
project . clickOnMapLegacy ( 410 , 175 ) ;
18
+
19
+ // wait for the response completed
20
+ let getDataResponse = await getDataPromise ;
21
+ await getDataResponse . finished ( ) ;
17
22
} ) ;
18
23
19
- test ( 'should toggle tab visibility when toggling checkbox' , async function ( {
24
+ test ( 'should toggle tab visibility when toggling checkbox @readonly ' , async function ( {
20
25
page,
21
26
} ) {
27
+ const project = new ProjectPage ( page , 'form_advanced' ) ;
22
28
await expect (
23
29
page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
24
30
) . toBeHidden ( ) ;
25
31
await expect (
26
32
page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
27
33
) . toHaveText ( 'photo' ) ;
28
34
await expect (
29
- page . locator ( '#jforms_view_edition_has_photo ')
35
+ project . editingField ( 'has_photo ')
30
36
) . not . toBeChecked ( ) ;
31
37
32
38
// 't' is a legacy value meaning true. This might change in future
33
- await expect ( page . locator ( '#jforms_view_edition_has_photo' ) ) . toHaveValue (
34
- 't'
35
- ) ;
36
- await page . locator ( '#jforms_view_edition_has_photo' ) . click ( ) ;
39
+ await expect ( project . editingField ( 'has_photo' ) ) . toHaveValue ( 't' ) ;
40
+ // Create the promise to wait for GetGroupVisibilities response
41
+ let getGroupVisibilitiesPromise = page . waitForResponse ( / l i z m a p \/ e d i t i o n \/ g e t G r o u p V i s i b i l i t i e s / )
42
+ // Click on the checkbox has_photo
43
+ await project . editingField ( 'has_photo' ) . click ( ) ;
44
+ // wait for the response completed
45
+ let getGroupVisibilities = await getGroupVisibilitiesPromise ;
46
+ await getGroupVisibilities . finished ( ) ;
47
+ await expect ( getGroupVisibilities . status ( ) ) . toBe ( 200 ) ;
48
+ expect ( getGroupVisibilities . headers ( ) [ 'content-type' ] ) . toBe ( 'application/json' ) ;
49
+ // check body
50
+ let getGroupVisibilitiesBody = await getGroupVisibilities . json ( ) ;
51
+ expect ( getGroupVisibilitiesBody ) . toHaveProperty ( 'jforms_view_edition-tab1' ) ;
52
+ expect ( getGroupVisibilitiesBody [ 'jforms_view_edition-tab1' ] ) . toBe ( true ) ;
53
+ expect ( getGroupVisibilitiesBody ) . toHaveProperty ( 'jforms_view_edition-tab2' ) ;
54
+ expect ( getGroupVisibilitiesBody [ 'jforms_view_edition-tab2' ] ) . toBe ( true ) ;
55
+
56
+ // check the checkbox is checked
57
+ await expect ( project . editingField ( 'has_photo' ) ) . toBeChecked ( ) ;
58
+ // check the tab is now visible
37
59
await expect (
38
60
page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
39
61
) . toBeVisible ( ) ;
40
- await expect ( page . locator ( '#jforms_view_edition_has_photo' ) ) . toBeChecked ( ) ;
41
- await page . locator ( '#jforms_view_edition_has_photo' ) . click ( ) ;
62
+
63
+ // Create the promise to wait for GetGroupVisibilities response
64
+ getGroupVisibilitiesPromise = page . waitForResponse ( / l i z m a p \/ e d i t i o n \/ g e t G r o u p V i s i b i l i t i e s / )
65
+ // Click on the checkbox has_photo
66
+ await project . editingField ( 'has_photo' ) . click ( ) ;
67
+ // wait for the response completed
68
+ getGroupVisibilities = await getGroupVisibilitiesPromise ;
69
+ await getGroupVisibilities . finished ( ) ;
70
+ await expect ( getGroupVisibilities . status ( ) ) . toBe ( 200 ) ;
71
+ expect ( getGroupVisibilities . headers ( ) [ 'content-type' ] ) . toBe ( 'application/json' ) ;
72
+ // check body
73
+ getGroupVisibilitiesBody = await getGroupVisibilities . json ( ) ;
74
+ expect ( getGroupVisibilitiesBody ) . toHaveProperty ( 'jforms_view_edition-tab1' ) ;
75
+ expect ( getGroupVisibilitiesBody [ 'jforms_view_edition-tab1' ] ) . toBe ( true ) ;
76
+ expect ( getGroupVisibilitiesBody ) . toHaveProperty ( 'jforms_view_edition-tab2' ) ;
77
+ expect ( getGroupVisibilitiesBody [ 'jforms_view_edition-tab2' ] ) . toBe ( false ) ;
78
+
79
+ // check the checkbox is not checked
80
+ await expect (
81
+ project . editingField ( 'has_photo' )
82
+ ) . not . toBeChecked ( ) ;
83
+ // check the tab is again not visible
42
84
await expect (
43
85
page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
44
86
) . not . toBeVisible ( ) ;
45
- await expect (
46
- page . locator ( '#jforms_view_edition_has_photo' )
47
- ) . not . toBeChecked ( ) ;
48
87
} ) ;
49
88
50
- test ( 'should have expression constraint on field' , async function ( { page } ) {
89
+ test ( 'should have expression constraint on field @write' , async function ( { page } ) {
90
+ const project = new ProjectPage ( page , 'form_advanced' ) ;
51
91
// Type string not valid for expression constraint
52
- await page . locator ( '#jforms_view_edition_website ') . fill ( 'a' ) ;
53
- await page . locator ( '#jforms_view_edition__submit_submit ') . click ( ) ;
92
+ await project . editingField ( 'website ') . fill ( 'a' ) ;
93
+ await project . editingSubmit ( 'submit ') . click ( ) ;
54
94
55
95
// Assert an error is returned
56
96
await expect (
57
97
page . locator ( '#jforms_view_edition_website_label' )
58
98
) . toHaveClass ( / j f o r m s - e r r o r / ) ;
59
- await expect ( page . locator ( '#jforms_view_edition_website ') ) . toHaveClass (
99
+ await expect ( project . editingField ( 'website ') ) . toHaveClass (
60
100
/ j f o r m s - e r r o r /
61
101
) ;
62
102
await expect ( page . locator ( '#jforms_view_edition_errors' ) ) . toHaveClass (
@@ -67,56 +107,91 @@ test.describe('Advanced form', function () {
67
107
) ;
68
108
69
109
// Type string valid for expression constraint
70
- await page
71
- . locator ( '#jforms_view_edition_website' )
110
+ await project . editingField ( 'website' )
72
111
. fill ( 'https://www.3liz.com' ) ;
73
- await page . locator ( '#jforms_view_edition__submit_submit ') . click ( ) ;
112
+ await project . editingSubmit ( 'submit ') . click ( ) ;
74
113
75
114
// A message should confirm form had been saved and form selector should be displayed back
76
115
await expect ( page . locator ( '#lizmap-edition-message' ) ) . toBeVisible ( ) ;
77
116
await expect ( page . locator ( '#edition-layer' ) ) . toBeVisible ( ) ;
78
117
} ) ;
79
118
80
- test ( 'should change selected quartier and sousquartier based on drawn point' , async function ( {
119
+ test ( 'should change selected quartier and sousquartier based on drawn point @readonly ' , async function ( {
81
120
page,
82
121
} ) {
122
+ const project = new ProjectPage ( page , 'form_advanced' ) ;
83
123
await expect (
84
- page . locator ( '#jforms_view_edition_quartier option' )
124
+ project . editingField ( 'quartier' ) . locator ( 'option' )
85
125
) . toHaveCount ( 2 ) ;
86
126
await expect (
87
- page . locator ( '#jforms_view_edition_quartier option' ) . first ( )
127
+ project . editingField ( 'quartier' ) . locator ( 'option' ) . first ( )
88
128
) . toHaveText ( '' ) ;
89
129
await expect (
90
- page . locator ( '#jforms_view_edition_quartier option' ) . last ( )
130
+ project . editingField ( 'quartier' ) . locator ( 'option' ) . last ( )
91
131
) . toHaveText ( 'HOPITAUX-FACULTES' ) ;
92
132
93
133
// Cancel and open form
94
134
page . on ( 'dialog' , dialog => dialog . accept ( ) ) ;
95
- await page . locator ( '#jforms_view_edition__submit_cancel ') . click ( ) ;
135
+ await project . editingSubmit ( 'cancel ') . click ( ) ;
96
136
await page . locator ( '#edition-draw' ) . click ( ) ;
97
137
98
- // Create the promise to wait for the response to GetData
99
- const getDataPromise = page . waitForResponse ( / j e l i x \/ f o r m s \/ g e t d a t a / ) ;
138
+ // Create the promise to wait for the request to GetData for quartier
139
+ let getDataQuartierPromise = page . waitForRequest (
140
+ request => request . method ( ) === 'POST' && / j e l i x \/ f o r m s \/ g e t d a t a / . test ( request . url ( ) ) &&
141
+ request . postData ( ) ?. includes ( '_ref=quartier' )
142
+ ) ;
143
+ // Create the promise to wait for the request to GetData for sousquartier
144
+ let getDataSousQuartierPromise = page . waitForRequest (
145
+ request => request . method ( ) === 'POST' && / j e l i x \/ f o r m s \/ g e t d a t a / . test ( request . url ( ) ) &&
146
+ request . postData ( ) ?. includes ( '_ref=sousquartier' )
147
+ ) ;
100
148
// Assert quartier value is good for another drawn point
101
149
project . clickOnMapLegacy ( 455 , 250 ) ;
102
- // Wait for GetData completed before checking the select (for quartier based on geometry)
103
- await getDataPromise ;
150
+ // Wait for GetData quartier completed (based on geometry)
151
+ let getDataQuartier = await ( await getDataQuartierPromise ) . response ( ) ;
152
+ expect ( getDataQuartier . status ( ) ) . toBe ( 200 ) ;
153
+ expect ( getDataQuartier . headers ( ) [ 'content-type' ] ) . toBe ( 'application/json' ) ;
154
+ // check body
155
+ let getDataQuartierBody = await getDataQuartier . json ( ) ;
156
+ expect ( getDataQuartierBody . length ) . toBe ( 1 ) ;
157
+
158
+ // Wait for GetData quartier completed (based on quartier)
159
+ let getDataSousQuartier = await ( await getDataSousQuartierPromise ) . response ( ) ;
160
+ expect ( getDataSousQuartier . status ( ) ) . toBe ( 200 ) ;
161
+ expect ( getDataSousQuartier . headers ( ) [ 'content-type' ] ) . toBe ( 'application/json' ) ;
162
+ // check body
163
+ let getDataSousQuartierBody = await getDataSousQuartier . json ( ) ;
164
+ expect ( getDataSousQuartierBody . length ) . toBe ( 0 ) ;
165
+
166
+ // Assert 2 options are proposed for quartier list
104
167
await expect (
105
- page . locator ( '#jforms_view_edition_quartier option' )
168
+ project . editingField ( 'quartier' ) . locator ( 'option' )
106
169
) . toHaveCount ( 2 ) ;
107
170
108
- await page . waitForTimeout ( 100 ) ;
171
+ // Assert 1 option are proposed for sousquartier list
172
+ await expect (
173
+ project . editingField ( 'sousquartier' ) . locator ( 'option' )
174
+ ) . toHaveCount ( 1 ) ;
109
175
176
+ // Create the promise to wait for the request to GetData for sousquartier
177
+ getDataSousQuartierPromise = page . waitForRequest (
178
+ request => request . method ( ) === 'POST' && / j e l i x \/ f o r m s \/ g e t d a t a / . test ( request . url ( ) ) &&
179
+ request . postData ( ) ?. includes ( '_ref=sousquartier' )
180
+ ) ;
110
181
// Select MONTPELLIER CENTRE
111
- await page
112
- . locator ( '#jforms_view_edition_quartier' )
182
+ await project . editingField ( 'quartier' )
113
183
. selectOption ( { label : 'MONTPELLIER CENTRE' } ) ;
114
- // Wait for GetData completed before checking the select (for sousquartier based on quartier)
115
- await getDataPromise ;
184
+ // Wait for GetData quartier completed (based on quartier)
185
+ getDataSousQuartier = await ( await getDataSousQuartierPromise ) . response ( ) ;
186
+ expect ( getDataSousQuartier . status ( ) ) . toBe ( 200 ) ;
187
+ expect ( getDataSousQuartier . headers ( ) [ 'content-type' ] ) . toBe ( 'application/json' ) ;
188
+ // check body
189
+ getDataSousQuartierBody = await getDataSousQuartier . json ( ) ;
190
+ expect ( getDataSousQuartierBody . length ) . toBe ( 10 ) ;
116
191
117
192
// Assert 11 options are proposed for sousquartier list
118
193
await expect (
119
- page . locator ( '#jforms_view_edition_sousquartier option' )
194
+ project . editingField ( 'sousquartier' ) . locator ( 'option' )
120
195
) . toHaveCount ( 11 ) ;
121
196
} ) ;
122
197
} ) ;
0 commit comments