first commit

This commit is contained in:
2025-04-24 13:11:28 +08:00
commit ff9c54d5e4
5960 changed files with 834111 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { render, screen } from '@testing-library/react'
import AcceptedInvite from '../../../../../../frontend/js/features/subscription/components/group-invite/accepted-invite'
import { expect } from 'chai'
describe('accepted group invite', function () {
it('renders', async function () {
window.metaAttributesCache.set('ol-inviterName', 'example@overleaf.com')
render(<AcceptedInvite />)
await screen.findByText(
'You have joined the group subscription managed by example@overleaf.com'
)
})
it('links to SSO enrollment page for SSO groups', async function () {
window.metaAttributesCache.set('ol-inviterName', 'example@overleaf.com')
window.metaAttributesCache.set('ol-groupSSOActive', true)
window.metaAttributesCache.set('ol-subscriptionId', 'group123')
render(<AcceptedInvite />)
const linkBtn = (await screen.findByRole('link', {
name: 'Done',
})) as HTMLLinkElement
expect(linkBtn.href).to.equal(
'https://www.test-overleaf.com/subscription/group123/sso_enrollment'
)
})
it('links to dash for non-SSO groups', async function () {
window.metaAttributesCache.set('ol-inviterName', 'example@overleaf.com')
render(<AcceptedInvite />)
const linkBtn = (await screen.findByRole('link', {
name: 'Done',
})) as HTMLLinkElement
expect(linkBtn.href).to.equal('https://www.test-overleaf.com/project')
})
})

View File

@@ -0,0 +1,120 @@
import { render, screen } from '@testing-library/react'
import { expect } from 'chai'
import GroupInvite from '../../../../../../frontend/js/features/subscription/components/group-invite/group-invite'
describe('group invite', function () {
const inviterName = 'example@overleaf.com'
beforeEach(function () {
window.metaAttributesCache.set('ol-inviterName', inviterName)
})
it('renders header', async function () {
render(<GroupInvite />)
await screen.findByText(inviterName)
screen.getByText(`has invited you to join a group subscription on Overleaf`)
expect(screen.queryByText('Email link expired, please request a new one.'))
.to.be.null
})
describe('when user has personal subscription', function () {
beforeEach(function () {
window.metaAttributesCache.set(
'ol-hasIndividualRecurlySubscription',
true
)
})
it('renders cancel personal subscription view', async function () {
render(<GroupInvite />)
await screen.findByText(
'You already have an individual subscription, would you like us to cancel this first before joining the group licence?'
)
})
describe('and in a managed group', function () {
// note: this should not be possible but managed user view takes priority over all
beforeEach(function () {
window.metaAttributesCache.set(
'ol-currentManagedUserAdminEmail',
'example@overleaf.com'
)
window.metaAttributesCache.set('ol-cannot-join-subscription', true)
})
it('renders managed user cannot join view', async function () {
render(<GroupInvite />)
await screen.findByText('You cant join this group subscription')
screen.getByText(
'Your Overleaf account is managed by your current group admin (example@overleaf.com). This means you cant join additional group subscriptions',
{ exact: false }
)
screen.getByRole('link', { name: 'Read more about Managed Users.' })
})
})
})
describe('when user does not have a personal subscription', function () {
beforeEach(function () {
window.metaAttributesCache.set(
'ol-hasIndividualRecurlySubscription',
false
)
window.metaAttributesCache.set('ol-inviteToken', 'token123')
})
it('does not render cancel personal subscription view', async function () {
render(<GroupInvite />)
await screen.findByText(
'Please click the button below to join the group subscription and enjoy the benefits of an upgraded Overleaf account'
)
})
})
describe('when the user is already a managed user in another group', function () {
beforeEach(function () {
window.metaAttributesCache.set(
'ol-currentManagedUserAdminEmail',
'example@overleaf.com'
)
window.metaAttributesCache.set('ol-cannot-join-subscription', true)
})
it('renders managed user cannot join view', async function () {
render(<GroupInvite />)
await screen.findByText(inviterName)
screen.getByText(
`has invited you to join a group subscription on Overleaf`
)
screen.getByText('You cant join this group subscription')
screen.getByText(
'Your Overleaf account is managed by your current group admin (example@overleaf.com). This means you cant join additional group subscriptions',
{ exact: false }
)
screen.getByRole('link', { name: 'Read more about Managed Users.' })
})
})
describe('expired', function () {
beforeEach(function () {
window.metaAttributesCache.set('ol-expired', true)
})
it('shows error notification when expired', async function () {
render(<GroupInvite />)
await screen.findByText('Email link expired, please request a new one.')
})
})
describe('join view', function () {
beforeEach(function () {
window.metaAttributesCache.set('ol-inviteToken', 'token123')
})
it('shows view to join group', async function () {
render(<GroupInvite />)
await screen.findByText(
'Please click the button below to join the group subscription and enjoy the benefits of an upgraded Overleaf account'
)
})
})
})

