2023-08-25 12:44:47 -04:00
|
|
|
import type { PropsWithChildren } from 'react'
|
2023-07-13 04:50:43 -04:00
|
|
|
import sinon from 'sinon'
|
2023-08-25 12:44:47 -04:00
|
|
|
import ManagedUserDropdownButton from '../../../../../../frontend/js/features/group-management/components/managed-users/managed-user-dropdown-button'
|
2023-08-22 09:30:34 -04:00
|
|
|
import { GroupMembersProvider } from '../../../../../../frontend/js/features/group-management/context/group-members-context'
|
2023-06-30 04:30:20 -04:00
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
function Wrapper({ children }: PropsWithChildren<Record<string, unknown>>) {
|
|
|
|
return (
|
|
|
|
<ul className="managed-users-list">
|
|
|
|
<span
|
|
|
|
className="managed-users-actions"
|
|
|
|
style={{ display: 'flex', width: '100%', justifyContent: 'flex-end' }}
|
|
|
|
>
|
|
|
|
<GroupMembersProvider>{children}</GroupMembersProvider>
|
|
|
|
</span>
|
|
|
|
</ul>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-30 04:30:20 -04:00
|
|
|
describe('ManagedUserDropdownButton', function () {
|
2023-08-22 17:38:37 -04:00
|
|
|
const subscriptionId = '123abc'
|
|
|
|
|
2023-06-30 04:30:20 -04:00
|
|
|
describe('with managed user', function () {
|
|
|
|
const user = {
|
|
|
|
_id: 'some-user',
|
|
|
|
email: 'some.user@example.com',
|
|
|
|
first_name: 'Some',
|
|
|
|
last_name: 'User',
|
2023-08-25 12:44:47 -04:00
|
|
|
invite: false,
|
2023-06-30 04:30:20 -04:00
|
|
|
last_active_at: new Date(),
|
|
|
|
enrollment: {
|
|
|
|
managedBy: 'some-group',
|
|
|
|
enrolledAt: new Date(),
|
|
|
|
},
|
|
|
|
isEntityAdmin: undefined,
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
|
|
|
|
2023-07-13 04:50:43 -04:00
|
|
|
cy.mount(
|
2023-08-25 12:44:47 -04:00
|
|
|
<Wrapper>
|
2023-08-22 09:30:34 -04:00
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={sinon.stub()}
|
2023-08-22 17:38:37 -04:00
|
|
|
groupId={subscriptionId}
|
|
|
|
setManagedUserAlert={sinon.stub()}
|
2023-08-22 09:30:34 -04:00
|
|
|
/>
|
2023-08-25 12:44:47 -04:00
|
|
|
</Wrapper>
|
2023-07-13 04:50:43 -04:00
|
|
|
)
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
it('should render dropdown button', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
|
|
|
'exist'
|
|
|
|
)
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get(`.action-btn`).should('exist')
|
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
it('should show the correct menu when dropdown button is clicked', function () {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.action-btn').click()
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.findByTestId('delete-user-action').should('exist')
|
|
|
|
cy.findByTestId('delete-user-action').then($el => {
|
2023-06-30 04:30:20 -04:00
|
|
|
Cypress.dom.isVisible($el)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
describe('with non-managed user (have joined group)', function () {
|
|
|
|
const 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])
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.mount(
|
|
|
|
<Wrapper>
|
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={sinon.stub()}
|
|
|
|
groupId={subscriptionId}
|
|
|
|
setManagedUserAlert={sinon.stub()}
|
|
|
|
/>
|
|
|
|
</Wrapper>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should render dropdown button', function () {
|
|
|
|
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
|
|
|
'exist'
|
|
|
|
)
|
|
|
|
cy.get(`.action-btn`).should('exist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should show the correct menu when dropdown button is clicked', function () {
|
|
|
|
cy.get('.action-btn').click()
|
|
|
|
cy.findByTestId('resend-managed-user-invite-action').should('exist')
|
|
|
|
cy.findByTestId('resend-managed-user-invite-action').then($el => {
|
|
|
|
Cypress.dom.isVisible($el)
|
|
|
|
})
|
|
|
|
cy.findByTestId('remove-user-action').should('exist')
|
|
|
|
cy.findByTestId('remove-user-action').then($el => {
|
|
|
|
Cypress.dom.isVisible($el)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with pending user (have not joined group)', function () {
|
2023-06-30 04:30:20 -04:00
|
|
|
const user = {
|
|
|
|
_id: 'some-user',
|
|
|
|
email: 'some.user@example.com',
|
|
|
|
first_name: 'Some',
|
|
|
|
last_name: 'User',
|
|
|
|
invite: true,
|
|
|
|
last_active_at: new Date(),
|
2023-08-24 06:29:37 -04:00
|
|
|
enrollment: {},
|
2023-06-30 04:30:20 -04:00
|
|
|
isEntityAdmin: undefined,
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.mount(
|
2023-08-25 12:44:47 -04:00
|
|
|
<Wrapper>
|
2023-08-22 09:30:34 -04:00
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={sinon.stub()}
|
2023-08-22 17:38:37 -04:00
|
|
|
groupId={subscriptionId}
|
|
|
|
setManagedUserAlert={sinon.stub()}
|
2023-08-22 09:30:34 -04:00
|
|
|
/>
|
2023-08-25 12:44:47 -04:00
|
|
|
</Wrapper>
|
2023-08-22 09:30:34 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
it('should render dropdown button', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
|
|
|
'exist'
|
|
|
|
)
|
|
|
|
cy.get(`.action-btn`).should('exist')
|
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
it('should show the correct menu when dropdown button is clicked', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.get('.action-btn').click()
|
2023-08-25 12:44:47 -04:00
|
|
|
cy.findByTestId('resend-group-invite-action').should('exist')
|
|
|
|
cy.findByTestId('resend-group-invite-action').then($el => {
|
|
|
|
Cypress.dom.isVisible($el)
|
|
|
|
})
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.findByTestId('remove-user-action').should('exist')
|
|
|
|
cy.findByTestId('remove-user-action').then($el => {
|
|
|
|
Cypress.dom.isVisible($el)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with group admin user', function () {
|
|
|
|
const user = {
|
|
|
|
_id: 'some-user',
|
|
|
|
email: 'some.user@example.com',
|
|
|
|
first_name: 'Some',
|
|
|
|
last_name: 'User',
|
|
|
|
invite: false,
|
|
|
|
last_active_at: new Date(),
|
2023-08-24 06:29:37 -04:00
|
|
|
enrollment: {},
|
2023-08-22 09:30:34 -04:00
|
|
|
isEntityAdmin: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
|
|
|
|
2023-07-13 04:50:43 -04:00
|
|
|
cy.mount(
|
2023-08-25 12:44:47 -04:00
|
|
|
<Wrapper>
|
2023-08-22 09:30:34 -04:00
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={sinon.stub()}
|
2023-08-22 17:38:37 -04:00
|
|
|
groupId={subscriptionId}
|
|
|
|
setManagedUserAlert={sinon.stub()}
|
2023-08-22 09:30:34 -04:00
|
|
|
/>
|
2023-08-25 12:44:47 -04:00
|
|
|
</Wrapper>
|
2023-07-13 04:50:43 -04:00
|
|
|
)
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
it('should render dropdown button', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
|
|
|
'exist'
|
|
|
|
)
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get(`.action-btn`).should('exist')
|
|
|
|
})
|
|
|
|
|
2023-08-25 12:44:47 -04:00
|
|
|
it('should show the (empty) menu when dropdown button is clicked', function () {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.action-btn').click()
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.findByTestId('no-actions-available').should('exist')
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
})
|
2023-08-25 05:24:58 -04:00
|
|
|
|
|
|
|
describe('with managed group admin user', function () {
|
|
|
|
const 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: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.mount(
|
2023-08-25 12:44:47 -04:00
|
|
|
<Wrapper>
|
2023-08-25 05:24:58 -04:00
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={sinon.stub()}
|
|
|
|
groupId={subscriptionId}
|
|
|
|
setManagedUserAlert={sinon.stub()}
|
|
|
|
/>
|
2023-08-25 12:44:47 -04:00
|
|
|
</Wrapper>
|
2023-08-25 05:24:58 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should render the button', function () {
|
|
|
|
cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
|
|
|
|
'exist'
|
|
|
|
)
|
|
|
|
cy.get(`.action-btn`).should('exist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should show the (empty) menu when the button is clicked', function () {
|
|
|
|
cy.get('.action-btn').click()
|
|
|
|
cy.findByTestId('no-actions-available').should('exist')
|
|
|
|
})
|
|
|
|
})
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|