11import { test , expect } from '@playwright/test' ;
22import { ProjectPage } from './pages/project' ;
33
4- let project ;
5-
64test . describe ( 'Advanced form' , function ( ) {
75
86 test . beforeEach ( async function ( { page } ) {
9- project = new ProjectPage ( page , 'form_advanced' ) ;
7+ const project = new ProjectPage ( page , 'form_advanced' ) ;
108 await project . open ( ) ;
119
1210 const formRequest = await project . openEditingFormWithLayer ( 'form_advanced_point' ) ;
1311 await formRequest . response ( ) ;
1412
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+
1516 // Click on map as form needs a geometry
1617 project . clickOnMapLegacy ( 410 , 175 ) ;
18+
19+ // wait for the response completed
20+ let getDataResponse = await getDataPromise ;
21+ await getDataResponse . finished ( ) ;
1722 } ) ;
1823
19- test ( 'should toggle tab visibility when toggling checkbox' , async function ( {
24+ test ( 'should toggle tab visibility when toggling checkbox @readonly ' , async function ( {
2025 page,
2126 } ) {
27+ const project = new ProjectPage ( page , 'form_advanced' ) ;
2228 await expect (
2329 page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
2430 ) . toBeHidden ( ) ;
2531 await expect (
2632 page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
2733 ) . toHaveText ( 'photo' ) ;
2834 await expect (
29- page . locator ( '#jforms_view_edition_has_photo ')
35+ project . editingField ( 'has_photo ')
3036 ) . not . toBeChecked ( ) ;
3137
3238 // '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
3759 await expect (
3860 page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
3961 ) . 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
4284 await expect (
4385 page . locator ( '#jforms_view_edition-tabs > li:nth-child(2)' )
4486 ) . not . toBeVisible ( ) ;
45- await expect (
46- page . locator ( '#jforms_view_edition_has_photo' )
47- ) . not . toBeChecked ( ) ;
4887 } ) ;
4988
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' ) ;
5191 // 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 ( ) ;
5494
5595 // Assert an error is returned
5696 await expect (
5797 page . locator ( '#jforms_view_edition_website_label' )
5898 ) . 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 (
60100 / j f o r m s - e r r o r /
61101 ) ;
62102 await expect ( page . locator ( '#jforms_view_edition_errors' ) ) . toHaveClass (
@@ -67,56 +107,91 @@ test.describe('Advanced form', function () {
67107 ) ;
68108
69109 // Type string valid for expression constraint
70- await page
71- . locator ( '#jforms_view_edition_website' )
110+ await project . editingField ( 'website' )
72111 . fill ( 'https://www.3liz.com' ) ;
73- await page . locator ( '#jforms_view_edition__submit_submit ') . click ( ) ;
112+ await project . editingSubmit ( 'submit ') . click ( ) ;
74113
75114 // A message should confirm form had been saved and form selector should be displayed back
76115 await expect ( page . locator ( '#lizmap-edition-message' ) ) . toBeVisible ( ) ;
77116 await expect ( page . locator ( '#edition-layer' ) ) . toBeVisible ( ) ;
78117 } ) ;
79118
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 ( {
81120 page,
82121 } ) {
122+ const project = new ProjectPage ( page , 'form_advanced' ) ;
83123 await expect (
84- page . locator ( '#jforms_view_edition_quartier option' )
124+ project . editingField ( 'quartier' ) . locator ( 'option' )
85125 ) . toHaveCount ( 2 ) ;
86126 await expect (
87- page . locator ( '#jforms_view_edition_quartier option' ) . first ( )
127+ project . editingField ( 'quartier' ) . locator ( 'option' ) . first ( )
88128 ) . toHaveText ( '' ) ;
89129 await expect (
90- page . locator ( '#jforms_view_edition_quartier option' ) . last ( )
130+ project . editingField ( 'quartier' ) . locator ( 'option' ) . last ( )
91131 ) . toHaveText ( 'HOPITAUX-FACULTES' ) ;
92132
93133 // Cancel and open form
94134 page . on ( 'dialog' , dialog => dialog . accept ( ) ) ;
95- await page . locator ( '#jforms_view_edition__submit_cancel ') . click ( ) ;
135+ await project . editingSubmit ( 'cancel ') . click ( ) ;
96136 await page . locator ( '#edition-draw' ) . click ( ) ;
97137
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+ ) ;
100148 // Assert quartier value is good for another drawn point
101149 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
104167 await expect (
105- page . locator ( '#jforms_view_edition_quartier option' )
168+ project . editingField ( 'quartier' ) . locator ( 'option' )
106169 ) . toHaveCount ( 2 ) ;
107170
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 ) ;
109175
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+ ) ;
110181 // Select MONTPELLIER CENTRE
111- await page
112- . locator ( '#jforms_view_edition_quartier' )
182+ await project . editingField ( 'quartier' )
113183 . 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 ) ;
116191
117192 // Assert 11 options are proposed for sousquartier list
118193 await expect (
119- page . locator ( '#jforms_view_edition_sousquartier option' )
194+ project . editingField ( 'sousquartier' ) . locator ( 'option' )
120195 ) . toHaveCount ( 11 ) ;
121196 } ) ;
122197} ) ;
0 commit comments