View File

@@ -0,0 +1,48 @@
import { expect } from 'chai'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import HasIndividualRecurlySubscription from '../../../../../../frontend/js/features/subscription/components/group-invite/has-individual-recurly-subscription'
import sinon from 'sinon'
import fetchMock from 'fetch-mock'
describe('group invite', function () {
describe('user has a personal subscription', function () {
afterEach(function () {
fetchMock.removeRoutes().clearHistory()
})
it('shows option to cancel subscription', async function () {
render(<HasIndividualRecurlySubscription setView={() => {}} />)
await screen.findByText(
'You already have an individual subscription, would you like us to cancel this first before joining the group licence?'
)
screen.getByRole('button', { name: 'Not now' })
screen.getByRole('button', { name: 'Cancel your subscription' })
})
it('handles subscription cancellation and calls to change invite view', async function () {
fetchMock.post('/user/subscription/cancel', 200)
const setView = sinon.stub()
render(<HasIndividualRecurlySubscription setView={setView} />)
const button = await screen.findByRole('button', {
name: 'Cancel your subscription',
})
fireEvent.click(button)
await waitFor(() => {
expect(setView).to.have.been.calledOnce
})
})
it('shows error message when cancelling subscription fails', async function () {
render(<HasIndividualRecurlySubscription setView={() => {}} />)
const button = await screen.findByRole('button', {
name: 'Cancel your subscription',
})
fireEvent.click(button)
await waitFor(() => {
screen.getByText(
'Something went wrong canceling your subscription. Please contact support.'
)
})
})
})
})

View File

@@ -0,0 +1,48 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { expect } from 'chai'
import JoinGroup from '../../../../../../frontend/js/features/subscription/components/group-invite/join-group'
import fetchMock from 'fetch-mock'
import sinon from 'sinon'
describe('join group', function () {
const inviteToken = 'token123'
beforeEach(function () {
window.metaAttributesCache.set('ol-inviteToken', inviteToken)
})
afterEach(function () {
fetchMock.removeRoutes().clearHistory()
})
it('shows option to join subscription', async function () {
render(<JoinGroup setView={() => {}} />)
await screen.findByText(
'Please click the button below to join the group subscription and enjoy the benefits of an upgraded Overleaf account'
)
screen.getByRole('link', { name: 'Not now' })
screen.getByRole('button', { name: 'Accept invitation' })
})
it('handles success when accepting invite', async function () {
fetchMock.put(`/subscription/invites/${inviteToken}`, 200)
const setView = sinon.stub()
render(<JoinGroup setView={setView} />)
const button = await screen.getByRole('button', {
name: 'Accept invitation',
})
fireEvent.click(button)
await waitFor(() => {
expect(setView).to.have.been.calledOnce
})
})
it('handles errors when accepting invite', async function () {
render(<JoinGroup setView={() => {}} />)
const button = await screen.getByRole('button', {
name: 'Accept invitation',
})
fireEvent.click(button)
await waitFor(() => {
screen.getByText('Sorry, something went wrong')
})
})
})

View File

@@ -0,0 +1,21 @@
import { render, screen } from '@testing-library/react'
import ManagedUserCannotJoin from '../../../../../../frontend/js/features/subscription/components/group-invite/managed-user-cannot-join'
describe('ManagedUserCannotJoin', function () {
beforeEach(function () {
window.metaAttributesCache.set(
'ol-currentManagedUserAdminEmail',
'example@overleaf.com'
)
window.metaAttributesCache.set('ol-cannot-join-subscription', true)
})
it('renders the component', async function () {
render(<ManagedUserCannotJoin />)
await screen.findByText(
'Your Overleaf account is managed by your current group admin (example@overleaf.com). This means you cant join additional group subscriptions',
{ exact: false }
)
screen.getByRole('link', { name: 'Read more about Managed Users.' })
})
})