11import { test , expect } from "@playwright/test" ;
2- import { beforeEachTest } from "./test-helper.js" ;
2+ import { beforeEachTest , fulfillDataRoute , fulfillEmptyRoutes , loginTest } from "./test-helper.js" ;
3+ import {
4+ playlistListJson ,
5+ onSaveJson ,
6+ errorJson ,
7+ screenGroupsListJson ,
8+ screenGroupsSingleJson
9+ } from "./data-fixtures.js" ;
10+ import { json } from "react-router-dom" ;
311
412test . describe ( "Create group page works" , ( ) => {
513 test . beforeEach ( async ( { page } ) => {
614 await beforeEachTest ( page ) ;
715 } ) ;
816
917 test . beforeEach ( async ( { page } ) => {
10- await page . goto ( "/admin/group/create" ) ;
11- await page . route ( "**/token" , async ( route ) => {
12- const json = {
13- token : "1" ,
14- refresh_token : "2" ,
15- tenants : [
16- {
17- tenantKey : "ABC" ,
18- title : "ABC Tenant" ,
19- description : "Description" ,
20- roles : [ "ROLE_ADMIN" ] ,
21- } ,
22- ] ,
23- user : {
24- fullname : "John Doe" ,
25- email : "johndoe@example.com" ,
26- } ,
27- } ;
28- await route . fulfill ( { json } ) ;
29- } ) ;
18+ await loginTest ( { page } ) ;
3019
31- await expect ( page ) . toHaveTitle ( / O S 2 D i s p l a y A d m i n / ) ;
32- await page . getByLabel ( "Email" ) . fill ( "johndoe@example.com" ) ;
33- await page . getByLabel ( "Kodeord" ) . fill ( "password" ) ;
34- await page . locator ( "#login" ) . click ( ) ;
35- await expect ( page . locator ( "h1" ) . getByText ( "Opret ny gruppe" ) ) . toBeVisible ( ) ;
20+ await fulfillEmptyRoutes ( page , [ "**/screen-groups*" ] ) ;
21+
22+ await page . getByRole ( "link" , { name : "Grupper" , exact : true } ) . click ( ) ;
23+ await expect ( page . getByRole ( "heading" , { name : "Grupper" , exact : true } ) ) . toBeVisible ( ) ;
24+ await page . getByRole ( "button" , { name : "Opret ny gruppe" , exact : true } ) . click ( ) ;
25+ await expect ( page . getByRole ( "heading" , { name : "Opret ny gruppe" , exact : true } ) ) . toBeVisible ( ) ;
3626 } ) ;
3727
3828 test ( "It loads create group page" , async ( { page } ) => {
3929 await expect ( page . locator ( "#save_group" ) ) . toBeVisible ( ) ;
4030 } ) ;
4131
4232 test ( "It redirects on save" , async ( { page } ) => {
43- await page . route ( "**/screen-groups" , async ( route ) => {
44- const json = {
45- title : "A laudantium aspernatur qui." ,
46- description : "Description" ,
47- created : "1991-09-10T22:36:56+02:00" ,
48- modified : "2021-12-09T12:01:33+01:00" ,
49- modifiedBy : "" ,
50- createdBy : "" ,
51- } ;
52- await route . fulfill ( { json } ) ;
53- } ) ;
33+ await fulfillDataRoute ( page , "**/screen-groups" , onSaveJson ) ;
5434
5535 // Displays success toast and redirects
5636 await expect (
@@ -74,15 +54,8 @@ test.describe("Create group page works", () => {
7454 } ) ;
7555
7656 test ( "It display error toast on save error" , async ( { page } ) => {
77- await page . route ( "**/screen-groups" , async ( route ) => {
78- const json = {
79- "@context" : "/contexts/Error" ,
80- "@type" : "hydra:Error" ,
81- "hydra:title" : "An error occurred" ,
82- "hydra:description" : "An error occurred" ,
83- } ;
84- await route . fulfill ( { status : 500 , json } ) ;
85- } ) ;
57+ await fulfillDataRoute ( page , "**/screen-groups" , errorJson , 500 ) ;
58+
8659 // Displays error toast and stays on page
8760 await expect (
8861 page . locator ( ".Toastify" ) . locator ( ".Toastify__toast--error" ) ,
@@ -97,152 +70,17 @@ test.describe("Create group page works", () => {
9770
9871test . describe ( "Groups list works" , ( ) => {
9972 test . beforeEach ( async ( { page } ) => {
100- await page . goto ( "/admin/group/list" ) ;
101- await page . route ( "**/token" , async ( route ) => {
102- const json = {
103- token : "1" ,
104- refresh_token : "2" ,
105- tenants : [
106- {
107- tenantKey : "ABC" ,
108- title : "ABC Tenant" ,
109- description : "Description" ,
110- roles : [ "ROLE_ADMIN" ] ,
111- } ,
112- ] ,
113- user : {
114- fullname : "John Doe" ,
115- email : "johndoe@example.com" ,
116- } ,
117- } ;
118- await route . fulfill ( { json } ) ;
119- } ) ;
73+ await beforeEachTest ( page ) ;
74+ } ) ;
12075
121- await page . route ( "**/screen-groups*" , async ( route ) => {
122- const json = {
123- "@id" : "/v2/screen-groups" ,
124- "hydra:member" : [
125- {
126- "@type" : "ScreenGroup" ,
127- "@id" : "/v2/screen-groups/000RAH746Q1AD8011Z1JNV06N3" ,
128- title : "Cupiditate et quidem autem iusto." ,
129- description :
130- "Eos quibusdam consectetur nisi consequatur voluptas. Unde maxime sunt quidem magnam. Sed ipsa voluptas qui occaecati ea nobis." ,
131- created : "1970-10-30T08:30:07+01:00" ,
132- modified : "2021-12-09T12:01:33+01:00" ,
133- modifiedBy : "" ,
134- createdBy : "" ,
135- } ,
136- {
137- "@type" : "ScreenGroup" ,
138- "@id" : "/v2/screen-groups/0012G98YZS0VTK0Z2T02AD1DC3" ,
139- title : "Dignissimos nihil non sit laudantium." ,
140- description :
141- "Maxime dicta magnam est voluptas voluptas. Est omnis expedita harum reprehenderit debitis laboriosam ab omnis. Sed temporibus iste voluptatibus ut qui est non voluptatem." ,
142- created : "1971-03-05T20:43:43+01:00" ,
143- modified : "2021-12-09T12:01:33+01:00" ,
144- modifiedBy : "" ,
145- createdBy : "" ,
146- } ,
147- {
148- "@type" : "ScreenGroup" ,
149- "@id" : "/v2/screen-groups/001EZQXKKR0P7X0A3119Z016SB" ,
150- title : "Aut nam accusantium id aut." ,
151- description :
152- "Et est nisi autem nihil. Blanditiis facere repellat et. Est et architecto modi laboriosam corporis et." ,
153- created : "1971-08-07T23:56:38+01:00" ,
154- modified : "2021-12-09T12:01:33+01:00" ,
155- modifiedBy : "" ,
156- createdBy : "" ,
157- } ,
158- {
159- "@type" : "ScreenGroup" ,
160- "@id" : "/v2/screen-groups/003J350X2D060H00TE1DW50640" ,
161- title : "Velit rem commodi necessitatibus eos." ,
162- description :
163- "Non sequi sed fugit. Nihil cumque nesciunt hic recusandae rem suscipit sunt. Nostrum voluptatem ut consequatur non illum." ,
164- created : "1973-11-18T23:15:03+01:00" ,
165- modified : "2021-12-09T12:01:33+01:00" ,
166- modifiedBy : "" ,
167- createdBy : "" ,
168- } ,
169- {
170- "@type" : "ScreenGroup" ,
171- "@id" : "/v2/screen-groups/003Z784JQS1PNS1RX1003N0NCD" ,
172- title : "Quod esse voluptas ut." ,
173- description :
174- "Deleniti velit est quasi commodi alias est minima. Harum iusto odio aperiam consequatur qui est. Vel ut id aperiam nobis fugiat et modi. Est dolores rerum id sed excepturi et." ,
175- created : "1974-05-01T02:50:31+01:00" ,
176- modified : "2021-12-09T12:01:33+01:00" ,
177- modifiedBy : "" ,
178- createdBy : "" ,
179- } ,
180- {
181- "@type" : "ScreenGroup" ,
182- "@id" : "/v2/screen-groups/009YS5ZYPH1B9T0JE01S290T5Y" ,
183- title : "Tenetur voluptatem quo rerum exercitationem." ,
184- description :
185- "Suscipit provident odit in eius sed voluptatibus. Neque aut corporis aspernatur quo qui. Inventore nam est sed sed maiores odio." ,
186- created : "1980-11-05T17:57:30+01:00" ,
187- modified : "2021-12-09T12:01:33+01:00" ,
188- modifiedBy : "" ,
189- createdBy : "" ,
190- } ,
191- {
192- "@type" : "ScreenGroup" ,
193- "@id" : "/v2/screen-groups/00C1V2MX2S02N30EXM163A0E6X" ,
194- title : "Distinctio quisquam et totam molestias." ,
195- description :
196- "Ad ipsam architecto eum repellat excepturi. Quos deleniti itaque ut reprehenderit aut rerum autem. Nihil et mollitia voluptatibus quis voluptatem. Ex eaque sint nostrum impedit." ,
197- created : "1983-02-17T02:51:45+01:00" ,
198- modified : "2021-12-09T12:01:33+01:00" ,
199- modifiedBy : "" ,
200- createdBy : "" ,
201- } ,
202- {
203- "@type" : "ScreenGroup" ,
204- "@id" : "/v2/screen-groups/00DDTCJCDX0H101N480E180K4B" ,
205- title : "Cumque facere nulla reiciendis." ,
206- description :
207- "Veritatis doloremque delectus voluptas numquam dolores nobis. Dignissimos quo facere eum iure." ,
208- created : "1984-08-16T16:14:03+02:00" ,
209- modified : "2021-12-09T12:01:33+01:00" ,
210- modifiedBy : "" ,
211- createdBy : "" ,
212- } ,
213- {
214- "@type" : "ScreenGroup" ,
215- "@id" : "/v2/screen-groups/00GEPM6JRX0V2P0YST0JHA03CC" ,
216- title : "Ea aspernatur odit rerum." ,
217- description :
218- "Adipisci tenetur placeat perspiciatis assumenda. Voluptas officiis magnam reprehenderit possimus non. Tempore delectus numquam veritatis harum natus." ,
219- created : "1987-12-03T16:33:04+01:00" ,
220- modified : "2021-12-09T12:01:33+01:00" ,
221- modifiedBy : "" ,
222- createdBy : "" ,
223- } ,
224- {
225- "@type" : "ScreenGroup" ,
226- "@id" : "/v2/screen-groups/00KXGYAJ4A1D5P0EA11SKF0BG8" ,
227- title : "A laudantium aspernatur qui." ,
228- description :
229- "Non fugiat nobis occaecati. Sed ut velit beatae amet ea esse. Quo dolorem commodi magni at. Illum voluptatem neque nobis et ut. Ad rerum tempore vel commodi suscipit corrupti." ,
230- created : "1991-09-10T22:36:56+02:00" ,
231- modified : "2021-12-09T12:01:33+01:00" ,
232- modifiedBy : "" ,
233- createdBy : "" ,
234- } ,
235- ] ,
236- "hydra:totalItems" : 20 ,
237- } ;
76+ test . beforeEach ( async ( { page } ) => {
77+ await loginTest ( { page } ) ;
23878
239- await route . fulfill ( { json } ) ;
240- } ) ;
79+ await fulfillEmptyRoutes ( page , [ '**/screens*' ] ) ;
80+ await fulfillDataRoute ( page , "**/screen-groups*" , screenGroupsListJson ) ;
24181
242- await expect ( page ) . toHaveTitle ( / O S 2 D i s p l a y A d m i n / ) ;
243- await page . getByLabel ( "Email" ) . fill ( "johndoe@example.com" ) ;
244- await page . getByLabel ( "Kodeord" ) . fill ( "password" ) ;
245- await page . locator ( "#login" ) . click ( ) ;
82+ await page . getByRole ( "link" , { name : "Grupper" , exact : true } ) . click ( ) ;
83+ await expect ( page . getByRole ( "heading" , { name : "Grupper" , exact : true } ) ) . toBeVisible ( ) ;
24684 } ) ;
24785
24886 test ( "It loads groups list" , async ( { page } ) => {
@@ -251,19 +89,7 @@ test.describe("Groups list works", () => {
25189 } ) ;
25290
25391 test ( "It goes to edit (groups list)" , async ( { page } ) => {
254- await page . route ( "**/screen-groups/*" , async ( route ) => {
255- const json = {
256- "@id" : "/v2/screen-groups/00GEPM6JRX0V2P0YST0JHA03CC" ,
257- title : "Ea aspernatur odit rerum." ,
258- description :
259- "Adipisci tenetur placeat perspiciatis assumenda. Voluptas officiis magnam reprehenderit possimus non. Tempore delectus numquam veritatis harum natus." ,
260- created : "1987-12-03T16:33:04+01:00" ,
261- modified : "2021-12-09T12:01:33+01:00" ,
262- modifiedBy : "" ,
263- createdBy : "" ,
264- } ;
265- await route . fulfill ( { json } ) ;
266- } ) ;
92+ await fulfillDataRoute ( page , "**/screen-groups/000RAH746Q1AD8011Z1JNV06N3" , screenGroupsSingleJson ) ;
26793
26894 await expect ( page . locator ( "#groupTitle" ) ) . not . toBeVisible ( ) ;
26995 await page . locator ( "tbody" ) . locator ( "tr td a" ) . nth ( 0 ) . click ( ) ;
@@ -284,11 +110,11 @@ test.describe("Groups list works", () => {
284110
285111 test ( "It removes all selected" , async ( { page } ) => {
286112 await page . locator ( "tbody" ) . locator ( "tr td input" ) . nth ( 0 ) . click ( ) ;
287- expect (
113+ await expect (
288114 page . locator ( "tbody" ) . locator ( "tr" ) . nth ( 0 ) . getByRole ( "checkbox" ) ,
289115 ) . toBeChecked ( ) ;
290116 await page . locator ( "#clear-rows-button" ) . click ( ) ;
291- expect (
117+ await expect (
292118 page . locator ( "tbody" ) . locator ( "tr" ) . nth ( 0 ) . getByRole ( "checkbox" ) ,
293119 ) . not . toBeChecked ( ) ;
294120 } ) ;
0 commit comments