2023-01-31 10:42:52 -05:00
|
|
|
import { expect } from 'chai'
|
2023-02-07 10:38:20 -05:00
|
|
|
import { screen } from '@testing-library/react'
|
2023-01-31 10:42:52 -05:00
|
|
|
import {
|
|
|
|
groupActiveSubscription,
|
|
|
|
groupActiveSubscriptionWithPendingLicenseChange,
|
|
|
|
} from '../../fixtures/subscriptions'
|
2023-02-07 10:38:04 -05:00
|
|
|
import ManagedGroupSubscriptions from '../../../../../../frontend/js/features/subscription/components/dashboard/managed-group-subscriptions'
|
|
|
|
import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
|
2023-02-07 10:38:20 -05:00
|
|
|
import {
|
|
|
|
cleanUpContext,
|
|
|
|
renderWithSubscriptionDashContext,
|
|
|
|
} from '../../helpers/render-with-subscription-dash-context'
|
2023-01-31 10:42:52 -05:00
|
|
|
|
2023-11-06 06:01:43 -05:00
|
|
|
function getManagedGroupSubscription(groupSSO: boolean, managedUsers: boolean) {
|
|
|
|
const subscriptionOne = {
|
2023-01-31 10:42:52 -05:00
|
|
|
...groupActiveSubscription,
|
|
|
|
userIsGroupMember: true,
|
|
|
|
planLevelName: 'Professional',
|
|
|
|
admin_id: {
|
|
|
|
id: 'abc123abc123',
|
|
|
|
email: 'you@example.com',
|
|
|
|
},
|
2023-11-06 06:01:43 -05:00
|
|
|
features: {
|
|
|
|
groupSSO,
|
|
|
|
managedUsers,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const subscriptionTwo = {
|
2023-01-31 10:42:52 -05:00
|
|
|
...groupActiveSubscriptionWithPendingLicenseChange,
|
|
|
|
userIsGroupMember: false,
|
|
|
|
planLevelName: 'Collaborator',
|
|
|
|
admin_id: {
|
|
|
|
id: 'bcd456bcd456',
|
|
|
|
email: 'someone@example.com',
|
|
|
|
},
|
2023-11-06 06:01:43 -05:00
|
|
|
features: {
|
|
|
|
groupSSO,
|
|
|
|
managedUsers,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return [subscriptionOne, subscriptionTwo]
|
|
|
|
}
|
|
|
|
|
|
|
|
const managedGroupSubscriptions: ManagedGroupSubscription[] =
|
|
|
|
getManagedGroupSubscription(false, false)
|
|
|
|
const managedGroupSubscriptions2: ManagedGroupSubscription[] =
|
|
|
|
getManagedGroupSubscription(true, true)
|
|
|
|
const managedGroupSubscriptions3: ManagedGroupSubscription[] =
|
|
|
|
getManagedGroupSubscription(true, false)
|
|
|
|
const managedGroupSubscriptions4: ManagedGroupSubscription[] =
|
|
|
|
getManagedGroupSubscription(false, true)
|
2023-01-31 10:42:52 -05:00
|
|
|
|
|
|
|
describe('<ManagedGroupSubscriptions />', function () {
|
|
|
|
afterEach(function () {
|
2023-02-07 10:38:20 -05:00
|
|
|
cleanUpContext()
|
2023-01-31 10:42:52 -05:00
|
|
|
})
|
|
|
|
|
2023-06-08 09:19:32 -04:00
|
|
|
it('renders all managed group subscriptions', async function () {
|
2023-02-07 10:38:20 -05:00
|
|
|
renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
|
|
|
|
metaTags: [
|
|
|
|
{
|
|
|
|
name: 'ol-managedGroupSubscriptions',
|
|
|
|
value: managedGroupSubscriptions,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
2023-01-31 10:42:52 -05:00
|
|
|
|
|
|
|
const elements = screen.getAllByText('You are a', {
|
|
|
|
exact: false,
|
|
|
|
})
|
|
|
|
expect(elements.length).to.equal(2)
|
|
|
|
expect(elements[0].textContent).to.equal(
|
|
|
|
'You are a manager and member of the Professional group subscription GAS administered by you@example.com'
|
|
|
|
)
|
|
|
|
expect(elements[1].textContent).to.equal(
|
|
|
|
'You are a manager of the Collaborator group subscription GASWPLC administered by someone@example.com'
|
|
|
|
)
|
|
|
|
|
2023-06-08 09:19:32 -04:00
|
|
|
const links = screen.getAllByRole('link')
|
|
|
|
expect(links[1].getAttribute('href')).to.equal(
|
2023-01-31 10:42:52 -05:00
|
|
|
'/manage/groups/bcd567/members'
|
|
|
|
)
|
2023-06-08 09:19:32 -04:00
|
|
|
expect(links[2].getAttribute('href')).to.equal(
|
2023-01-31 10:42:52 -05:00
|
|
|
'/manage/groups/bcd567/managers'
|
|
|
|
)
|
2023-06-08 09:19:32 -04:00
|
|
|
expect(links[3].getAttribute('href')).to.equal('/metrics/groups/bcd567')
|
|
|
|
expect(links[5].getAttribute('href')).to.equal(
|
|
|
|
'/manage/groups/def456/members'
|
2023-01-31 10:42:52 -05:00
|
|
|
)
|
2023-06-08 09:19:32 -04:00
|
|
|
expect(links[6].getAttribute('href')).to.equal(
|
|
|
|
'/manage/groups/def456/managers'
|
2023-01-31 10:42:52 -05:00
|
|
|
)
|
2023-06-08 09:19:32 -04:00
|
|
|
expect(links[7].getAttribute('href')).to.equal('/metrics/groups/def456')
|
2023-01-31 10:42:52 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders nothing when there are no group memberships', function () {
|
2023-02-07 10:38:20 -05:00
|
|
|
renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />)
|
2023-01-31 10:42:52 -05:00
|
|
|
const elements = screen.queryAllByText('You are a', {
|
|
|
|
exact: false,
|
|
|
|
})
|
|
|
|
expect(elements.length).to.equal(0)
|
|
|
|
})
|
2023-11-06 06:01:43 -05:00
|
|
|
it('does not render the Manage group settings row when feature is turned off', function () {
|
|
|
|
expect(screen.queryByText('Manage group settings')).to.be.null
|
|
|
|
expect(screen.queryByText('Configure and manage SSO and Managed Users')).to
|
|
|
|
.be.null
|
|
|
|
})
|
|
|
|
it('renders the Manage group settings row when feature is turned on', async function () {
|
|
|
|
renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
|
|
|
|
metaTags: [
|
|
|
|
{
|
|
|
|
name: 'ol-managedGroupSubscriptions',
|
|
|
|
value: managedGroupSubscriptions2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
await screen.findAllByText('Manage group settings')
|
|
|
|
await screen.findAllByText('Configure and manage SSO and Managed Users')
|
|
|
|
})
|
|
|
|
it('renders the the correct subText for Manage Group settings row', async function () {
|
|
|
|
renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
|
|
|
|
metaTags: [
|
|
|
|
{
|
|
|
|
name: 'ol-managedGroupSubscriptions',
|
|
|
|
value: managedGroupSubscriptions2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
await screen.findAllByText('Configure and manage SSO and Managed Users')
|
|
|
|
|
|
|
|
renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
|
|
|
|
metaTags: [
|
|
|
|
{
|
|
|
|
name: 'ol-managedGroupSubscriptions',
|
|
|
|
value: managedGroupSubscriptions3,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
await screen.findAllByText('Configure and manage SSO')
|
|
|
|
renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
|
|
|
|
metaTags: [
|
|
|
|
{
|
|
|
|
name: 'ol-managedGroupSubscriptions',
|
|
|
|
value: managedGroupSubscriptions4,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
await screen.findAllByText('Turn on Managed Users')
|
|
|
|
})
|
2023-01-31 10:42:52 -05:00
|
|
|
})
|