@@ -43,21 +43,17 @@ test.describe("Permission table", () => {
4343
4444 // The new subject only should have the read permission
4545 // We uncheck it to remove the subject so we are back to the previous state
46- await subjectEditorDrawer . getByLabel ( 'Read' ) . uncheck ( ) ;
46+ await expect ( subjectEditorDrawer . getByLabel ( 'Read' ) ) . toBeChecked ( ) ;
4747 await expect ( subjectEditorDrawer . getByLabel ( 'Write' ) ) . not . toBeChecked ( ) ;
4848 await expect ( subjectEditorDrawer . getByLabel ( 'Append' ) ) . not . toBeChecked ( ) ;
4949 await expect ( subjectEditorDrawer . getByLabel ( 'Control' ) ) . not . toBeChecked ( ) ;
5050
51- // Wait until the operation is finished
52- await expect ( subjectEditorDrawer . getByLabel ( 'Read' ) ) . toBeEnabled ( ) ;
53-
5451 await subjectEditorDrawer . locator ( "button.p-drawer-close-button" ) . click ( ) ;
5552 await expect ( subjectEditorDrawer ) . toBeHidden ( ) ;
5653
57- // Check if the table is updated & close the drawer
58- await expect ( tableDrawer . locator ( "tbody" ) . getByRole ( "row" ) ) . toHaveCount ( 2 ) ;
54+ // Use delete button to remove entry
55+ await newSubjectRow . getByRole ( "button" , { name : "Delete" } ) . click ( ) ;
5956 await tableDrawer . locator ( "button.p-drawer-close-button" ) . click ( ) ;
60- await expect ( tableDrawer ) . toBeHidden ( ) ;
6157
6258 // Check if the right side panel has the 2 subjects
6359 await expect ( startAgentPanelList . getByRole ( "listitem" ) ) . toHaveCount ( 2 ) ;
@@ -189,5 +185,105 @@ test.describe("Permission table", () => {
189185 await expect ( writePermCheckbox ) . toBeEnabled ( ) ;
190186 await writePermCheckbox . uncheck ( ) ;
191187 await expect ( writePermCheckbox ) . toBeEnabled ( ) ;
188+ } ) ;
189+
190+ test ( "Disabling permissions remove access" , async ( { page, browser } ) => {
191+ await page . getByText ( "README" ) . click ( ) ;
192+
193+ // Check if right panel is loaded
194+ const rightPanelElem = page . locator ( ".right-panel" ) ;
195+ const listHeader = rightPanelElem . locator ( ".list-header" ) ;
196+ await expect ( listHeader ) . toContainText ( "Subjects with permissions" )
197+
198+ await rightPanelElem . getByRole ( "button" , { name : "Edit" } ) . click ( ) ;
199+
200+ const tableDrawer = page . locator ( ".permission-drawer" ) ;
201+ const publicSubjectRow = tableDrawer . locator ( "tr" , { hasText : "Public" } ) ;
202+ await expect ( publicSubjectRow ) . toBeVisible ( ) ;
203+
204+ const accessSwitch = publicSubjectRow . getByRole ( "switch" ) ;
205+ await accessSwitch . uncheck ( ) ;
206+ await expect ( accessSwitch ) . not . toBeChecked ( ) ;
207+
208+ const podPage = await browser . newPage ( ) ;
209+ // Disable caching
210+ await podPage . route ( "**/pod1/README" , ( route ) => route . continue ( ) ) ;
211+ await podPage . goto ( "http://localhost:8080/pod1/README" ) ;
212+ await expect ( podPage . getByText ( "Welcome to your pod" ) ) . toBeVisible ( ) ;
213+
214+ // Remove access
215+ await accessSwitch . check ( ) ;
216+ await expect ( accessSwitch ) . toBeEnabled ( ) ;
217+
218+ await podPage . reload ( ) ;
219+ await expect ( podPage . getByText ( "Not logged in" ) ) . toBeVisible ( ) ;
220+
221+ // Restore to default state
222+ await accessSwitch . check ( ) ;
223+ await expect ( accessSwitch ) . toBeEnabled ( ) ;
224+ } ) ;
225+
226+ test ( "Removing access keeps permissions on re-enabling of access" , async ( { page } ) => {
227+ await page . getByText ( "README" ) . click ( ) ;
228+
229+ // Check if right panel is loaded
230+ const rightPanelElem = page . locator ( ".right-panel" ) ;
231+ const listHeader = rightPanelElem . locator ( ".list-header" ) ;
232+ await expect ( listHeader ) . toContainText ( "Subjects with permissions" )
233+
234+ await rightPanelElem . getByRole ( "button" , { name : "Edit" } ) . click ( ) ;
235+
236+ const tableDrawer = page . locator ( ".permission-drawer" ) ;
237+ const publicSubjectRow = tableDrawer . locator ( "tr" , { hasText : "Public" } ) ;
238+ await expect ( publicSubjectRow ) . toBeVisible ( ) ;
239+
240+ // Open subject editor drawer & give write permissions
241+ await publicSubjectRow . getByRole ( "button" , { name : "Edit" } ) . click ( ) ;
242+ const subjectEditorDrawer = page . locator ( ".subject-drawer" ) ;
243+ await expect ( subjectEditorDrawer ) . toBeVisible ( )
244+ const writePermCheckbox = subjectEditorDrawer . getByLabel ( 'Write' )
245+ await expect ( writePermCheckbox ) . not . toBeChecked ( ) ;
246+ await writePermCheckbox . check ( ) ;
247+ await expect ( writePermCheckbox ) . toBeChecked ( ) ;
248+ await expect ( writePermCheckbox ) . toBeEnabled ( ) ;
249+
250+ // close subject editor drawer
251+ const subjectEditorCloseBtn = subjectEditorDrawer . locator ( "button.p-drawer-close-button" ) ;
252+ await subjectEditorCloseBtn . click ( ) ;
253+ await expect ( subjectEditorDrawer ) . toBeHidden ( ) ;
254+
255+ // Disable access
256+ const accessSwitch = publicSubjectRow . getByRole ( "switch" ) ;
257+ await accessSwitch . uncheck ( ) ;
258+ await expect ( accessSwitch ) . not . toBeChecked ( ) ;
259+
260+ // Force reload the permission table
261+ await publicSubjectRow . getByRole ( "button" , { name : "Edit" } ) . click ( ) ;
262+ await expect ( subjectEditorDrawer ) . toBeVisible ( )
263+ await subjectEditorCloseBtn . click ( ) ;
264+ await expect ( subjectEditorDrawer ) . toBeHidden ( ) ;
265+
266+ // Check if write permissions is checked in table
267+ await expect ( publicSubjectRow . locator ( 'td:nth-child(4) > .locheck' ) ) . toBeVisible ( ) ;
268+
269+ // Re-enable access
270+ await accessSwitch . check ( ) ;
271+ await expect ( accessSwitch ) . toBeChecked ( ) ;
272+
273+ // Restoring to default state
274+ await publicSubjectRow . getByRole ( "button" , { name : "Edit" } ) . click ( ) ;
275+ await expect ( subjectEditorDrawer ) . toBeVisible ( )
276+ await writePermCheckbox . uncheck ( ) ;
277+ await expect ( writePermCheckbox ) . not . toBeChecked ( ) ;
278+ await expect ( writePermCheckbox ) . toBeEnabled ( ) ;
279+
280+ await subjectEditorCloseBtn . click ( ) ;
281+ await expect ( subjectEditorDrawer ) . toBeHidden ( ) ;
282+
283+
284+ // Check if write permissions are removed from the table
285+ await expect ( publicSubjectRow . locator ( 'td:nth-child(4) > .locheck' ) ) . toBeHidden ( {
286+ timeout : 10000 ,
287+ } ) ;
192288 } )
193289} )
0 commit comments