Merge pull request #18161 from overleaf/jel-subscription-dash-admin

[web] Subscription dash message when viewing as admin

GitOrigin-RevId: 699a523d7ac8d1a71e9ba14c7b8a66b39142958a
This commit is contained in:
Jessica Lawshe
2024-05-31 08:04:23 +00:00
committed by Copybot
parent c85f4ab5e5
commit cbe5cefb9a
5 changed files with 156 additions and 52 deletions
@@ -1,49 +1,78 @@
import { expect } from 'chai'
import { screen } from '@testing-library/react'
import {
groupActiveSubscription,
groupActiveSubscriptionWithPendingLicenseChange,
} from '../../fixtures/subscriptions'
import ManagedGroupSubscriptions from '../../../../../../frontend/js/features/subscription/components/dashboard/managed-group-subscriptions'
import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
import {
cleanUpContext,
renderWithSubscriptionDashContext,
} from '../../helpers/render-with-subscription-dash-context'
import { UserId } from '../../../../../../types/user'
function getManagedGroupSubscriptions(
groupSSO: boolean | null,
managedUsers: boolean | null
): ManagedGroupSubscription[] {
const subscriptionOne = {
...groupActiveSubscription,
_id: 'bcd567',
userIsGroupMember: true,
planLevelName: 'Professional',
admin_id: {
id: 'abc123abc123' as UserId,
email: 'you@example.com',
},
features: {
groupSSO,
managedUsers,
},
teamName: 'GAS',
}
const subscriptionTwo = {
...groupActiveSubscriptionWithPendingLicenseChange,
_id: 'def456',
userIsGroupMember: false,
planLevelName: 'Collaborator',
admin_id: {
id: 'bcd456bcd456' as UserId,
email: 'someone@example.com',
},
features: {
groupSSO,
managedUsers,
},
teamName: 'GASWPLC',
}
return [subscriptionOne, subscriptionTwo]
const subscriptionMemberAndAdmin = {
_id: 'group2abc',
userIsGroupMember: true,
planLevelName: 'Collaborator',
admin_id: {
email: 'admin@example.com',
},
features: {
groupSSO,
managedUsers,
},
teamName: 'Testing',
}
const subscriptionAdmin = {
_id: 'group123abc',
userIsGroupMember: false,
planLevelName: 'Collaborator',
admin_id: {
email: 'admin@example.com',
},
features: {
groupSSO,
managedUsers,
},
teamName: 'Testing Another',
}
return [
subscriptionOne,
subscriptionTwo,
subscriptionMemberAndAdmin,
subscriptionAdmin,
]
}
const managedGroupSubscriptions: ManagedGroupSubscription[] =
@@ -69,18 +98,25 @@ describe('<ManagedGroupSubscriptions />', function () {
name: 'ol-managedGroupSubscriptions',
value: managedGroupSubscriptions,
},
{ name: 'ol-usersEmail', value: 'admin@example.com' },
],
})
const elements = screen.getAllByText('You are a', {
exact: false,
})
expect(elements.length).to.equal(2)
expect(elements.length).to.equal(4)
expect(elements[0].textContent).to.equal(
'You are a manager and member of the Professional group subscription GAS administered by you@example.com'
'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'
'You are a manager of the Collaborator group subscription GASWPLC administered by someone@example.com.'
)
expect(elements[2].textContent).to.equal(
'You are a manager and member of the Collaborator group subscription Testing administered by you (admin@example.com).'
)
expect(elements[3].textContent).to.equal(
'You are a manager of the Collaborator group subscription Testing Another administered by you (admin@example.com).'
)
const links = screen.getAllByRole('link')
@@ -98,6 +134,22 @@ describe('<ManagedGroupSubscriptions />', function () {
'/manage/groups/def456/managers'
)
expect(links[7].getAttribute('href')).to.equal('/metrics/groups/def456')
expect(links[9].getAttribute('href')).to.equal(
'/manage/groups/group2abc/members'
)
expect(links[10].getAttribute('href')).to.equal(
'/manage/groups/group2abc/managers'
)
expect(links[11].getAttribute('href')).to.equal('/metrics/groups/group2abc')
expect(links[13].getAttribute('href')).to.equal(
'/manage/groups/group123abc/members'
)
expect(links[14].getAttribute('href')).to.equal(
'/manage/groups/group123abc/managers'
)
expect(links[15].getAttribute('href')).to.equal(
'/metrics/groups/group123abc'
)
})
it('renders nothing when there are no group memberships', function () {