2023-08-22 09:30:34 -04:00
|
|
|
import sinon from 'sinon'
|
2023-06-30 04:30:20 -04:00
|
|
|
import ManagedUserRow from '../../../../../../frontend/js/features/group-management/components/managed-users/managed-user-row'
|
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
|
|
|
import { User } from '../../../../../../types/group-management/user'
|
|
|
|
|
|
|
|
describe('ManagedUserRow', function () {
|
2023-08-22 17:38:37 -04:00
|
|
|
const subscriptionId = '123abc'
|
|
|
|
|
2023-06-30 04:30:20 -04:00
|
|
|
describe('with an ordinary user', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
let user: User
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
cy.mount(
|
2023-08-22 09:30:34 -04:00
|
|
|
<GroupMembersProvider>
|
|
|
|
<ManagedUserRow
|
|
|
|
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
|
|
|
/>
|
|
|
|
</GroupMembersProvider>
|
2023-06-30 04:30:20 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the row', function () {
|
|
|
|
cy.get('.row').should('exist')
|
|
|
|
// Checkbox
|
|
|
|
cy.get('.select-item').should('not.be.checked')
|
|
|
|
// Email
|
|
|
|
cy.get('.row').contains(user.email)
|
|
|
|
// Name
|
|
|
|
cy.get('.row').contains(user.first_name)
|
|
|
|
cy.get('.row').contains(user.last_name)
|
|
|
|
// Last active date
|
|
|
|
cy.get('.row').contains('21st Nov 2070')
|
|
|
|
// Managed status
|
|
|
|
cy.get('.row').contains('Managed')
|
|
|
|
// Dropdown button
|
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
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a pending invite', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
let user: User
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
cy.mount(
|
2023-08-22 09:30:34 -04:00
|
|
|
<GroupMembersProvider>
|
|
|
|
<ManagedUserRow
|
|
|
|
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
|
|
|
/>
|
|
|
|
</GroupMembersProvider>
|
2023-06-30 04:30:20 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should render a "Pending invite" badge', function () {
|
|
|
|
cy.get('.badge-new-comment').contains('Pending invite')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a group admin', function () {
|
2023-08-22 09:30:34 -04:00
|
|
|
let user: User
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
cy.mount(
|
2023-08-22 09:30:34 -04:00
|
|
|
<GroupMembersProvider>
|
|
|
|
<ManagedUserRow
|
|
|
|
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
|
|
|
/>
|
|
|
|
</GroupMembersProvider>
|
2023-06-30 04:30:20 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should render a "Group admin" symbol', function () {
|
|
|
|
cy.get('[aria-label="Group admin"].fa-user-circle-o').should('exist')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-08-22 09:30:34 -04:00
|
|
|
describe('selecting and unselecting user row', function () {
|
|
|
|
let user: User
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
|
})
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
cy.mount(
|
2023-08-22 09:30:34 -04:00
|
|
|
<GroupMembersProvider>
|
|
|
|
<ManagedUserRow
|
|
|
|
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
|
|
|
/>
|
|
|
|
</GroupMembersProvider>
|
2023-06-30 04:30:20 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2023-08-22 09:30:34 -04:00
|
|
|
it('should select and unselect the user', function () {
|
2023-06-30 04:30:20 -04:00
|
|
|
cy.get('.select-item').should('not.be.checked')
|
|
|
|
cy.get('.select-item').click()
|
|
|
|
cy.get('.select-item').should('be.checked')
|
|
|
|
cy.get('.select-item').click()
|
2023-08-22 09:30:34 -04:00
|
|
|
cy.get('.select-item').should('not.be.checked')
|
2023-06-30 04:30:20 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|