| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849 |
- import { expect } from 'chai'
- import sinon from 'sinon'
- import {
- fireEvent,
- render,
- screen,
- waitForElementToBeRemoved,
- within,
- } from '@testing-library/react'
- import fetchMock from 'fetch-mock'
- import { merge, cloneDeep } from 'lodash'
- import {
- professionalUserData,
- unconfirmedUserData,
- unconfirmedCommonsUserData,
- } from '../../settings/fixtures/test-user-email-data'
- import {
- notification,
- notificationsInstitution,
- } from '../fixtures/notifications-data'
- import Common from '../../../../../frontend/js/features/project-list/components/notifications/groups/common'
- import Institution from '../../../../../frontend/js/features/project-list/components/notifications/groups/institution'
- import ConfirmEmail from '../../../../../frontend/js/features/project-list/components/notifications/groups/confirm-email'
- import ReconfirmationInfo from '../../../../../frontend/js/features/project-list/components/notifications/groups/affiliation/reconfirmation-info'
- import { ProjectListProvider } from '../../../../../frontend/js/features/project-list/context/project-list-context'
- import {
- Notification,
- Institution as InstitutionType,
- } from '../../../../../types/project/dashboard/notification'
- import { DeepPartial } from '../../../../../types/utils'
- import { Project } from '../../../../../types/project/dashboard/api'
- import GroupsAndEnterpriseBanner from '../../../../../frontend/js/features/project-list/components/notifications/groups-and-enterprise-banner'
- import localStorage from '../../../../../frontend/js/infrastructure/local-storage'
- import * as useLocationModule from '../../../../../frontend/js/shared/hooks/use-location'
- const renderWithinProjectListProvider = (Component: React.ComponentType) => {
- render(<Component />, {
- wrapper: ({ children }) => (
- <ProjectListProvider>
- <ul className="list-unstyled">{children}</ul>
- </ProjectListProvider>
- ),
- })
- }
- describe('<UserNotifications />', function () {
- const exposedSettings = {
- samlInitPath: '/fakeSaml/',
- appName: 'Overleaf',
- }
- beforeEach(function () {
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- fetchMock.reset()
- // at least one project is required to show some notifications
- const projects = [{}] as Project[]
- fetchMock.post(/\/api\/project/, {
- status: 200,
- body: {
- projects,
- totalSize: projects.length,
- },
- })
- })
- afterEach(function () {
- window.metaAttributesCache = new Map()
- fetchMock.reset()
- })
- describe('<Common>', function () {
- beforeEach(function () {
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- window.metaAttributesCache.set('ol-ExposedSettings', exposedSettings)
- })
- afterEach(function () {
- window.metaAttributesCache = new Map()
- fetchMock.reset()
- })
- it('accepts project invite', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey: 'notification_project_invite',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- const deleteMock = fetchMock.delete(
- `/notifications/${reconfiguredNotification._id}`,
- 200
- )
- const acceptMock = fetchMock.post(
- `project/${notification.messageOpts.projectId}/invite/token/${notification.messageOpts.token}/accept`,
- 200
- )
- screen.getByRole('alert')
- screen.getByText(/would like you to join/i)
- const joinBtn = screen.getByRole('button', {
- name: /join project/i,
- }) as HTMLButtonElement
- expect(joinBtn.disabled).to.be.false
- fireEvent.click(joinBtn)
- expect(joinBtn.disabled).to.be.true
- await waitForElementToBeRemoved(() =>
- screen.getByRole('button', { name: /joining/i })
- )
- expect(acceptMock.called()).to.be.true
- screen.getByText(/joined/i)
- expect(screen.queryByRole('button', { name: /join project/i })).to.be.null
- const openProject = screen.getByRole('link', { name: /open project/i })
- expect(openProject.getAttribute('href')).to.equal(
- `/project/${notification.messageOpts.projectId}`
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(deleteMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('fails to accept project invite', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey: 'notification_project_invite',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.post(
- `project/${notification.messageOpts.projectId}/invite/token/${notification.messageOpts.token}/accept`,
- 500
- )
- screen.getByRole('alert')
- screen.getByText(/would like you to join/i)
- const joinBtn = screen.getByRole('button', {
- name: /join project/i,
- }) as HTMLButtonElement
- fireEvent.click(joinBtn)
- await waitForElementToBeRemoved(() =>
- screen.getByRole('button', { name: /joining/i })
- )
- expect(fetchMock.called()).to.be.true
- screen.getByRole('button', { name: /join project/i })
- expect(screen.queryByRole('link', { name: /open project/i })).to.be.null
- })
- it('shows WFH2020', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey: 'wfh_2020_upgrade_offer',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.delete(`/notifications/${reconfiguredNotification._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/your free WFH2020 upgrade came to an end on/i)
- const viewLink = screen.getByRole('link', { name: /view/i })
- expect(viewLink.getAttribute('href')).to.equal(
- 'https://www.overleaf.com/events/wfh2020'
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows IP matched affiliation with SSO enabled', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey: 'notification_ip_matched_affiliation',
- messageOpts: { ssoEnabled: true },
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.delete(`/notifications/${reconfiguredNotification._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/it looks like you’re at/i)
- screen.getByText(/you can now log in through your institution/i)
- screen.getByText(
- /link an institutional email address to your account to get started/i
- )
- const findOutMore = screen.getByRole('link', { name: /find out more/i })
- expect(findOutMore.getAttribute('href')).to.equal(
- 'https://www.overleaf.com/learn/how-to/Institutional_Login'
- )
- const linkAccount = screen.getByRole('link', { name: /link account/i })
- expect(linkAccount.getAttribute('href')).to.equal(
- `${exposedSettings.samlInitPath}?university_id=${notification.messageOpts.institutionId}&auto=/project`
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows IP matched affiliation with SSO disabled', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey: 'notification_ip_matched_affiliation',
- messageOpts: { ssoEnabled: false },
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.delete(`/notifications/${reconfiguredNotification._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/it looks like you’re at/i)
- screen.getByText(/did you know that/i)
- screen.getByText(
- /add an institutional email address to claim your features/i
- )
- const addAffiliation = screen.getByRole('link', {
- name: /add affiliation/i,
- })
- expect(addAffiliation.getAttribute('href')).to.equal(`/user/settings`)
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows tpds file limit', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- templateKey: 'notification_tpds_file_limit',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- screen.getByRole('alert')
- screen.getByText(/file limit/i)
- screen.getByText(
- /please decrease the size of your project to prevent further errors/i
- )
- const accountSettings = screen.getByRole('link', {
- name: /account settings/i,
- })
- expect(accountSettings.getAttribute('href')).to.equal('/user/settings')
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows dropbox duplicate project names warning', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey: 'notification_dropbox_duplicate_project_names',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.delete(`/notifications/${reconfiguredNotification._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/you have more than one project called/i)
- screen.getByText(/make your project names unique/i)
- const learnMore = screen.getByRole('link', { name: /learn more/i })
- expect(learnMore.getAttribute('href')).to.equal(
- '/learn/how-to/Dropbox_Synchronization#Troubleshooting'
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows dropbox unlinked tue to lapsed reconfirmation', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- templateKey:
- 'notification_dropbox_unlinked_due_to_lapsed_reconfirmation',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.delete(`/notifications/${reconfiguredNotification._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/your Dropbox account has been unlinked/i)
- screen.getByText(
- /confirm you are still at the institution and on their license, or upgrade your account in order to relink your dropbox account/i
- )
- const learnMore = screen.getByRole('link', { name: /learn more/i })
- expect(learnMore.getAttribute('href')).to.equal(
- '/learn/how-to/Institutional_Email_Reconfirmation'
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows non specific notification', async function () {
- const reconfiguredNotification: DeepPartial<Notification> = {
- _id: 1,
- html: 'unspecific message',
- }
- window.metaAttributesCache.set('ol-notifications', [
- merge(cloneDeep(notification), reconfiguredNotification),
- ])
- renderWithinProjectListProvider(Common)
- await fetchMock.flush(true)
- fetchMock.delete(`/notifications/${reconfiguredNotification._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(reconfiguredNotification.html!)
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- })
- describe('<Institution>', function () {
- beforeEach(function () {
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- window.metaAttributesCache.set('ol-ExposedSettings', exposedSettings)
- fetchMock.reset()
- })
- afterEach(function () {
- fetchMock.reset()
- })
- it('shows sso available', function () {
- const institution: DeepPartial<InstitutionType> = {
- templateKey: 'notification_institution_sso_available',
- }
- window.metaAttributesCache.set('ol-notificationsInstitution', [
- { ...notificationsInstitution, ...institution },
- ])
- render(<Institution />)
- screen.getByRole('alert')
- screen.getByText(/you can now link/i)
- screen.getByText(/doing this will allow you to log in/i)
- const learnMore = screen.getByRole('link', { name: /learn more/i })
- expect(learnMore.getAttribute('href')).to.equal(
- '/learn/how-to/Institutional_Login'
- )
- const action = screen.getByRole('link', { name: /link account/i })
- expect(action.getAttribute('href')).to.equal(
- `${exposedSettings.samlInitPath}?university_id=${notificationsInstitution.institutionId}&auto=/project&email=${notificationsInstitution.email}`
- )
- })
- it('shows sso linked', function () {
- const institution: DeepPartial<InstitutionType> = {
- _id: 1,
- templateKey: 'notification_institution_sso_linked',
- }
- window.metaAttributesCache.set('ol-notificationsInstitution', [
- { ...notificationsInstitution, ...institution },
- ])
- render(<Institution />)
- fetchMock.delete(`/notifications/${institution._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/has been linked to your/i)
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows sso non canonical', function () {
- const institution: DeepPartial<InstitutionType> = {
- _id: 1,
- templateKey: 'notification_institution_sso_non_canonical',
- }
- window.metaAttributesCache.set('ol-notificationsInstitution', [
- { ...notificationsInstitution, ...institution },
- ])
- render(<Institution />)
- fetchMock.delete(`/notifications/${institution._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/you’ve tried to log in with/i)
- screen.getByText(
- /in order to match your institutional metadata, your account is associated with/i
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows sso already registered', function () {
- const institution: DeepPartial<InstitutionType> = {
- _id: 1,
- templateKey: 'notification_institution_sso_already_registered',
- }
- window.metaAttributesCache.set('ol-notificationsInstitution', [
- { ...notificationsInstitution, ...institution },
- ])
- render(<Institution />)
- fetchMock.delete(`/notifications/${institution._id}`, 200)
- screen.getByRole('alert')
- screen.getByText(/which is already registered with/i)
- const action = screen.getByRole('link', { name: /find out more/i })
- expect(action.getAttribute('href')).to.equal(
- '/learn/how-to/Institutional_Login'
- )
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('shows sso error', function () {
- const institution: DeepPartial<InstitutionType> = {
- templateKey: 'notification_institution_sso_error',
- error: {
- message: 'fake message',
- tryAgain: true,
- },
- }
- window.metaAttributesCache.set('ol-notificationsInstitution', [
- { ...notificationsInstitution, ...institution },
- ])
- render(<Institution />)
- screen.getByRole('alert')
- screen.getByText(/something went wrong/i)
- screen.getByText(institution.error!.message!)
- screen.getByText(/please try again/i)
- const closeBtn = screen.getByRole('button', { name: /close/i })
- fireEvent.click(closeBtn)
- expect(screen.queryByRole('alert')).to.be.null
- })
- })
- describe('<ConfirmEmail/>', function () {
- beforeEach(async function () {
- window.metaAttributesCache.set('ol-ExposedSettings', {
- emailConfirmationDisabled: false,
- })
- window.metaAttributesCache.set('ol-userEmails', [unconfirmedUserData])
- })
- afterEach(function () {
- fetchMock.reset()
- })
- it('sends successfully', async function () {
- renderWithinProjectListProvider(ConfirmEmail)
- await fetchMock.flush(true)
- fetchMock.post('/user/emails/resend_confirmation', 200)
- const email = unconfirmedUserData.email
- const notificationBody = screen.getByTestId('pro-notification-body')
- expect(notificationBody.textContent).to.contain(
- `Please confirm your email ${email} by clicking on the link in the confirmation email`
- )
- const resendButton = screen.getByRole('button', { name: /resend/i })
- fireEvent.click(resendButton)
- expect(screen.queryByRole('button', { name: /resend/i })).to.be.null
- await waitForElementToBeRemoved(() =>
- screen.getByText(/resending confirmation email/i)
- )
- expect(fetchMock.called()).to.be.true
- expect(screen.queryByRole('alert')).to.be.null
- })
- it('fails to send', async function () {
- renderWithinProjectListProvider(ConfirmEmail)
- await fetchMock.flush(true)
- fetchMock.post('/user/emails/resend_confirmation', 500)
- const resendButton = screen.getByRole('button', { name: /resend/i })
- fireEvent.click(resendButton)
- await waitForElementToBeRemoved(() =>
- screen.getByText(/resending confirmation email/i)
- )
- expect(fetchMock.called()).to.be.true
- screen.getByText(/something went wrong/i)
- })
- it('shows notification for commons account', async function () {
- window.metaAttributesCache.set('ol-userEmails', [
- unconfirmedCommonsUserData,
- ])
- renderWithinProjectListProvider(ConfirmEmail)
- await fetchMock.flush(true)
- const alert = screen.getByRole('alert')
- const email = unconfirmedCommonsUserData.email
- const notificationBody = within(alert).getByTestId('notification-body')
- expect(notificationBody.textContent).to.contain(
- 'You are one step away from accessing Overleaf Professional features'
- )
- expect(notificationBody.textContent).to.contain(
- `Overleaf has an Overleaf subscription. Click the confirmation link sent to ${email} to upgrade to Overleaf Professional`
- )
- })
- })
- describe('<Affiliation/>', function () {
- let assignStub: sinon.SinonStub
- beforeEach(function () {
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- window.metaAttributesCache.set('ol-ExposedSettings', exposedSettings)
- assignStub = sinon.stub()
- this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
- assign: assignStub,
- reload: sinon.stub(),
- })
- fetchMock.reset()
- })
- afterEach(function () {
- window.metaAttributesCache = new Map()
- this.locationStub.restore()
- fetchMock.reset()
- })
- it('shows reconfirm message with SSO disabled', async function () {
- window.metaAttributesCache.set('ol-allInReconfirmNotificationPeriods', [
- { ...professionalUserData, samlProviderId: 'Saml Provider' },
- ])
- render(<ReconfirmationInfo />)
- screen.getByRole('alert')
- screen.getByText(
- /take a moment to confirm your institutional email address/i
- )
- const removeLink = screen.getByRole('link', { name: /remove it/i })
- expect(removeLink.getAttribute('href')).to.equal(
- `/user/settings?remove=${professionalUserData.email}`
- )
- const learnMore = screen.getByRole('link', { name: /learn more/i })
- expect(learnMore.getAttribute('href')).to.equal(
- '/learn/how-to/Institutional_Email_Reconfirmation'
- )
- const sendReconfirmationMock = fetchMock.post(
- '/user/emails/send-reconfirmation',
- 200
- )
- fireEvent.click(
- screen.getByRole('button', { name: /confirm affiliation/i })
- )
- await waitForElementToBeRemoved(() => screen.getByText(/sending/i))
- screen.getByText(/check your email inbox to confirm/i)
- expect(screen.queryByRole('button', { name: /confirm affiliation/i })).to
- .be.null
- expect(screen.queryByRole('link', { name: /remove it/i })).to.be.null
- expect(screen.queryByRole('link', { name: /learn more/i })).to.be.null
- expect(sendReconfirmationMock.called()).to.be.true
- fireEvent.click(
- screen.getByRole('button', { name: /resend confirmation email/i })
- )
- await waitForElementToBeRemoved(() => screen.getByText(/sending/i))
- expect(sendReconfirmationMock.calls()).to.have.lengthOf(2)
- })
- it('shows reconfirm message with SSO enabled', async function () {
- window.metaAttributesCache.set('ol-allInReconfirmNotificationPeriods', [
- merge(cloneDeep(professionalUserData), {
- affiliation: { institution: { ssoEnabled: true } },
- }),
- ])
- render(<ReconfirmationInfo />)
- fireEvent.click(
- screen.getByRole('button', { name: /confirm affiliation/i })
- )
- sinon.assert.calledOnce(assignStub)
- sinon.assert.calledWithMatch(
- assignStub,
- `${exposedSettings.samlInitPath}?university_id=${professionalUserData.affiliation.institution.id}&reconfirm=/project`
- )
- })
- it('shows success reconfirmation message', function () {
- window.metaAttributesCache.set('ol-userEmails', [
- { ...professionalUserData, samlProviderId: 'Saml Provider' },
- ])
- window.metaAttributesCache.set('ol-reconfirmedViaSAML', 'Saml Provider')
- const { rerender } = render(<ReconfirmationInfo />)
- screen.getByRole('alert')
- screen.getByText(professionalUserData.affiliation!.institution!.name!)
- screen.getByText(/affiliation is confirmed/i)
- window.metaAttributesCache.set('ol-reconfirmedViaSAML', '')
- rerender(<ReconfirmationInfo />)
- expect(screen.queryByRole('alert')).to.be.null
- })
- })
- describe('<GroupsAndEnterpriseBanner />', function () {
- beforeEach(function () {
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- localStorage.clear()
- fetchMock.reset()
- // at least one project is required to show some notifications
- const projects = [{}] as Project[]
- fetchMock.post(/\/api\/project/, {
- status: 200,
- body: {
- projects,
- totalSize: projects.length,
- },
- })
- window.metaAttributesCache.set(
- 'ol-groupsAndEnterpriseBannerVariant',
- 'did-you-know'
- )
- })
- afterEach(function () {
- fetchMock.reset()
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- })
- it('does not show the banner for users that are in group or are affiliated', async function () {
- window.metaAttributesCache.set('ol-showGroupsAndEnterpriseBanner', false)
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- expect(screen.queryByRole('link', { name: 'Contact Sales' })).to.be.null
- })
- it('shows the banner for users that have dismissed the previous banners', async function () {
- window.metaAttributesCache.set('ol-showGroupsAndEnterpriseBanner', true)
- localStorage.setItem('has_dismissed_groups_and_enterprise_banner', true)
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- expect(screen.queryByRole('link', { name: 'Contact Sales' })).to.not.be
- .null
- })
- it('shows the banner for users that have dismissed the banner more than 30 days ago', async function () {
- const dismissed = new Date()
- dismissed.setDate(dismissed.getDate() - 31) // 31 days
- window.metaAttributesCache.set('ol-showGroupsAndEnterpriseBanner', true)
- localStorage.setItem(
- 'has_dismissed_groups_and_enterprise_banner',
- dismissed
- )
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- expect(screen.queryByRole('link', { name: 'Contact Sales' })).to.not.be
- .null
- })
- it('does not show the banner for users that have dismissed the banner within the last 30 days', async function () {
- const dismissed = new Date()
- dismissed.setDate(dismissed.getDate() - 29) // 29 days
- window.metaAttributesCache.set('ol-showGroupsAndEnterpriseBanner', true)
- localStorage.setItem(
- 'has_dismissed_groups_and_enterprise_banner',
- dismissed
- )
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- expect(screen.queryByRole('link', { name: 'Contact Sales' })).to.be.null
- })
- describe('users that are not in group and are not affiliated', function () {
- beforeEach(function () {
- localStorage.clear()
- fetchMock.reset()
- // at least one project is required to show some notifications
- const projects = [{}] as Project[]
- fetchMock.post(/\/api\/project/, {
- status: 200,
- body: {
- projects,
- totalSize: projects.length,
- },
- })
- window.metaAttributesCache.set('ol-showGroupsAndEnterpriseBanner', true)
- })
- afterEach(function () {
- fetchMock.reset()
- window.metaAttributesCache = window.metaAttributesCache || new Map()
- })
- after(function () {
- localStorage.clear()
- })
- it('will show the correct text for the `did-you-know` variant', async function () {
- window.metaAttributesCache.set(
- 'ol-groupsAndEnterpriseBannerVariant',
- 'did-you-know'
- )
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- screen.getByText(
- 'Did you know that Overleaf offers group and organization-wide subscription options? Request information or a quote.'
- )
- const link = screen.getByRole('link', { name: 'Contact Sales' })
- expect(link.getAttribute('href')).to.equal(`/for/contact-sales-1`)
- })
- it('will show the correct text for the `on-premise` variant', async function () {
- window.metaAttributesCache.set(
- 'ol-groupsAndEnterpriseBannerVariant',
- 'on-premise'
- )
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- screen.getByText(
- 'Overleaf On-Premises: Does your company want to keep its data within its firewall? Overleaf offers Server Pro, an on-premises solution for companies. Get in touch to learn more.'
- )
- const link = screen.getByRole('link', { name: 'Contact Sales' })
- expect(link.getAttribute('href')).to.equal(`/for/contact-sales-2`)
- })
- it('will show the correct text for the `people` variant', async function () {
- window.metaAttributesCache.set(
- 'ol-groupsAndEnterpriseBannerVariant',
- 'people'
- )
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- screen.getByText(
- 'Other people at your company may already be using Overleaf. Save money with Overleaf group and company-wide subscriptions. Request more information.'
- )
- const link = screen.getByRole('link', { name: 'Contact Sales' })
- expect(link.getAttribute('href')).to.equal(`/for/contact-sales-3`)
- })
- it('will show the correct text for the `FOMO` variant', async function () {
- window.metaAttributesCache.set(
- 'ol-groupsAndEnterpriseBannerVariant',
- 'FOMO'
- )
- renderWithinProjectListProvider(GroupsAndEnterpriseBanner)
- await fetchMock.flush(true)
- screen.getByText(
- 'Why do Fortune 500 companies and top research institutions trust Overleaf to streamline their collaboration? Get in touch to learn more.'
- )
- const link = screen.getByRole('link', { name: 'Contact Sales' })
- expect(link.getAttribute('href')).to.equal(`/for/contact-sales-4`)
- })
- })
- })
- })
|