2023-10-27 09:11:34 -04:00
|
|
|
import GroupMembers from '@/features/group-management/components/group-members'
|
|
|
|
import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
|
2023-11-09 11:26:46 -05:00
|
|
|
import { User } from '../../../../../types/group-management/user'
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
const GROUP_ID = '777fff777fff'
|
2023-11-09 11:26:46 -05:00
|
|
|
const JOHN_DOE: User = {
|
2023-06-30 04:30:20 -04:00
|
|
|
_id: 'abc123def456',
|
|
|
|
first_name: 'John',
|
|
|
|
last_name: 'Doe',
|
|
|
|
email: 'john.doe@test.com',
|
|
|
|
last_active_at: new Date('2023-01-15'),
|
|
|
|
invite: true,
|
|
|
|
}
|
2023-11-09 11:26:46 -05:00
|
|
|
const BOBBY_LAPOINTE: User = {
|
2023-06-30 04:30:20 -04:00
|
|
|
_id: 'bcd234efa567',
|
|
|
|
first_name: 'Bobby',
|
|
|
|
last_name: 'Lapointe',
|
|
|
|
email: 'bobby.lapointe@test.com',
|
|
|
|
last_active_at: new Date('2023-01-02'),
|
|
|
|
invite: false,
|
2023-11-09 11:26:46 -05:00
|
|
|
enrollment: {
|
|
|
|
sso: [
|
|
|
|
{
|
|
|
|
groupId: 'another',
|
|
|
|
linkedAt: new Date(),
|
|
|
|
primary: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-06-30 04:30:20 -04:00
|
|
|
}
|
2023-11-09 11:26:46 -05:00
|
|
|
const CLAIRE_JENNINGS: User = {
|
2023-06-30 04:30:20 -04:00
|
|
|
_id: 'defabc231453',
|
|
|
|
first_name: 'Claire',
|
|
|
|
last_name: 'Jennings',
|
|
|
|
email: 'claire.jennings@test.com',
|
|
|
|
last_active_at: new Date('2023-01-03'),
|
|
|
|
invite: false,
|
|
|
|
enrollment: {
|
|
|
|
managedBy: GROUP_ID,
|
|
|
|
enrolledAt: new Date('2023-01-03'),
|
2023-11-09 11:26:46 -05:00
|
|
|
sso: [
|
|
|
|
{
|
|
|
|
groupId: GROUP_ID,
|
|
|
|
linkedAt: new Date(),
|
|
|
|
primary: true,
|
|
|
|
},
|
|
|
|
],
|
2023-06-30 04:30:20 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
const PATHS = {
|
|
|
|
addMember: `/manage/groups/${GROUP_ID}/invites`,
|
|
|
|
removeMember: `/manage/groups/${GROUP_ID}/user`,
|
|
|
|
removeInvite: `/manage/groups/${GROUP_ID}/invites`,
|
|
|
|
exportMembers: `/manage/groups/${GROUP_ID}/members/export`,
|
|
|
|
}
|
|
|
|
|
2023-10-19 08:51:33 -04:00
|
|
|
function mountGroupMembersProvider() {
|
|
|
|
cy.mount(
|
|
|
|
<GroupMembersProvider>
|
|
|
|
<GroupMembers />
|
|
|
|
</GroupMembersProvider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-30 04:30:20 -04:00
|
|
|
describe('group members, with managed users', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map()
|
|
|
|
win.metaAttributesCache.set('ol-users', [
|
|
|
|
JOHN_DOE,
|
|
|
|
BOBBY_LAPOINTE,
|
|
|
|
CLAIRE_JENNINGS,
|
|
|
|
])
|
|
|
|
win.metaAttributesCache.set('ol-groupId', GROUP_ID)
|
|
|
|
win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
|
|
|
|
win.metaAttributesCache.set('ol-groupSize', 10)
|
|
|
|
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
|
|
|
})
|
2023-10-19 08:51:33 -04:00
|
|
|
mountGroupMembersProvider()
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the group members page', function () {
|
|
|
|
cy.get('h1').contains('My Awesome Team')
|
|
|
|
cy.get('small').contains('You have added 3 of 10 available members')
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(1)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.contains('john.doe@test.com')
|
|
|
|
cy.contains('John Doe')
|
|
|
|
cy.contains('15th Jan 2023')
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('.sr-only').contains('Pending invite')
|
2023-06-30 04:30:20 -04:00
|
|
|
|
2024-04-19 08:30:23 -04:00
|
|
|
cy.findByTestId('badge-pending-invite').should(
|
|
|
|
'have.text',
|
|
|
|
'Pending invite'
|
|
|
|
)
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get(`.security-state-invite-pending`).should('exist')
|
|
|
|
})
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('tr:nth-child(2)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.contains('bobby.lapointe@test.com')
|
|
|
|
cy.contains('Bobby Lapointe')
|
|
|
|
cy.contains('2nd Jan 2023')
|
2024-04-19 08:30:23 -04:00
|
|
|
cy.findByTestId('badge-pending-invite').should('not.exist')
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('.sr-only').contains('Not managed')
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('tr:nth-child(3)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.contains('claire.jennings@test.com')
|
|
|
|
cy.contains('Claire Jennings')
|
|
|
|
cy.contains('3rd Jan 2023')
|
2024-04-19 08:30:23 -04:00
|
|
|
cy.findByTestId('badge-pending-invite').should('not.exist')
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('.sr-only').contains('Managed')
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sends an invite', function () {
|
|
|
|
cy.intercept('POST', PATHS.addMember, {
|
|
|
|
statusCode: 201,
|
|
|
|
body: {
|
|
|
|
user: {
|
|
|
|
email: 'someone.else@test.com',
|
|
|
|
invite: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('.form-control').type('someone.else@test.com')
|
|
|
|
cy.get('.add-more-members-form button').click()
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(4)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.contains('someone.else@test.com')
|
|
|
|
cy.contains('N/A')
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('.sr-only').contains('Pending invite')
|
2024-04-19 08:30:23 -04:00
|
|
|
cy.findByTestId('badge-pending-invite').should(
|
|
|
|
'have.text',
|
|
|
|
'Pending invite'
|
|
|
|
)
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get(`.security-state-invite-pending`).should('exist')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tries to send an invite and displays the error', function () {
|
|
|
|
cy.intercept('POST', PATHS.addMember, {
|
|
|
|
statusCode: 500,
|
|
|
|
body: {
|
|
|
|
error: {
|
|
|
|
message: 'User already added',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('.form-control').type('someone.else@test.com')
|
|
|
|
cy.get('.add-more-members-form button').click()
|
|
|
|
cy.get('.alert').contains('Error: User already added')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('checks the select all checkbox', function () {
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(1)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').should('not.be.checked')
|
|
|
|
})
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('tr:nth-child(2)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').should('not.be.checked')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('.select-all').click()
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(1)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').should('be.checked')
|
|
|
|
})
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('tr:nth-child(2)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').should('be.checked')
|
|
|
|
})
|
|
|
|
})
|
2023-08-30 11:20:57 -04:00
|
|
|
|
|
|
|
cy.get('button').contains('Remove from group').click()
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('remove a member', function () {
|
|
|
|
cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
|
|
|
|
statusCode: 200,
|
|
|
|
})
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(1)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').check()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('button').contains('Remove from group').click()
|
|
|
|
|
|
|
|
cy.get('small').contains('You have added 2 of 10 available members')
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(1)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.contains('bobby.lapointe@test.com')
|
|
|
|
cy.contains('Bobby Lapointe')
|
|
|
|
cy.contains('2nd Jan 2023')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('cannot remove a managed member', function () {
|
|
|
|
cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
|
|
|
|
statusCode: 200,
|
|
|
|
})
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
2023-08-25 05:19:33 -04:00
|
|
|
// no checkbox should be shown for 'Claire Jennings', a managed user
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('tr:nth-child(3)').within(() => {
|
2023-08-25 05:19:33 -04:00
|
|
|
cy.get('.select-item').should('not.exist')
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tries to remove a user and displays the error', function () {
|
|
|
|
cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
|
|
|
|
statusCode: 500,
|
|
|
|
})
|
|
|
|
|
2023-08-25 04:51:45 -04:00
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(1)').within(() => {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').check()
|
|
|
|
})
|
|
|
|
})
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.get('.page-header').within(() => {
|
|
|
|
cy.get('button').contains('Remove from group').click()
|
|
|
|
})
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
cy.get('.alert').contains('Sorry, something went wrong')
|
|
|
|
})
|
|
|
|
})
|
2023-10-19 08:51:33 -04:00
|
|
|
|
|
|
|
describe('Group members when group SSO is enabled', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map()
|
|
|
|
win.metaAttributesCache.set('ol-users', [
|
|
|
|
JOHN_DOE,
|
|
|
|
BOBBY_LAPOINTE,
|
|
|
|
CLAIRE_JENNINGS,
|
|
|
|
])
|
|
|
|
win.metaAttributesCache.set('ol-groupId', GROUP_ID)
|
|
|
|
win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
|
|
|
|
win.metaAttributesCache.set('ol-groupSize', 10)
|
|
|
|
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not display SSO Column when group sso is not enabled', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-groupSSOActive', false)
|
|
|
|
})
|
|
|
|
mountGroupMembersProvider()
|
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(2)').within(() => {
|
|
|
|
cy.contains('bobby.lapointe@test.com')
|
2023-10-27 09:11:34 -04:00
|
|
|
cy.get('.sr-only').contains('SSO not active').should('not.exist')
|
2023-10-19 08:51:33 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('tr:nth-child(3)').within(() => {
|
|
|
|
cy.contains('claire.jennings@test.com')
|
2023-10-27 09:11:34 -04:00
|
|
|
cy.get('.sr-only').contains('SSO active').should('not.exist')
|
2023-10-19 08:51:33 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2023-10-27 09:11:34 -04:00
|
|
|
|
|
|
|
it('should display SSO Column when Group SSO is enabled', function () {
|
2023-10-19 08:51:33 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
|
|
|
})
|
|
|
|
mountGroupMembersProvider()
|
|
|
|
cy.get('ul.managed-users-list table > tbody').within(() => {
|
|
|
|
cy.get('tr:nth-child(2)').within(() => {
|
|
|
|
cy.contains('bobby.lapointe@test.com')
|
2023-10-27 09:11:34 -04:00
|
|
|
cy.get('.sr-only').contains('SSO not active')
|
2023-10-19 08:51:33 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('tr:nth-child(3)').within(() => {
|
|
|
|
cy.contains('claire.jennings@test.com')
|
2023-10-27 09:11:34 -04:00
|
|
|
cy.get('.sr-only').contains('SSO active')
|
2023-10-19 08:51:33 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|