11import { expect , test } from "@playwright/test" ;
2- import { v4 as uuidv4 } from "uuid" ;
3- import adminClient from "../utils/AdminClient.ts" ;
2+ import { toClientScopes } from "../../src/client-scopes/routes/ClientScopes.tsx" ;
3+ import { toNewClientScope } from "../../src/client-scopes/routes/NewClientScope.tsx" ;
4+ import { createTestBed } from "../support/testbed.ts" ;
45import { assertSaveButtonIsDisabled , clickSaveButton } from "../utils/form.ts" ;
5- import { login } from "../utils/login.ts" ;
6+ import { login , navigateTo } from "../utils/login.ts" ;
67import { assertNotificationMessage } from "../utils/masthead.ts" ;
78import { confirmModal } from "../utils/modal.ts" ;
8- import { goToClientScopes } from "../utils/sidebar.ts" ;
99import {
1010 assertRowExists ,
1111 assertTableRowsLength ,
@@ -21,7 +21,6 @@ import {
2121 fillClientScopeData ,
2222 getTableAssignedTypeColumn ,
2323 getTableProtocolColumn ,
24- goToCreateItem ,
2524 selectChangeType ,
2625 selectClientScopeFilter ,
2726 selectSecondaryFilterAssignedType ,
@@ -42,193 +41,178 @@ const FilterProtocol = {
4241 OpenID : "OpenID Connect" ,
4342} ;
4443
45- test . describe . serial ( "Client Scopes test" , ( ) => {
46- const clientScopeName = "client-scope-test" ;
47- const itemId = `client-scope-test-${ uuidv4 ( ) } ` ;
48- const clientScope = {
49- name : clientScopeName ,
50- description : "" ,
51- protocol : "openid-connect" ,
52- attributes : {
53- "include.in.token.scope" : "true" ,
54- "display.on.consent.screen" : "true" ,
55- "gui.order" : "1" ,
56- "consent.screen.text" : "" ,
57- } ,
58- } ;
59- const placeHolder = "Search for client scope" ;
60- const tableName = "Client scopes" ;
61-
62- test . beforeAll ( async ( ) => {
63- for ( let i = 0 ; i < 5 ; i ++ ) {
64- clientScope . name = clientScopeName + i ;
65- await adminClient . createClientScope ( clientScope ) ;
66- }
44+ const placeHolder = "Search for client scope" ;
45+ const tableName = "Client scopes" ;
46+
47+ test . describe ( "Client scopes filtering" , ( ) => {
48+ test ( "filters item by name" , async ( { page } ) => {
49+ await using testBed = await createTestBed ( {
50+ clientScopes : [ { name : "test-scope" } ] ,
51+ } ) ;
52+
53+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
54+
55+ await searchItem ( page , placeHolder , "test-scope" ) ;
56+ await assertRowExists ( page , "test-scope" ) ;
57+ await assertTableRowsLength ( page , tableName , 1 ) ;
6758 } ) ;
6859
69- test . afterAll ( async ( ) => {
70- for ( let i = 0 ; i < 5 ; i ++ ) {
71- if ( await adminClient . existsClientScope ( clientScopeName + i ) ) {
72- await adminClient . deleteClientScope ( clientScopeName + i ) ;
73- }
74- }
60+ test ( "filters items by assigned type 'default'" , async ( { page } ) => {
61+ await using testBed = await createTestBed ( ) ;
62+
63+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
64+
65+ await selectClientScopeFilter ( page , "Assigned type" ) ;
66+ await selectSecondaryFilterAssignedType ( page , FilterAssignedType . Default ) ;
67+
68+ const assignedTypes = await getTableAssignedTypeColumn ( page , tableName ) ;
69+
70+ expect ( assignedTypes ) . toContain ( FilterAssignedType . Default ) ;
71+ expect ( assignedTypes ) . not . toContain ( FilterAssignedType . Optional ) ;
72+ expect ( assignedTypes ) . not . toContain ( FilterAssignedType . None ) ;
7573 } ) ;
7674
77- test . describe . serial ( "Client Scope filter list items" , ( ) => {
78- test . beforeEach ( async ( { page } ) => {
79- await login ( page ) ;
80- await goToClientScopes ( page ) ;
81- } ) ;
75+ test ( "filters items by assigned type 'optional'" , async ( { page } ) => {
76+ await using testBed = await createTestBed ( ) ;
8277
83- test ( "should filter item by name" , async ( { page } ) => {
84- const itemName = clientScopeName + "0" ;
85- await searchItem ( page , placeHolder , itemName ) ;
86- await assertRowExists ( page , itemName ) ;
87- await assertTableRowsLength ( page , tableName , 1 ) ;
88- } ) ;
78+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
8979
90- test ( "should filter items by Assigned type Default" , async ( { page } ) => {
91- await selectClientScopeFilter ( page , "Assigned type" ) ;
92- await selectSecondaryFilterAssignedType ( page , FilterAssignedType . Default ) ;
80+ await selectClientScopeFilter ( page , "Assigned type" ) ;
81+ await selectSecondaryFilterAssignedType ( page , FilterAssignedType . Optional ) ;
9382
94- const assignedTypes = await getTableAssignedTypeColumn ( page , tableName ) ;
83+ const assignedTypes = await getTableAssignedTypeColumn ( page , tableName ) ;
9584
96- expect ( assignedTypes ) . toContain ( FilterAssignedType . Default ) ;
97- expect ( assignedTypes ) . not . toContain ( FilterAssignedType . Optional ) ;
98- expect ( assignedTypes ) . not . toContain ( FilterAssignedType . None ) ;
99- } ) ;
85+ expect ( assignedTypes ) . not . toContain ( FilterAssignedType . Default ) ;
86+ expect ( assignedTypes ) . not . toContain ( FilterAssignedType . None ) ;
87+ expect ( assignedTypes ) . toContain ( FilterAssignedType . Optional ) ;
88+ } ) ;
10089
101- test ( "should filter items by Assigned type Optional" , async ( { page } ) => {
102- await selectClientScopeFilter ( page , "Assigned type" ) ;
103- await selectSecondaryFilterAssignedType (
104- page ,
105- FilterAssignedType . Optional ,
106- ) ;
90+ test ( "filters items by assigned type 'all'" , async ( { page } ) => {
91+ await using testBed = await createTestBed ( ) ;
10792
108- const assignedTypes = await getTableAssignedTypeColumn ( page , tableName ) ;
93+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
10994
110- expect ( assignedTypes ) . not . toContain ( FilterAssignedType . Default ) ;
111- expect ( assignedTypes ) . not . toContain ( FilterAssignedType . None ) ;
112- expect ( assignedTypes ) . toContain ( FilterAssignedType . Optional ) ;
113- } ) ;
95+ await selectClientScopeFilter ( page , "Assigned type" ) ;
96+ await selectSecondaryFilterAssignedType ( page , FilterAssignedType . AllTypes ) ;
11497
115- test ( "should filter items by Assigned type All" , async ( { page } ) => {
116- await selectClientScopeFilter ( page , "Assigned type" ) ;
117- await selectSecondaryFilterAssignedType (
118- page ,
119- FilterAssignedType . AllTypes ,
120- ) ;
98+ const assignedTypes = await getTableAssignedTypeColumn ( page , tableName ) ;
12199
122- const assignedTypes = await getTableAssignedTypeColumn ( page , tableName ) ;
100+ expect ( assignedTypes ) . toContain ( FilterAssignedType . Default ) ;
101+ expect ( assignedTypes ) . toContain ( FilterAssignedType . Optional ) ;
102+ } ) ;
123103
124- expect ( assignedTypes ) . toContain ( FilterAssignedType . Default ) ;
125- expect ( assignedTypes ) . toContain ( FilterAssignedType . Optional ) ;
126- expect ( assignedTypes ) . toContain ( FilterAssignedType . None ) ;
127- } ) ;
104+ test ( "filters items by protocol 'openid'" , async ( { page } ) => {
105+ await using testBed = await createTestBed ( ) ;
128106
129- test ( "should filter items by Protocol OpenID" , async ( { page } ) => {
130- await selectClientScopeFilter ( page , "Protocol" ) ;
131- await selectSecondaryFilterProtocol ( page , FilterProtocol . OpenID ) ;
107+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
132108
133- const protocols = await getTableProtocolColumn ( page , tableName ) ;
109+ await selectClientScopeFilter ( page , "Protocol" ) ;
110+ await selectSecondaryFilterProtocol ( page , FilterProtocol . OpenID ) ;
134111
135- expect ( protocols ) . not . toContain ( FilterProtocol . SAML ) ;
136- expect ( protocols ) . toContain ( FilterProtocol . OpenID ) ;
137- } ) ;
112+ const protocols = await getTableProtocolColumn ( page , tableName ) ;
138113
139- test ( "should filter items by Protocol SAML" , async ( { page } ) => {
140- await selectClientScopeFilter ( page , "Protocol" ) ;
141- await selectSecondaryFilterProtocol ( page , FilterProtocol . SAML ) ;
114+ expect ( protocols ) . not . toContain ( FilterProtocol . SAML ) ;
115+ expect ( protocols ) . toContain ( FilterProtocol . OpenID ) ;
116+ } ) ;
142117
143- const protocols = await getTableProtocolColumn ( page , tableName ) ;
118+ test ( "filters items by protocol 'saml'" , async ( { page } ) => {
119+ await using testBed = await createTestBed ( ) ;
144120
145- expect ( protocols ) . toContain ( FilterProtocol . SAML ) ;
146- expect ( protocols ) . not . toContain ( FilterProtocol . OpenID ) ;
147- } ) ;
121+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
148122
149- test ( "should show items on next page are more than 11" , async ( {
150- page,
151- } ) => {
152- await clickNextPageButton ( page ) ;
153- const rows = await getTableData ( page , tableName ) ;
154- expect ( rows . length ) . toBeGreaterThan ( 1 ) ;
155- } ) ;
123+ await selectClientScopeFilter ( page , "Protocol" ) ;
124+ await selectSecondaryFilterProtocol ( page , FilterProtocol . SAML ) ;
125+
126+ const protocols = await getTableProtocolColumn ( page , tableName ) ;
127+
128+ expect ( protocols ) . toContain ( FilterProtocol . SAML ) ;
129+ expect ( protocols ) . not . toContain ( FilterProtocol . OpenID ) ;
156130 } ) ;
157131
158- test . describe . serial ( "Client Scope modify list items" , ( ) => {
159- test . beforeEach ( async ( { page } ) => {
160- await login ( page ) ;
161- await goToClientScopes ( page ) ;
162- } ) ;
132+ test ( "shows items on next page are more than 11" , async ( { page } ) => {
133+ await using testBed = await createTestBed ( ) ;
163134
164- test ( "should modify selected item type to Default" , async ( { page } ) => {
165- const itemName = clientScopeName + "0" ;
166- await clickSelectRow ( page , tableName , itemName ) ;
167- await selectChangeType ( page , FilterAssignedType . Default ) ;
168- await assertNotificationMessage ( page , "Scope mapping updated" ) ;
135+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
169136
170- const rows = await getTableData ( page , tableName ) ;
171- const itemRow = rows . find ( ( r ) => r . includes ( itemName ) ) ;
172- expect ( itemRow ) . toContain ( FilterAssignedType . Default ) ;
173- } ) ;
137+ await clickNextPageButton ( page ) ;
138+ const rows = await getTableData ( page , tableName ) ;
139+ expect ( rows . length ) . toBeGreaterThan ( 1 ) ;
174140 } ) ;
141+ } ) ;
175142
176- test . describe . serial ( "Client Scope creation " , ( ) => {
177- test . beforeEach ( async ( { page } ) => {
178- await login ( page ) ;
179- await goToClientScopes ( page ) ;
143+ test . describe ( "Client scopes modification " , ( ) => {
144+ test ( "modifies selected item type to 'default'" , async ( { page } ) => {
145+ await using testBed = await createTestBed ( {
146+ clientScopes : [ { name : "test-scope" } ] ,
180147 } ) ;
181148
182- test ( "should fail creating client scope" , async ( { page } ) => {
183- await goToCreateItem ( page ) ;
184- await assertSaveButtonIsDisabled ( page ) ;
149+ await login ( page , { to : toClientScopes ( { realm : testBed . realm } ) } ) ;
185150
186- await fillClientScopeData ( page , "address" ) ;
187- await page . getByTestId ( "save" ) . click ( ) ;
151+ await clickSelectRow ( page , tableName , "test-scope" ) ;
152+ await selectChangeType ( page , FilterAssignedType . Default ) ;
153+ await assertNotificationMessage ( page , "Scope mapping updated" ) ;
188154
189- await assertNotificationMessage (
190- page ,
191- "Could not create client scope: 'Client Scope address already exists'" ,
192- ) ;
155+ const rows = await getTableData ( page , tableName ) ;
156+ const itemRow = rows . find ( ( r ) => r . includes ( "test-scope" ) ) ;
157+ expect ( itemRow ) . toContain ( FilterAssignedType . Default ) ;
158+ } ) ;
159+ } ) ;
193160
194- await fillClientScopeData ( page , "" ) ;
195- await expect ( page . getByTestId ( "save" ) ) . toBeDisabled ( ) ;
196- } ) ;
161+ test . describe ( "Client scopes creation" , ( ) => {
162+ test ( "fails creating client scope with an existing name" , async ( {
163+ page,
164+ } ) => {
165+ await using testBed = await createTestBed ( ) ;
166+
167+ await login ( page , { to : toNewClientScope ( { realm : testBed . realm } ) } ) ;
197168
198- test ( "hides 'consent text' field when 'display consent' switch is disabled" , async ( {
169+ await assertSaveButtonIsDisabled ( page ) ;
170+
171+ await fillClientScopeData ( page , "address" ) ;
172+ await page . getByTestId ( "save" ) . click ( ) ;
173+
174+ await assertNotificationMessage (
199175 page ,
200- } ) => {
201- await goToCreateItem ( page ) ;
176+ "Could not create client scope: 'Client Scope address already exists'" ,
177+ ) ;
202178
203- await assertSwitchDisplayOnConsentScreenIsChecked ( page ) ;
204- await assertConsentInputIsVisible ( page ) ;
179+ await fillClientScopeData ( page , "" ) ;
180+ await expect ( page . getByTestId ( "save" ) ) . toBeDisabled ( ) ;
181+ } ) ;
205182
206- await switchOffDisplayOnConsentScreen ( page ) ;
183+ test ( "hides 'consent text' field when 'display consent' switch is disabled" , async ( {
184+ page,
185+ } ) => {
186+ await using testBed = await createTestBed ( ) ;
207187
208- await assertConsentInputIsVisible ( page , true ) ;
209- } ) ;
188+ await login ( page , { to : toNewClientScope ( { realm : testBed . realm } ) } ) ;
210189
211- test ( "Client scope CRUD test" , async ( { page } ) => {
212- await assertRowExists ( page , itemId , false ) ;
213- await goToCreateItem ( page ) ;
190+ await assertSwitchDisplayOnConsentScreenIsChecked ( page ) ;
191+ await assertConsentInputIsVisible ( page ) ;
214192
215- await fillClientScopeData ( page , itemId ) ;
216- await clickSaveButton ( page ) ;
193+ await switchOffDisplayOnConsentScreen ( page ) ;
217194
218- await assertNotificationMessage ( page , "Client scope created" ) ;
195+ await assertConsentInputIsVisible ( page , true ) ;
196+ } ) ;
219197
220- await goToClientScopes ( page ) ;
198+ test ( "creates and deletes a client scope" , async ( { page } ) => {
199+ const itemId = "test-scope" ;
200+ await using testBed = await createTestBed ( ) ;
221201
222- await searchItem ( page , placeHolder , itemId ) ;
223- await assertRowExists ( page , itemId ) ;
224- await clickRowKebabItem ( page , itemId , "Delete" ) ;
202+ await login ( page , { to : toNewClientScope ( { realm : testBed . realm } ) } ) ;
203+ await fillClientScopeData ( page , itemId ) ;
204+ await clickSaveButton ( page ) ;
225205
226- await confirmModal ( page ) ;
227- await assertNotificationMessage (
228- page ,
229- "The client scope has been deleted" ,
230- ) ;
231- await assertRowExists ( page , itemId , false ) ;
232- } ) ;
206+ await assertNotificationMessage ( page , "Client scope created" ) ;
207+
208+ await navigateTo ( page , toClientScopes ( { realm : testBed . realm } ) ) ;
209+
210+ await searchItem ( page , placeHolder , itemId ) ;
211+ await assertRowExists ( page , itemId ) ;
212+ await clickRowKebabItem ( page , itemId , "Delete" ) ;
213+
214+ await confirmModal ( page ) ;
215+ await assertNotificationMessage ( page , "The client scope has been deleted" ) ;
216+ await assertRowExists ( page , itemId , false ) ;
233217 } ) ;
234218} ) ;
0 commit comments