first commit
This commit is contained in:
@@ -0,0 +1,802 @@
|
||||
import type { PropsWithChildren } from 'react'
|
||||
import sinon from 'sinon'
|
||||
import DropdownButton from '@/features/group-management/components/members-table/dropdown-button'
|
||||
import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
|
||||
import { User } from '../../../../../../types/group-management/user'
|
||||
|
||||
function Wrapper({ children }: PropsWithChildren<Record<string, unknown>>) {
|
||||
return (
|
||||
<table className="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="managed-users-actions" style={{ textAlign: 'right' }}>
|
||||
<GroupMembersProvider>{children}</GroupMembersProvider>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
)
|
||||
}
|
||||
|
||||
function mountDropDownComponent(user: User, subscriptionId: string) {
|
||||
cy.mount(
|
||||
<Wrapper>
|
||||
<DropdownButton
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</Wrapper>
|
||||
)
|
||||
}
|
||||
|
||||
describe('DropdownButton', function () {
|
||||
const subscriptionId = '123abc123abc'
|
||||
|
||||
describe('with a standard group', function () {
|
||||
describe('for a pending user (has not joined group)', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-group-invite-action').should('be.visible')
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for the group admin', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Managed Users enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a pending user (has not joined group)', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-group-invite-action').should('be.visible')
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a managed group member', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: subscriptionId,
|
||||
enrolledAt: new Date(),
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render the dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('delete-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('remove-user-action').should('not.exist')
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a non-managed group member', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should(
|
||||
'be.visible'
|
||||
)
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a managed group admin user', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: subscriptionId,
|
||||
enrolledAt: new Date(),
|
||||
},
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render the button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the (empty) menu when the button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('no-actions-available').should('exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Group SSO enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-managedUsersActive', false)
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a pending user (has not joined group)', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-group-invite-action').should('be.visible')
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('unlink-user-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a group member not linked with SSO yet', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
})
|
||||
|
||||
it('should show resend invite when user is admin', function () {
|
||||
mountDropDownComponent({ ...user, isEntityAdmin: true }, '123abc')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('exist')
|
||||
})
|
||||
|
||||
it('should not show resend invite when SSO is disabled', function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', false)
|
||||
})
|
||||
mountDropDownComponent(user, '123abc')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
})
|
||||
|
||||
it('should show the resend SSO invite option when dropdown button is clicked', function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
mountDropDownComponent(user, '123abc')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('be.visible')
|
||||
})
|
||||
|
||||
it('should make the correct post request when resend SSO invite is clicked ', function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
cy.intercept(
|
||||
'POST',
|
||||
'/manage/groups/123abc/resendSSOLinkInvite/some-user',
|
||||
{ success: true }
|
||||
).as('resendInviteRequest')
|
||||
mountDropDownComponent(user, '123abc')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-sso-link-invite-action')
|
||||
.should('exist')
|
||||
.as('resendInvite')
|
||||
cy.get('@resendInvite').click()
|
||||
cy.wait('@resendInviteRequest')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Managed Users and Group SSO enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a pending user (has not joined group)', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('resend-group-invite-action').should('be.visible')
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('unlink-user-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a non-managed group member with SSO linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
sso: [
|
||||
{
|
||||
groupId: subscriptionId,
|
||||
linkedAt: new Date(),
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should(
|
||||
'be.visible'
|
||||
)
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
cy.findByTestId('unlink-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a non-managed group member with SSO not linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
sso: [],
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should(
|
||||
'be.visible'
|
||||
)
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
cy.findByTestId('unlink-user-action').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a non-managed group admin with SSO linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
sso: [
|
||||
{
|
||||
groupId: subscriptionId,
|
||||
linkedAt: new Date(),
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should(
|
||||
'be.visible'
|
||||
)
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
cy.findByTestId('unlink-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('delete-user-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a non-managed group admin with SSO not linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
sso: [],
|
||||
},
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should(
|
||||
'be.visible'
|
||||
)
|
||||
cy.findByTestId('remove-user-action').should('be.visible')
|
||||
cy.findByTestId('delete-user-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('exist')
|
||||
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a managed group member with SSO not linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: subscriptionId,
|
||||
enrolledAt: new Date(),
|
||||
sso: [],
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render the dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('delete-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('remove-user-action').should('not.exist')
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('exist')
|
||||
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a managed group member with SSO linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: subscriptionId,
|
||||
enrolledAt: new Date(),
|
||||
sso: [
|
||||
{
|
||||
groupId: subscriptionId,
|
||||
linkedAt: new Date(),
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render the dropdown button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('delete-user-action').should('be.visible')
|
||||
|
||||
cy.findByTestId('remove-user-action').should('not.exist')
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a managed group admin with SSO not linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: subscriptionId,
|
||||
enrolledAt: new Date(),
|
||||
sso: [],
|
||||
},
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render the button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show the correct menu when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('exist')
|
||||
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('remove-user-action').should('not.exist')
|
||||
cy.findByTestId('delete-user-action').should('not.exist')
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('for a managed group admin with SSO linked', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: subscriptionId,
|
||||
enrolledAt: new Date(),
|
||||
sso: [
|
||||
{
|
||||
groupId: subscriptionId,
|
||||
linkedAt: new Date(),
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
mountDropDownComponent(user, subscriptionId)
|
||||
})
|
||||
|
||||
it('should render the button', function () {
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
cy.findByRole('button', { name: /actions/i })
|
||||
})
|
||||
|
||||
it('should show no actions except to unlink when dropdown button is clicked', function () {
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
|
||||
cy.findByTestId('unlink-user-action').should('exist')
|
||||
|
||||
cy.findByTestId('no-actions-available').should('not.exist')
|
||||
cy.findByTestId('delete-user-action').should('not.exist')
|
||||
cy.findByTestId('remove-user-action').should('not.exist')
|
||||
cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
|
||||
cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,86 @@
|
||||
import ManagedUserStatus from '@/features/group-management/components/members-table/managed-user-status'
|
||||
import { User } from '../../../../../../types/group-management/user'
|
||||
|
||||
describe('MemberStatus', function () {
|
||||
describe('with a pending invite', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date(),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
beforeEach(function () {
|
||||
cy.mount(<ManagedUserStatus user={user} />)
|
||||
})
|
||||
|
||||
it('should render a pending state', function () {
|
||||
cy.get('.security-state-invite-pending').contains('Managed')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a managed user', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: { managedBy: 'some-group', enrolledAt: new Date() },
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
beforeEach(function () {
|
||||
cy.mount(<ManagedUserStatus user={user} />)
|
||||
})
|
||||
|
||||
it('should render a pending state', function () {
|
||||
cy.get('.security-state-managed').contains('Managed')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an un-managed user', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
beforeEach(function () {
|
||||
cy.mount(<ManagedUserStatus user={user} />)
|
||||
})
|
||||
|
||||
it('should render an un-managed state', function () {
|
||||
cy.get('.security-state-not-managed').contains('Managed')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with the group admin', function () {
|
||||
const user: User = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
beforeEach(function () {
|
||||
cy.mount(<ManagedUserStatus user={user} />)
|
||||
})
|
||||
|
||||
it('should render no state indicator', function () {
|
||||
cy.get('.security-state-group-admin')
|
||||
.contains('Managed')
|
||||
.should('not.exist')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,710 @@
|
||||
import sinon from 'sinon'
|
||||
import MemberRow from '@/features/group-management/components/members-table/member-row'
|
||||
import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
|
||||
import { User } from '../../../../../../types/group-management/user'
|
||||
|
||||
describe('MemberRow', function () {
|
||||
const subscriptionId = '123abc'
|
||||
|
||||
describe('default view', function () {
|
||||
describe('with an ordinary user', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('renders the row', function () {
|
||||
cy.get('tr')
|
||||
// Checkbox
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
// Email
|
||||
cy.get('tr').contains(user.email)
|
||||
// Name
|
||||
cy.get('tr').contains(user.first_name)
|
||||
cy.get('tr').contains(user.last_name)
|
||||
// Last active date
|
||||
cy.get('tr').contains('21st Nov 2070')
|
||||
// Dropdown button
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
|
||||
cy.get('tr').contains('SSO').should('not.exist')
|
||||
cy.get('tr').contains('Managed').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a pending invite', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Pending invite" badge', function () {
|
||||
cy.findByTestId('badge-pending-invite').should(
|
||||
'have.text',
|
||||
'Pending invite'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a group admin', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Group admin" symbol', function () {
|
||||
cy.findByTestId('group-admin-symbol').within(() => {
|
||||
cy.findByText(/group admin/i)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('selecting and unselecting user row', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should select and unselect the user', function () {
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Managed Users enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an ordinary user', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('renders the row', function () {
|
||||
cy.get('tr').should('exist')
|
||||
// Checkbox
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
// Email
|
||||
cy.get('tr').contains(user.email)
|
||||
// Name
|
||||
cy.get('tr').contains(user.first_name)
|
||||
cy.get('tr').contains(user.last_name)
|
||||
// Last active date
|
||||
cy.get('tr').contains('21st Nov 2070')
|
||||
// Managed status
|
||||
cy.get('tr').contains('Managed')
|
||||
// Dropdown button
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a pending invite', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Pending invite" badge', function () {
|
||||
cy.findByTestId('badge-pending-invite').should(
|
||||
'have.text',
|
||||
'Pending invite'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a group admin', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Group admin" symbol', function () {
|
||||
cy.findByTestId('group-admin-symbol').within(() => {
|
||||
cy.findByText(/group admin/i)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('selecting and unselecting user row', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should select and unselect the user', function () {
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Group SSO enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an ordinary user', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('renders the row', function () {
|
||||
// Checkbox
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
// Email
|
||||
cy.get('tr').contains(user.email)
|
||||
// Name
|
||||
cy.get('tr').contains(user.first_name)
|
||||
cy.get('tr').contains(user.last_name)
|
||||
// Last active date
|
||||
cy.get('tr').contains('21st Nov 2070')
|
||||
// SSO status
|
||||
cy.get('tr').contains('SSO')
|
||||
// Dropdown button
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
|
||||
cy.get('tr').contains('Managed').should('not.exist')
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a pending invite', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Pending invite" badge', function () {
|
||||
cy.findByTestId('badge-pending-invite').should(
|
||||
'have.text',
|
||||
'Pending invite'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a group admin', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Group admin" symbol', function () {
|
||||
cy.findByTestId('group-admin-symbol').within(() => {
|
||||
cy.findByText(/group admin/i)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('selecting and unselecting user row', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should select and unselect the user', function () {
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with Managed Users and Group SSO enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an ordinary user', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('renders the row', function () {
|
||||
// Checkbox
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
// Email
|
||||
cy.get('tr').contains(user.email)
|
||||
// Name
|
||||
cy.get('tr').contains(user.first_name)
|
||||
cy.get('tr').contains(user.last_name)
|
||||
// Last active date
|
||||
cy.get('tr').contains('21st Nov 2070')
|
||||
// Managed status
|
||||
cy.get('tr').contains('Managed')
|
||||
// SSO status
|
||||
cy.get('tr').contains('SSO')
|
||||
// Dropdown button
|
||||
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
||||
'exist'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a pending invite', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Pending invite" badge', function () {
|
||||
cy.findByTestId('badge-pending-invite').should(
|
||||
'have.text',
|
||||
'Pending invite'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a group admin', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: true,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render a "Group admin" symbol', function () {
|
||||
cy.findByTestId('group-admin-symbol').within(() => {
|
||||
cy.findByText(/group admin/i)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('selecting and unselecting user row', function () {
|
||||
let user: User
|
||||
|
||||
beforeEach(function () {
|
||||
user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [user])
|
||||
})
|
||||
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MemberRow
|
||||
user={user}
|
||||
openOffboardingModalForUser={sinon.stub()}
|
||||
openUnlinkUserModal={sinon.stub()}
|
||||
groupId={subscriptionId}
|
||||
setGroupUserAlert={sinon.stub()}
|
||||
/>
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should select and unselect the user', function () {
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('be.checked')
|
||||
cy.findByTestId('select-single-checkbox').click()
|
||||
cy.findByTestId('select-single-checkbox').should('not.be.checked')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,332 @@
|
||||
import MembersList from '@/features/group-management/components/members-table/members-list'
|
||||
import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
|
||||
import { User } from '../../../../../../types/group-management/user'
|
||||
|
||||
const groupId = 'somegroup'
|
||||
|
||||
function mountManagedUsersList() {
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MembersList groupId={groupId} />
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
}
|
||||
|
||||
describe('MembersList', function () {
|
||||
describe('with users', function () {
|
||||
const users = [
|
||||
{
|
||||
_id: 'user-one',
|
||||
email: 'sarah.brennan@example.com',
|
||||
first_name: 'Sarah',
|
||||
last_name: 'Brennan',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-10-22T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
},
|
||||
{
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date('2070-11-21T03:00:00'),
|
||||
enrollment: undefined,
|
||||
isEntityAdmin: undefined,
|
||||
},
|
||||
]
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', users)
|
||||
})
|
||||
mountManagedUsersList()
|
||||
})
|
||||
|
||||
it('should render the table headers but not SSO Column', function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', false)
|
||||
})
|
||||
mountManagedUsersList()
|
||||
|
||||
// Select-all checkbox
|
||||
cy.findByTestId('managed-entities-table').within(() => {
|
||||
cy.findByTestId('select-all-checkbox')
|
||||
})
|
||||
cy.findByTestId('managed-entities-table').should('contain.text', 'Email')
|
||||
cy.findByTestId('managed-entities-table').should('contain.text', 'Name')
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
'Last Active'
|
||||
)
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'not.contain.text',
|
||||
'Security'
|
||||
)
|
||||
})
|
||||
it('should render the table headers with SSO Column', function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
mountManagedUsersList()
|
||||
|
||||
// Select-all checkbox
|
||||
cy.findByTestId('managed-entities-table').within(() => {
|
||||
cy.findByTestId('select-all-checkbox')
|
||||
})
|
||||
|
||||
cy.findByTestId('managed-entities-table').should('contain.text', 'Email')
|
||||
cy.findByTestId('managed-entities-table').should('contain.text', 'Name')
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
'Last Active'
|
||||
)
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
'Security'
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the list of users', function () {
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.findAllByRole('row').should('have.length', 2)
|
||||
})
|
||||
// First user
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
users[0].email
|
||||
)
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
users[0].first_name
|
||||
)
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
users[0].last_name
|
||||
)
|
||||
// Second user
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
users[1].email
|
||||
)
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
users[1].first_name
|
||||
)
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
users[1].last_name
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('empty user list', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-users', [])
|
||||
})
|
||||
cy.mount(
|
||||
<GroupMembersProvider>
|
||||
<MembersList groupId={groupId} />
|
||||
</GroupMembersProvider>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the list, with a "no members" message', function () {
|
||||
cy.findByTestId('managed-entities-table').should(
|
||||
'contain.text',
|
||||
'No members'
|
||||
)
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.findAllByRole('row')
|
||||
.should('have.length', 1)
|
||||
.and('contain.text', 'No members')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('SSO unlinking', function () {
|
||||
const USER_PENDING_INVITE: User = {
|
||||
_id: 'abc123def456',
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
email: 'john.doe@test.com',
|
||||
last_active_at: new Date('2023-01-15'),
|
||||
invite: true,
|
||||
}
|
||||
const USER_NOT_LINKED: User = {
|
||||
_id: 'bcd234efa567',
|
||||
first_name: 'Bobby',
|
||||
last_name: 'Lapointe',
|
||||
email: 'bobby.lapointe@test.com',
|
||||
last_active_at: new Date('2023-01-02'),
|
||||
invite: false,
|
||||
}
|
||||
const USER_LINKED: User = {
|
||||
_id: 'defabc231453',
|
||||
first_name: 'Claire',
|
||||
last_name: 'Jennings',
|
||||
email: 'claire.jennings@test.com',
|
||||
last_active_at: new Date('2023-01-03'),
|
||||
invite: false,
|
||||
enrollment: {
|
||||
sso: [
|
||||
{
|
||||
groupId,
|
||||
linkedAt: new Date('2023-01-03'),
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
const USER_LINKED_AND_MANAGED: User = {
|
||||
_id: 'defabc231453',
|
||||
first_name: 'Jean-Luc',
|
||||
last_name: 'Picard',
|
||||
email: 'picard@test.com',
|
||||
last_active_at: new Date('2023-01-03'),
|
||||
invite: false,
|
||||
enrollment: {
|
||||
managedBy: groupId,
|
||||
enrolledAt: new Date('2023-01-03'),
|
||||
sso: [
|
||||
{
|
||||
groupId,
|
||||
linkedAt: new Date('2023-01-03'),
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
const users = [
|
||||
USER_PENDING_INVITE,
|
||||
USER_NOT_LINKED,
|
||||
USER_LINKED,
|
||||
USER_LINKED_AND_MANAGED,
|
||||
]
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-groupId', groupId)
|
||||
win.metaAttributesCache.set('ol-users', users)
|
||||
win.metaAttributesCache.set('ol-groupSSOActive', true)
|
||||
})
|
||||
|
||||
cy.intercept('POST', `manage/groups/${groupId}/unlink-user/*`, {
|
||||
statusCode: 200,
|
||||
})
|
||||
})
|
||||
|
||||
describe('unlinking user', function () {
|
||||
beforeEach(function () {
|
||||
mountManagedUsersList()
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.get('tr:nth-child(3)').within(() => {
|
||||
cy.findByText('SSO active')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('unlink-user-action').click()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should show successs notification and update the user row after unlinking', function () {
|
||||
cy.findByRole('dialog').within(() => {
|
||||
cy.findByRole('button', { name: /unlink user/i }).click()
|
||||
})
|
||||
cy.findByRole('alert').should(
|
||||
'contain.text',
|
||||
`SSO reauthentication request has been sent to ${USER_LINKED.email}`
|
||||
)
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.get('tr:nth-child(3)').within(() => {
|
||||
cy.findByText('SSO not active')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('managed users enabled', function () {
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache.set('ol-managedUsersActive', true)
|
||||
})
|
||||
mountManagedUsersList()
|
||||
})
|
||||
|
||||
describe('when user is not managed', function () {
|
||||
beforeEach(function () {
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.get('tr:nth-child(3)').within(() => {
|
||||
cy.findByText('SSO active')
|
||||
cy.findByText('Not managed')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('unlink-user-action').click()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should show successs notification and update the user row after unlinking', function () {
|
||||
cy.findByRole('dialog').within(() => {
|
||||
cy.findByRole('button', { name: /unlink user/i }).click()
|
||||
})
|
||||
cy.findByRole('alert').should(
|
||||
'contain.text',
|
||||
`SSO reauthentication request has been sent to ${USER_LINKED.email}`
|
||||
)
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.get('tr:nth-child(3)').within(() => {
|
||||
cy.findByText('SSO not active')
|
||||
cy.findByText('Not managed')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when user is managed', function () {
|
||||
beforeEach(function () {
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.get('tr:nth-child(4)').within(() => {
|
||||
cy.findByText('SSO active')
|
||||
cy.findAllByText('Managed')
|
||||
cy.findByRole('button', { name: /actions/i }).click()
|
||||
cy.findByTestId('unlink-user-action').click()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should show successs notification and update the user row after unlinking', function () {
|
||||
cy.findByRole('dialog').within(() => {
|
||||
cy.findByRole('button', { name: /unlink user/i }).click()
|
||||
})
|
||||
cy.findByRole('alert').should(
|
||||
'contain.text',
|
||||
`SSO reauthentication request has been sent to ${USER_LINKED_AND_MANAGED.email}`
|
||||
)
|
||||
cy.findByTestId('managed-entities-table')
|
||||
.find('tbody')
|
||||
.within(() => {
|
||||
cy.get('tr:nth-child(4)').within(() => {
|
||||
cy.findByText('SSO not active')
|
||||
cy.findAllByText('Managed')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,107 @@
|
||||
import OffboardManagedUserModal from '@/features/group-management/components/members-table/offboard-managed-user-modal'
|
||||
import sinon from 'sinon'
|
||||
|
||||
describe('OffboardManagedUserModal', function () {
|
||||
describe('happy path', function () {
|
||||
const groupId = 'some-group'
|
||||
const user = {
|
||||
_id: 'some-user',
|
||||
email: 'some.user@example.com',
|
||||
first_name: 'Some',
|
||||
last_name: 'User',
|
||||
invite: true,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: `${groupId}`,
|
||||
enrolledAt: new Date(),
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
const otherUser = {
|
||||
_id: 'other-user',
|
||||
email: 'other.user@example.com',
|
||||
first_name: 'Other',
|
||||
last_name: 'User',
|
||||
invite: false,
|
||||
last_active_at: new Date(),
|
||||
enrollment: {
|
||||
managedBy: `${groupId}`,
|
||||
enrolledAt: new Date(),
|
||||
},
|
||||
isEntityAdmin: undefined,
|
||||
}
|
||||
const allMembers = [user, otherUser]
|
||||
|
||||
beforeEach(function () {
|
||||
cy.mount(
|
||||
<OffboardManagedUserModal
|
||||
user={user}
|
||||
allMembers={allMembers}
|
||||
groupId={groupId}
|
||||
onClose={sinon.stub()}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
it('should render the modal', function () {
|
||||
cy.get('#delete-user-form').should('exist')
|
||||
})
|
||||
|
||||
it('should disable the button if a recipient is not selected', function () {
|
||||
// Button should be disabled initially
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
|
||||
// Not selecting a recipient...
|
||||
|
||||
// Fill in the email input
|
||||
cy.get('#supplied-email-input').type(user.email)
|
||||
|
||||
// Button still disabled
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
})
|
||||
|
||||
it('should disable the button if the email is not filled in', function () {
|
||||
// Button should be disabled initially
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
|
||||
// Select a recipient
|
||||
cy.get('#recipient-select-input').select('other.user@example.com')
|
||||
|
||||
// Not filling in the email...
|
||||
|
||||
// Button still disabled
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
})
|
||||
|
||||
it('should disable the button if the email does not match the user', function () {
|
||||
// Button should be disabled initially
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
|
||||
// Select a recipient
|
||||
cy.get('#recipient-select-input').select('other.user@example.com')
|
||||
|
||||
// Fill in the email input, with the wrong email address
|
||||
cy.get('#supplied-email-input').type('totally.wrong@example.com')
|
||||
|
||||
// Button still disabled
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
})
|
||||
|
||||
it('should fill out the form, and enable the delete button', function () {
|
||||
// Button should be disabled initially
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
|
||||
// Select a recipient
|
||||
cy.get('#recipient-select-input').select('other.user@example.com')
|
||||
|
||||
// Button still disabled
|
||||
cy.get('button[type="submit"]').should('be.disabled')
|
||||
|
||||
// Fill in the email input
|
||||
cy.get('#supplied-email-input').type(user.email)
|
||||
|
||||
// Button should be enabled now
|
||||
cy.get('button[type="submit"]').should('not.be.disabled')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { ReactElement } from 'react'
|
||||
import sinon from 'sinon'
|
||||
import fetchMock from 'fetch-mock'
|
||||
import UnlinkUserModal from '@/features/group-management/components/members-table/unlink-user-modal'
|
||||
import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
|
||||
import { expect } from 'chai'
|
||||
|
||||
export function renderWithContext(component: ReactElement, props = {}) {
|
||||
const GroupMembersProviderWrapper = ({
|
||||
children,
|
||||
}: {
|
||||
children: ReactElement
|
||||
}) => <GroupMembersProvider {...props}>{children}</GroupMembersProvider>
|
||||
|
||||
return render(component, { wrapper: GroupMembersProviderWrapper })
|
||||
}
|
||||
|
||||
describe('<UnlinkUserModal />', function () {
|
||||
let defaultProps: any
|
||||
const groupId = 'group123'
|
||||
const userId = 'user123'
|
||||
|
||||
beforeEach(function () {
|
||||
defaultProps = {
|
||||
onClose: sinon.stub(),
|
||||
user: { _id: userId },
|
||||
setGroupUserAlert: sinon.stub(),
|
||||
}
|
||||
window.metaAttributesCache.set('ol-groupId', groupId)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
fetchMock.removeRoutes().clearHistory()
|
||||
})
|
||||
|
||||
it('displays the modal', async function () {
|
||||
renderWithContext(<UnlinkUserModal {...defaultProps} />)
|
||||
await screen.findByRole('heading', {
|
||||
name: 'Unlink user',
|
||||
})
|
||||
screen.getByText('You’re about to remove the SSO login option for', {
|
||||
exact: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('closes the modal on success', async function () {
|
||||
fetchMock.post(`/manage/groups/${groupId}/unlink-user/${userId}`, 200)
|
||||
|
||||
renderWithContext(<UnlinkUserModal {...defaultProps} />)
|
||||
await screen.findByRole('heading', {
|
||||
name: 'Unlink user',
|
||||
})
|
||||
|
||||
const confirmButton = screen.getByRole('button', { name: 'Unlink user' })
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
await waitFor(() => expect(defaultProps.onClose).to.have.been.called)
|
||||
})
|
||||
|
||||
it('handles errors', async function () {
|
||||
fetchMock.post(`/manage/groups/${groupId}/unlink-user/${userId}`, 500)
|
||||
|
||||
renderWithContext(<UnlinkUserModal {...defaultProps} />)
|
||||
await screen.findByRole('heading', {
|
||||
name: 'Unlink user',
|
||||
})
|
||||
|
||||
const confirmButton = screen.getByRole('button', { name: 'Unlink user' })
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
await waitFor(() => screen.findByText('Sorry, something went wrong'))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user