|
|
@@ -2,6 +2,7 @@ import type { PropsWithChildren } from 'react'
|
|
|
import sinon from 'sinon'
|
|
|
import ManagedUserDropdownButton from '../../../../../../frontend/js/features/group-management/components/managed-users/managed-user-dropdown-button'
|
|
|
import { GroupMembersProvider } from '../../../../../../frontend/js/features/group-management/context/group-members-context'
|
|
|
+import { User } from '../../../../../../types/group-management/user'
|
|
|
|
|
|
function Wrapper({ children }: PropsWithChildren<Record<string, unknown>>) {
|
|
|
return (
|
|
|
@@ -16,6 +17,19 @@ function Wrapper({ children }: PropsWithChildren<Record<string, unknown>>) {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+function mountDropDownComponent(user: User, subscriptionId: string) {
|
|
|
+ cy.mount(
|
|
|
+ <Wrapper>
|
|
|
+ <ManagedUserDropdownButton
|
|
|
+ user={user}
|
|
|
+ openOffboardingModalForUser={sinon.stub()}
|
|
|
+ groupId={subscriptionId}
|
|
|
+ setManagedUserAlert={sinon.stub()}
|
|
|
+ />
|
|
|
+ </Wrapper>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
describe('ManagedUserDropdownButton', function () {
|
|
|
const subscriptionId = '123abc'
|
|
|
|
|
|
@@ -38,17 +52,7 @@ describe('ManagedUserDropdownButton', 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>
|
|
|
- )
|
|
|
+ mountDropDownComponent(user, subscriptionId)
|
|
|
})
|
|
|
|
|
|
it('should render dropdown button', function () {
|
|
|
@@ -84,16 +88,7 @@ describe('ManagedUserDropdownButton', function () {
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
})
|
|
|
|
|
|
- cy.mount(
|
|
|
- <Wrapper>
|
|
|
- <ManagedUserDropdownButton
|
|
|
- user={user}
|
|
|
- openOffboardingModalForUser={sinon.stub()}
|
|
|
- groupId={subscriptionId}
|
|
|
- setManagedUserAlert={sinon.stub()}
|
|
|
- />
|
|
|
- </Wrapper>
|
|
|
- )
|
|
|
+ mountDropDownComponent(user, subscriptionId)
|
|
|
})
|
|
|
|
|
|
it('should render dropdown button', function () {
|
|
|
@@ -133,16 +128,7 @@ describe('ManagedUserDropdownButton', function () {
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
})
|
|
|
|
|
|
- cy.mount(
|
|
|
- <Wrapper>
|
|
|
- <ManagedUserDropdownButton
|
|
|
- user={user}
|
|
|
- openOffboardingModalForUser={sinon.stub()}
|
|
|
- groupId={subscriptionId}
|
|
|
- setManagedUserAlert={sinon.stub()}
|
|
|
- />
|
|
|
- </Wrapper>
|
|
|
- )
|
|
|
+ mountDropDownComponent(user, subscriptionId)
|
|
|
})
|
|
|
|
|
|
it('should render dropdown button', function () {
|
|
|
@@ -181,17 +167,7 @@ describe('ManagedUserDropdownButton', 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>
|
|
|
- )
|
|
|
+ mountDropDownComponent(user, subscriptionId)
|
|
|
})
|
|
|
|
|
|
it('should render dropdown button', function () {
|
|
|
@@ -227,16 +203,7 @@ describe('ManagedUserDropdownButton', function () {
|
|
|
win.metaAttributesCache.set('ol-users', [user])
|
|
|
})
|
|
|
|
|
|
- cy.mount(
|
|
|
- <Wrapper>
|
|
|
- <ManagedUserDropdownButton
|
|
|
- user={user}
|
|
|
- openOffboardingModalForUser={sinon.stub()}
|
|
|
- groupId={subscriptionId}
|
|
|
- setManagedUserAlert={sinon.stub()}
|
|
|
- />
|
|
|
- </Wrapper>
|
|
|
- )
|
|
|
+ mountDropDownComponent(user, subscriptionId)
|
|
|
})
|
|
|
|
|
|
it('should render the button', function () {
|
|
|
@@ -251,4 +218,89 @@ describe('ManagedUserDropdownButton', function () {
|
|
|
cy.findByTestId('no-actions-available').should('exist')
|
|
|
})
|
|
|
})
|
|
|
+ describe('sending SSO invite reminder', 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: undefined,
|
|
|
+ }
|
|
|
+ beforeEach(function () {
|
|
|
+ cy.window().then(win => {
|
|
|
+ win.metaAttributesCache.set('ol-users', [user])
|
|
|
+ })
|
|
|
+ cy.window().then(win => {
|
|
|
+ win.metaAttributesCache.set('ol-groupSSOActive', true)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ it('should show resend invite when user is admin', function () {
|
|
|
+ mountDropDownComponent({ ...user, isEntityAdmin: true }, '123abc')
|
|
|
+ cy.get('.action-btn').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.get('.action-btn').click()
|
|
|
+ cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
|
|
|
+ })
|
|
|
+ it('should not show resend invite when user has accepted SSO already', function () {
|
|
|
+ cy.window().then(win => {
|
|
|
+ win.metaAttributesCache.set('ol-groupSSOActive', false)
|
|
|
+ })
|
|
|
+ mountDropDownComponent(
|
|
|
+ {
|
|
|
+ ...user,
|
|
|
+ enrollment: {
|
|
|
+ managedBy: 'some-group',
|
|
|
+ enrolledAt: new Date(),
|
|
|
+ sso: {
|
|
|
+ providerId: '123',
|
|
|
+ externalId: '123',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ '123abc'
|
|
|
+ )
|
|
|
+ cy.get('.action-btn').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.get('.action-btn').click()
|
|
|
+ cy.findByTestId('resend-sso-link-invite-action').should('exist')
|
|
|
+ cy.findByTestId('resend-sso-link-invite-action').then($el => {
|
|
|
+ Cypress.dom.isVisible($el)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ 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.get('.action-btn').click()
|
|
|
+ cy.findByTestId('resend-sso-link-invite-action')
|
|
|
+ .should('exist')
|
|
|
+ .as('resendInvite')
|
|
|
+ cy.get('@resendInvite').click()
|
|
|
+ cy.wait('@resendInviteRequest')
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|