-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2728 from pnaik1/userManagement
added user management cypress test
- Loading branch information
Showing
8 changed files
with
220 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GroupsConfig } from '~/pages/groupSettings/groupTypes'; | ||
|
||
export const mockGroupSettings = (): GroupsConfig => ({ | ||
adminGroups: [ | ||
{ | ||
id: 0, | ||
name: 'odh-admins', | ||
enabled: true, | ||
}, | ||
{ | ||
id: 1, | ||
name: 'odh-admins-1', | ||
enabled: false, | ||
}, | ||
], | ||
allowedGroups: [ | ||
{ | ||
id: 0, | ||
name: 'odh-admins', | ||
enabled: false, | ||
}, | ||
{ | ||
id: 1, | ||
name: 'odh-admins-1', | ||
enabled: false, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'system:authenticated', | ||
enabled: true, | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
frontend/src/__tests__/cypress/cypress/e2e/userManagement/userManagement.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { mockGroupSettings } from '~/__mocks__/mockGroupConfig'; | ||
import { userManagement } from '~/__tests__/cypress/cypress/pages/userManagement'; | ||
import { asProductAdminUser, asProjectAdminUser } from '~/__tests__/cypress/cypress/utils/users'; | ||
import { pageNotfound } from '~/__tests__/cypress/cypress/pages/pageNotFound'; | ||
|
||
it('Cluster settings should not be available for non product admins', () => { | ||
asProjectAdminUser(); | ||
userManagement.visit(false); | ||
pageNotfound.findPage().should('exist'); | ||
userManagement.findNavItem().should('not.exist'); | ||
}); | ||
|
||
describe('User Management', () => { | ||
beforeEach(() => { | ||
asProductAdminUser(); | ||
cy.interceptOdh('GET /api/groups-config', mockGroupSettings()); | ||
userManagement.visit(); | ||
}); | ||
|
||
it('Administrator group setting', () => { | ||
const administratorGroupSection = userManagement.getAdministratorGroupSection(); | ||
userManagement.findSubmitButton().should('be.disabled'); | ||
administratorGroupSection.findChipItem(/^odh-admins$/).should('exist'); | ||
administratorGroupSection.shouldHaveAdministratorGroupInfo(); | ||
administratorGroupSection.clearMultiChipItem(); | ||
administratorGroupSection.selectMultiGroup('odh-admins'); | ||
administratorGroupSection.findMultiGroupInput().type('odh-admin'); | ||
administratorGroupSection.findMultiGroupOptions('odh-admins-1').click(); | ||
administratorGroupSection.removeChipItem('odh-admins'); | ||
administratorGroupSection.findChipItem(/^odh-admins$/).should('not.exist'); | ||
administratorGroupSection.removeChipItem('odh-admins-1'); | ||
administratorGroupSection.findErrorText().should('exist'); | ||
administratorGroupSection.findMultiGroupOptions('odh-admins').click(); | ||
administratorGroupSection.findErrorText().should('not.exist'); | ||
userManagement.findSubmitButton().should('be.enabled'); | ||
}); | ||
|
||
it('User group setting', () => { | ||
const userGroupSection = userManagement.getUserGroupSection(); | ||
userManagement.findSubmitButton().should('be.disabled'); | ||
userGroupSection.findChipItem('system:authenticated').should('exist'); | ||
userGroupSection.clearMultiChipItem(); | ||
userGroupSection.findErrorText().should('exist'); | ||
userGroupSection.selectMultiGroup('odh-admins'); | ||
userGroupSection.findChipItem(/^odh-admins$/).should('exist'); | ||
userGroupSection.findMultiGroupSelectButton().click(); | ||
userManagement.findSubmitButton().should('be.enabled'); | ||
|
||
cy.interceptOdh('PUT /api/groups-config', mockGroupSettings()).as('saveGroupSetting'); | ||
|
||
userManagement.findSubmitButton().click(); | ||
cy.wait('@saveGroupSetting').then((interception) => { | ||
expect(interception.request.body).to.eql({ | ||
adminGroups: [ | ||
{ id: 0, name: 'odh-admins', enabled: true }, | ||
{ id: 1, name: 'odh-admins-1', enabled: false }, | ||
], | ||
allowedGroups: [ | ||
{ id: 0, name: 'odh-admins', enabled: true }, | ||
{ id: 1, name: 'odh-admins-1', enabled: false }, | ||
{ id: 2, name: 'system:authenticated', enabled: false }, | ||
], | ||
}); | ||
}); | ||
userManagement.shouldHaveSuccessAlertMessage(); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
frontend/src/__tests__/cypress/cypress/pages/userManagement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { appChrome } from './appChrome'; | ||
import { Contextual } from './components/Contextual'; | ||
|
||
class GroupSettingSection extends Contextual<HTMLElement> { | ||
shouldHaveAdministratorGroupInfo() { | ||
this.find().findByTestId('data-science-administrator-info'); | ||
return this; | ||
} | ||
|
||
clearMultiChipItem() { | ||
this.find().findByRole('button', { name: 'Clear all' }).click(); | ||
} | ||
|
||
findMultiGroupInput() { | ||
return this.find().find('input'); | ||
} | ||
|
||
findMultiGroupOptions(name: string) { | ||
return this.find().findByTestId('multi-group-selection').findByRole('option', { name }); | ||
} | ||
|
||
private findChipGroup() { | ||
return this.find().findByRole('list', { name: 'Chip group category' }); | ||
} | ||
|
||
findChipItem(name: string | RegExp) { | ||
return this.findChipGroup().find('li').contains('span', name); | ||
} | ||
|
||
removeChipItem(name: string) { | ||
this.findChipGroup() | ||
.findByRole('button', { name: `Remove ${name}` }) | ||
.click(); | ||
} | ||
|
||
findErrorText() { | ||
return this.find().findByTestId('group-selection-error-text'); | ||
} | ||
|
||
findMultiGroupSelectButton() { | ||
return this.find().findByRole('button', { name: 'Options menu' }); | ||
} | ||
|
||
selectMultiGroup(name: string) { | ||
this.findMultiGroupSelectButton().click(); | ||
this.findMultiGroupOptions(name).click(); | ||
} | ||
} | ||
class UserManagement { | ||
visit(wait = true) { | ||
cy.visit('/groupSettings'); | ||
if (wait) { | ||
this.wait(); | ||
} | ||
} | ||
|
||
private wait() { | ||
cy.findByTestId('app-page-title').should('have.text', 'User management'); | ||
cy.testA11y(); | ||
} | ||
|
||
navigate() { | ||
this.findNavItem().click(); | ||
this.wait(); | ||
} | ||
|
||
findNavItem() { | ||
return appChrome.findNavItem('User management', 'Settings'); | ||
} | ||
|
||
findSubmitButton() { | ||
return cy.findByTestId('save-button'); | ||
} | ||
|
||
shouldHaveSuccessAlertMessage() { | ||
cy.findByRole('heading', { name: 'Success alert: Group settings changes saved' }).should( | ||
'exist', | ||
); | ||
return this; | ||
} | ||
|
||
getAdministratorGroupSection() { | ||
return new GroupSettingSection(() => cy.findByTestId('data-science-administrator-groups')); | ||
} | ||
|
||
getUserGroupSection() { | ||
return new GroupSettingSection(() => cy.findByTestId('data-science-user-groups')); | ||
} | ||
} | ||
|
||
export const userManagement = new UserManagement(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters