| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652 |
- import { expect } from 'chai'
- import sinon from 'sinon'
- import { screen, Screen, fireEvent, waitFor } from '@testing-library/react'
- import fetchMock, { CallLog } from 'fetch-mock'
- import userEvent from '@testing-library/user-event'
- import ShareProjectModal from '../../../../../frontend/js/features/share-project-modal/components/share-project-modal'
- import { renderWithEditorContext } from '../../../helpers/render-with-context'
- import {
- makeProjectProvider,
- projectDefaults,
- USER_EMAIL,
- USER_ID,
- } from '../../../helpers/editor-providers'
- import { location } from '@/shared/components/location'
- import { useProjectContext } from '@/shared/context/project-context'
- import {
- ProjectMember,
- ProjectMetadata,
- } from '@/shared/context/types/project-metadata'
- import { UserId } from '@ol-types/user'
- import { PublicAccessLevel } from '@ol-types/public-access-level'
- async function changePrivilegeLevel(
- screen: Screen,
- { current, next }: { current: string; next: string }
- ) {
- const select = screen.getByDisplayValue(current)
- fireEvent.click(select)
- const option = screen.getByRole('option', {
- name: next,
- })
- fireEvent.click(option)
- }
- const testProjectOverrides: Partial<ProjectMetadata> = {
- _id: 'test-project',
- name: 'Test Project',
- features: {
- collaborators: 10,
- compileGroup: 'standard',
- },
- owner: {
- _id: USER_ID,
- email: USER_EMAIL,
- first_name: 'Test',
- last_name: 'Owner',
- privileges: 'owner',
- signUpDate: new Date('2025-07-07').toISOString(),
- },
- }
- const shareModalProjectDefaults: ProjectMetadata = Object.assign(
- {},
- projectDefaults,
- testProjectOverrides
- )
- function createContextProps(projectOverrides?: Partial<ProjectMetadata>) {
- const project = Object.assign({}, shareModalProjectDefaults, projectOverrides)
- return { providers: { ProjectProvider: makeProjectProvider(project) } }
- }
- describe('<ShareProjectModal/>', function () {
- const contacts = [
- // user with edited name
- {
- type: 'user',
- email: 'test-user@example.com',
- first_name: 'Test',
- last_name: 'User',
- name: 'Test User',
- },
- // user with default name (email prefix)
- {
- type: 'user',
- email: 'test@example.com',
- first_name: 'test',
- },
- // no last name
- {
- type: 'user',
- first_name: 'Eratosthenes',
- email: 'eratosthenes@example.com',
- },
- // more users
- {
- type: 'user',
- first_name: 'Claudius',
- last_name: 'Ptolemy',
- email: 'ptolemy@example.com',
- },
- {
- type: 'user',
- first_name: 'Abd al-Rahman',
- last_name: 'Al-Sufi',
- email: 'al-sufi@example.com',
- },
- {
- type: 'user',
- first_name: 'Nicolaus',
- last_name: 'Copernicus',
- email: 'copernicus@example.com',
- },
- ]
- const modalProps = {
- show: true,
- handleHide: sinon.stub(),
- handleOpen: sinon.stub(),
- }
- beforeEach(function () {
- this.locationWrapperSandbox = sinon.createSandbox()
- this.locationWrapperStub = this.locationWrapperSandbox.stub(location)
- fetchMock.get('/user/contacts', { contacts })
- window.metaAttributesCache.set('ol-user', { allowedFreeTrial: true })
- window.metaAttributesCache.set('ol-showUpgradePrompt', true)
- window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
- })
- afterEach(function () {
- this.locationWrapperSandbox.restore()
- fetchMock.removeRoutes().clearHistory()
- })
- it('renders the modal', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- await screen.findByText('Share Project')
- })
- it('calls handleHide when a Close button is pressed', async function () {
- const handleHide = sinon.stub()
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} handleHide={handleHide} />,
- createContextProps()
- )
- const closeButton = screen.getByRole('button', { name: 'Close dialog' })
- await userEvent.click(closeButton)
- expect(handleHide.callCount).to.equal(1)
- })
- it('handles access level "private"', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'private' })
- )
- await screen.findByText('Link sharing is off')
- await screen.findByRole('button', { name: 'Turn on link sharing' })
- expect(screen.queryByText('Anyone with this link can view this project')).to
- .be.null
- expect(screen.queryByText('Anyone with this link can edit this project')).to
- .be.null
- })
- it('handles access level "tokenBased"', async function () {
- const tokens = {
- readAndWrite: '6862414195fwtbrtrdtskb',
- readAndWritePrefix: '6862414195',
- readOnly: 'wrnjfzkysqkr',
- readAndWriteHashPrefix: 'taEVki',
- readOnlyHashPrefix: 'j2xYbL',
- }
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, tokens)
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- await screen.findByText('Link sharing is on')
- await screen.findByRole('button', { name: 'Turn off link sharing' })
- expect(screen.queryByText('Anyone with this link can view this project'))
- .not.to.be.null
- expect(screen.queryByText('Anyone with this link can edit this project'))
- .not.to.be.null
- screen.getByText(
- `https://www.test-overleaf.com/${tokens.readAndWrite}#${tokens.readAndWriteHashPrefix}`
- )
- screen.getByText(
- `https://www.test-overleaf.com/read/${tokens.readOnly}#${tokens.readOnlyHashPrefix}`
- )
- })
- it('handles legacy access level "readAndWrite"', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'readAndWrite' })
- )
- await screen.findByText(
- 'This project is public and can be edited by anyone with the URL.'
- )
- await screen.findByRole('button', { name: 'Make private' })
- })
- it('handles legacy access level "readOnly"', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'readOnly' })
- )
- await screen.findByText(
- 'This project is public and can be viewed but not edited by anyone with the URL'
- )
- await screen.findByRole('button', { name: 'Make private' })
- })
- it('displays actions for project-owners', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- const invites: ProjectMember[] = [
- {
- _id: 'invited-author' as UserId,
- email: 'invited-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Invited',
- last_name: 'Author',
- },
- ]
- // render as project owner: actions should be present
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', invites })
- )
- await screen.findByRole('button', { name: 'Turn off link sharing' })
- await screen.findByRole('button', { name: 'Resend' })
- })
- it('hides actions from non-project-owners when link sharing on', async function () {
- const invites: ProjectMember[] = [
- {
- _id: 'invited-author' as UserId,
- email: 'invited-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Invited',
- last_name: 'Author',
- },
- ]
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps({ publicAccessLevel: 'tokenBased', invites }),
- user: {
- id: 'non-project-owner' as UserId,
- email: 'non-project-owner@example.com',
- },
- })
- await screen.findByText(
- 'To change access permissions, please ask the project owner'
- )
- expect(screen.queryByRole('button', { name: 'Turn off link sharing' })).to
- .be.null
- expect(screen.queryByRole('button', { name: 'Turn on link sharing' })).to.be
- .null
- expect(screen.queryByRole('button', { name: 'Resend' })).to.be.null
- })
- it('hides actions from non-project-owners when link sharing off', async function () {
- const invites: ProjectMember[] = [
- {
- _id: 'invited-author' as UserId,
- email: 'invited-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Invited',
- last_name: 'Author',
- },
- ]
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps({ publicAccessLevel: 'private', invites }),
- user: {
- id: 'non-project-owner' as UserId,
- email: 'non-project-owner@example.com',
- },
- })
- await screen.findByText(
- 'To add more collaborators or turn on link sharing, please ask the project owner'
- )
- expect(screen.queryByRole('button', { name: 'Turn off link sharing' })).to
- .be.null
- expect(screen.queryByRole('button', { name: 'Turn on link sharing' })).to.be
- .null
- expect(screen.queryByRole('button', { name: 'Resend' })).to.be.null
- })
- it('only shows read-only token link to restricted token members', async function () {
- window.metaAttributesCache.set('ol-isRestrictedTokenMember', true)
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps({ publicAccessLevel: 'private' }),
- isRestrictedTokenMember: true,
- })
- // no buttons
- expect(screen.queryByRole('button', { name: 'Turn on link sharing' })).to.be
- .null
- expect(screen.queryByRole('button', { name: 'Turn off link sharing' })).to
- .be.null
- // only read-only token link
- await screen.findByText('Anyone with this link can view this project')
- expect(screen.queryByText('Anyone with this link can edit this project')).to
- .be.null
- })
- it('displays project members and invites', async function () {
- const members: ProjectMember[] = [
- {
- _id: 'member-author' as UserId,
- email: 'member-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Member',
- last_name: 'Author',
- },
- {
- _id: 'member-viewer' as UserId,
- email: 'member-viewer@example.com',
- privileges: 'readOnly',
- first_name: 'Member',
- last_name: 'Viewer',
- },
- ]
- const invites: ProjectMember[] = [
- {
- _id: 'invited-author' as UserId,
- email: 'invited-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Invited',
- last_name: 'Author',
- },
- {
- _id: 'invited-viewer' as UserId,
- email: 'invited-viewer@example.com',
- privileges: 'readOnly',
- first_name: 'Invited',
- last_name: 'Viewer',
- },
- ]
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', members, invites })
- )
- const projectOwnerEmail = USER_EMAIL
- await screen.findByText(projectOwnerEmail)
- expect(screen.queryAllByText(projectOwnerEmail)).to.have.length(1)
- expect(screen.queryAllByText('member-author@example.com')).to.have.length(1)
- expect(screen.queryAllByText('member-viewer@example.com')).to.have.length(1)
- expect(screen.queryAllByText('invited-author@example.com')).to.have.length(
- 1
- )
- expect(screen.queryAllByText('invited-viewer@example.com')).to.have.length(
- 1
- )
- expect(screen.queryAllByText('Invite not yet accepted.')).to.have.length(
- invites.length
- )
- expect(screen.queryAllByRole('button', { name: 'Resend' })).to.have.length(
- invites.length
- )
- })
- it('resends an invite', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.postOnce(
- 'express:/project/:projectId/invite/:inviteId/resend',
- 204
- )
- const invites: ProjectMember[] = [
- {
- _id: 'invited-author' as UserId,
- email: 'invited-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Invited',
- last_name: 'Author',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', invites })
- )
- const closeButton = screen.getByRole('button', {
- name: 'Close',
- })
- const resendButton = screen.getByRole('button', { name: 'Resend' })
- fireEvent.click(resendButton)
- await waitFor(
- () => expect((closeButton as HTMLButtonElement).disabled).to.be.true
- )
- expect(fetchMock.callHistory.done()).to.be.true
- await waitFor(
- () => expect((closeButton as HTMLButtonElement).disabled).to.be.false
- )
- })
- it('revokes an invite', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.deleteOnce('express:/project/:projectId/invite/:inviteId', 204)
- const invites: ProjectMember[] = [
- {
- _id: 'invited-author' as UserId,
- email: 'invited-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Invited',
- last_name: 'Author',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', invites })
- )
- const closeButton = screen.getByRole('button', {
- name: 'Close',
- })
- const revokeButton = screen.getByRole('button', { name: 'Revoke' })
- fireEvent.click(revokeButton)
- await waitFor(
- () => expect((closeButton as HTMLButtonElement).disabled).to.be.true
- )
- expect(fetchMock.callHistory.done()).to.be.true
- await waitFor(
- () => expect((closeButton as HTMLButtonElement).disabled).to.be.false
- )
- })
- it('changes member privileges to read + write', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.putOnce('express:/project/:projectId/users/:userId', 204)
- const members: ProjectMember[] = [
- {
- _id: 'member-viewer' as UserId,
- email: 'member-viewer@example.com',
- privileges: 'readOnly',
- first_name: 'Member',
- last_name: 'Viewer',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', members })
- )
- const closeButton = screen.getByRole('button', {
- name: 'Close',
- })
- expect(
- await screen.findAllByText('member-viewer@example.com')
- ).to.have.length(1)
- await changePrivilegeLevel(screen, { current: 'Viewer', next: 'Editor' })
- await waitFor(
- () => expect((closeButton as HTMLButtonElement).disabled).to.be.true
- )
- const body = fetchMock.callHistory.calls().at(-1)?.options?.body
- expect(JSON.parse(body as string)).to.deep.equal({
- privilegeLevel: 'readAndWrite',
- })
- expect(fetchMock.callHistory.done()).to.be.true
- await waitFor(
- () => expect((closeButton as HTMLButtonElement).disabled).to.be.false
- )
- })
- it('removes a member from the project', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.deleteOnce('express:/project/:projectId/users/:userId', 204)
- const members: ProjectMember[] = [
- {
- _id: 'member-viewer' as UserId,
- email: 'member-viewer@example.com',
- privileges: 'readOnly',
- first_name: 'Member',
- last_name: 'Viewer',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', members })
- )
- expect(
- await screen.findAllByText('member-viewer@example.com')
- ).to.have.length(1)
- await changePrivilegeLevel(screen, {
- current: 'Viewer',
- next: 'Remove access',
- })
- const removeButton = screen.getByRole('button', {
- name: 'Confirm',
- })
- fireEvent.click(removeButton)
- const url = fetchMock.callHistory.calls().at(-1)?.url
- expect(url).to.equal(
- 'https://www.test-overleaf.com/project/test-project/users/member-viewer'
- )
- expect(fetchMock.callHistory.done()).to.be.true
- })
- it('changes member privileges to owner with confirmation', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.postOnce('express:/project/:projectId/transfer-ownership', 204)
- const members: ProjectMember[] = [
- {
- _id: 'member-viewer' as UserId,
- email: 'member-viewer@example.com',
- privileges: 'readOnly',
- first_name: 'Member',
- last_name: 'Viewer',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', members })
- )
- await screen.findByText('member-viewer@example.com')
- expect(screen.queryAllByText('member-viewer@example.com')).to.have.length(1)
- await changePrivilegeLevel(screen, {
- current: 'Viewer',
- next: 'Make owner',
- })
- screen.getByText((_, node) => {
- return (
- node !== null &&
- node.textContent ===
- 'Are you sure you want to make member-viewer@example.com the owner of Test Project?'
- )
- })
- const confirmButton: HTMLButtonElement = screen.getByRole('button', {
- name: 'Change owner',
- })
- fireEvent.click(confirmButton)
- await waitFor(() => expect(confirmButton.disabled).to.be.true)
- const body = fetchMock.callHistory.calls().at(-1)?.options?.body
- expect(JSON.parse(body as string)).to.deep.equal({
- user_id: 'member-viewer',
- })
- expect(fetchMock.callHistory.done()).to.be.true
- })
- it('sends invites to input email addresses', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- // loading contacts
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- // displaying a list of matching contacts
- inputElement.focus()
- fireEvent.change(inputElement, { target: { value: 'ptolemy' } })
- await screen.findByText(/ptolemy@example.com/)
- // sending invitations
- fetchMock.post(
- 'express:/project/:projectId/invite',
- ({ args: [, req] }) => {
- const data = JSON.parse((req as { body: string }).body)
- if (data.email === 'a@b.c') {
- return {
- status: 400,
- body: { errorReason: 'invalid_email' },
- }
- }
- return {
- status: 200,
- body: {
- invite: {
- ...data,
- _id: data.email,
- },
- },
- }
- }
- )
- fireEvent.paste(inputElement, {
- clipboardData: {
- getData: () =>
- `test@example.com; foo@example.com
- bar@example.com, a@b.c`,
- },
- })
- const user = userEvent.setup()
- await user.click(screen.getByTestId('add-collaborator-select'))
- await user.click(screen.getByText('Viewer'))
- const submitButton = screen.getByRole('button', { name: 'Invite' })
- await userEvent.click(submitButton)
- let calls: CallLog[] = []
- await waitFor(
- () => {
- calls = fetchMock.callHistory.calls(
- 'express:/project/:projectId/invite'
- )
- expect(calls).to.have.length(4)
- },
- { timeout: 5000 } // allow time for delay between each request
- )
- expect((calls[0].args[1] as { body: string }).body).to.equal(
- JSON.stringify({ email: 'test@example.com', privileges: 'readOnly' })
- )
- expect((calls[1].args[1] as { body: string }).body).to.equal(
- JSON.stringify({ email: 'foo@example.com', privileges: 'readOnly' })
- )
- expect((calls[2].args[1] as { body: string }).body).to.equal(
- JSON.stringify({ email: 'bar@example.com', privileges: 'readOnly' })
- )
- expect((calls[3].args[1] as { body: string }).body).to.equal(
- JSON.stringify({ email: 'a@b.c', privileges: 'readOnly' })
- )
- // error from the last invite
- screen.getByText('An email address is invalid')
- })
- it('displays a message when the collaborator limit is reached', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.post(
- '/event/paywall-prompt',
- {},
- { body: { 'paywall-type': 'project-sharing' } }
- )
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({
- publicAccessLevel: 'tokenBased',
- features: {
- collaborators: 0,
- compileGroup: 'standard',
- trackChangesVisible: true,
- },
- })
- )
- await screen.findByText('Add more collaborators')
- const user = userEvent.setup()
- await user.click(screen.getByTestId('add-collaborator-select'))
- const editorOption = screen.getByText('Editor').closest('button')
- const reviewerOption = screen.getByText('Reviewer').closest('button')
- const viewerOption = screen.getByText('Viewer').closest('button')
- expect(editorOption?.classList.contains('disabled')).to.be.true
- expect(reviewerOption?.classList.contains('disabled')).to.be.true
- expect(viewerOption?.classList.contains('disabled')).to.be.false
- screen.getByText(
- /Upgrade to add more collaborators and access higher AI allowance, track changes, and full project history/
- )
- })
- it('counts reviewers towards the collaborator limit', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({
- features: {
- collaborators: 1,
- trackChangesVisible: true,
- },
- members: [
- {
- _id: 'reviewer-id' as UserId,
- email: 'reviewer@example.com',
- privileges: 'review',
- first_name: 'Reviewer',
- last_name: 'LastName',
- },
- ],
- })
- )
- await screen.findByText('Add more collaborators')
- const user = userEvent.setup()
- await user.click(screen.getByTestId('add-collaborator-select'))
- const editorOption = screen.getByText('Editor').closest('button')
- const reviewerOption = screen.getByText('Reviewer').closest('button')
- const viewerOption = screen.getByText('Viewer').closest('button')
- expect(editorOption?.classList.contains('disabled')).to.be.true
- expect(reviewerOption?.classList.contains('disabled')).to.be.true
- expect(viewerOption?.classList.contains('disabled')).to.be.false
- screen.getByText(
- /Upgrade to add more collaborators and access higher AI allowance, track changes, and full project history/
- )
- })
- it('handles server error responses', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({
- publicAccessLevel: 'tokenBased',
- })
- )
- // loading contacts
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- const submitButton: HTMLButtonElement = screen.getByRole('button', {
- name: 'Invite',
- })
- const respondWithError = async function (errorReason: string) {
- fireEvent.focus(inputElement)
- fireEvent.change(inputElement, {
- target: { value: 'invited-author-1@example.com' },
- })
- fireEvent.blur(inputElement)
- fetchMock.postOnce('express:/project/:projectId/invite', {
- status: 400,
- body: { errorReason },
- })
- expect(submitButton.disabled).to.be.false
- await userEvent.click(submitButton)
- await fetchMock.callHistory.flush(true)
- expect(fetchMock.callHistory.done()).to.be.true
- }
- await respondWithError('cannot_invite_non_user')
- await screen.findByText(
- `Can’t send invite. Recipient must already have an Overleaf account`
- )
- await respondWithError('cannot_verify_user_not_robot')
- await screen.findByText(
- `Sorry, we could not verify that you are not a robot. Please check that Google reCAPTCHA is not being blocked by an ad blocker or firewall.`
- )
- await respondWithError('cannot_invite_self')
- await screen.findByText(`Can’t send invite to yourself`)
- await respondWithError('invalid_email')
- await screen.findByText(`An email address is invalid`)
- await respondWithError('too_many_requests')
- await screen.findByText(
- `Too many requests were received in a short space of time. Please wait for a few moments and try again.`
- )
- })
- it('handles switching between access levels', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- fetchMock.post('express:/project/:projectId/settings/admin', 204)
- let setPublicAccessLevel = function (_: PublicAccessLevel) {}
- function WrappedModal() {
- const { updateProject } = useProjectContext()
- setPublicAccessLevel = (publicAccessLevel: PublicAccessLevel) => {
- updateProject({ publicAccessLevel })
- }
- return <ShareProjectModal {...modalProps} />
- }
- renderWithEditorContext(
- <WrappedModal />,
- createContextProps({
- publicAccessLevel: 'private',
- })
- )
- await screen.findByText('Link sharing is off')
- const enableButton: HTMLButtonElement = await screen.findByRole('button', {
- name: 'Turn on link sharing',
- })
- fireEvent.click(enableButton)
- await waitFor(() => expect(enableButton.disabled).to.be.true)
- const tokenBody = fetchMock.callHistory.calls().at(-1)?.options.body
- expect(JSON.parse(tokenBody as string)).to.deep.equal({
- publicAccessLevel: 'tokenBased',
- })
- // NOTE: the project data is usually updated via the websocket connection
- // but we can't do that so we're doing it via the project context, which is
- // exposed in a hacky way here
- setPublicAccessLevel('tokenBased')
- await screen.findByText('Link sharing is on')
- const disableButton: HTMLButtonElement = await screen.findByRole('button', {
- name: 'Turn off link sharing',
- })
- fireEvent.click(disableButton)
- await waitFor(() => expect(disableButton.disabled).to.be.true)
- const privateBody = fetchMock.callHistory.calls().at(-1)?.options.body
- expect(JSON.parse(privateBody as string)).to.deep.equal({
- publicAccessLevel: 'private',
- })
- setPublicAccessLevel('private')
- await screen.findByText('Link sharing is off')
- })
- it('avoids selecting unmatched contact', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- // Wait for contacts to load
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- // Enter a prefix that matches a contact
- inputElement.focus()
- fireEvent.change(inputElement, { target: { value: 'ptolemy' } })
- // The matching contact should now be present and selected
- await screen.findByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- selected: true,
- })
- // Keep entering text so the contact no longer matches
- fireEvent.change(inputElement, {
- target: { value: 'ptolemy.new@example.com' },
- })
- // The matching contact should no longer be present
- expect(
- screen.queryByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- })
- ).to.be.null
- // No items should be added yet
- expect(screen.queryByRole('button', { name: 'Remove' })).to.be.null
- // Pressing Tab should add the entered item
- fireEvent.keyDown(inputElement, { key: 'Tab', code: 'Tab' })
- const collaborators = await waitFor(() => {
- return screen.getAllByRole('button', { name: /Remove/ })
- })
- expect(collaborators).to.not.be.null
- // Blurring the input should not add another contact
- fireEvent.blur(inputElement)
- await waitFor(() => {
- expect(screen.getAllByRole('button', { name: /Remove/ }).length).to.eql(
- collaborators.length
- )
- })
- })
- it('selects contact by typing the entire email and blurring the input', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- // Wait for contacts to load
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- // Enter a prefix that matches a contact
- await userEvent.type(inputElement, 'ptolemy@example.com')
- // The matching contact should now be present and selected
- await screen.findByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- selected: true,
- })
- // No items should be added yet
- expect(screen.queryByRole('button', { name: /Remove/ })).to.be.null
- // Click anywhere on the form to blur the input
- await userEvent.click(screen.getByRole('dialog'))
- // The contact should be added
- await waitFor(() => {
- expect(screen.getAllByRole('button', { name: /Remove/ })).to.have.length(
- 1
- )
- })
- })
- it('selects contact by typing a partial email and selecting the suggestion', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- // Wait for contacts to load
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- // Enter a prefix that matches a contact
- await userEvent.type(inputElement, 'pto')
- // The matching contact should now be present and selected
- await userEvent.click(
- screen.getByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- selected: true,
- })
- )
- // Click anywhere on the form to blur the input
- await userEvent.click(screen.getByRole('dialog'))
- // The contact should be added
- await waitFor(() => {
- expect(screen.getAllByRole('button', { name: /Remove/ })).to.have.length(
- 1
- )
- })
- })
- it('re-selects the same suggestion after removing it', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- await userEvent.type(inputElement, 'pto')
- await userEvent.click(
- screen.getByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- })
- )
- const removeButton = await screen.findByRole('button', { name: /Remove/ })
- await userEvent.click(removeButton)
- await waitFor(() => {
- expect(screen.queryByRole('button', { name: /remove/i })).to.be.null
- })
- await userEvent.click(inputElement)
- await userEvent.click(
- await screen.findByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- })
- )
- await waitFor(() => {
- expect(screen.getAllByRole('button', { name: /remove/i })).to.have.length(
- 1
- )
- })
- })
- describe('sharing-updates feature flag enabled', function () {
- beforeEach(function () {
- window.metaAttributesCache.set('ol-splitTestVariants', {
- 'sharing-updates': 'enabled',
- })
- })
- afterEach(function () {
- window.metaAttributesCache.delete('ol-splitTestVariants')
- })
- it('sets "Via sharing links (legacy)" when `publicAccessLevel` is `tokenBased`', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/tokens`, {})
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- await screen.findByText('Via sharing links (legacy)')
- })
- it('sets "Only invited people" when sharing-link returns 404', async function () {
- fetchMock.get(
- `/project/${shareModalProjectDefaults._id}/sharing-link`,
- 404
- )
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'private' })
- )
- await screen.findByText('Only invited people')
- })
- it('sets "Anyone with the link" when sharing-link returns a link without `subscriptionId`', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/sharing-link`, {
- _id: 'link-id',
- token: 'abc123',
- privileges: 'readOnly',
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'private' })
- )
- await screen.findByText('Anyone with the link')
- })
- it('sets "Anyone in your group with the link" when sharing-link returns a link with subscriptionId', async function () {
- fetchMock.get(`/project/${shareModalProjectDefaults._id}/sharing-link`, {
- _id: 'link-id',
- token: 'abc123',
- privileges: 'readOnly',
- subscriptionId: 'sub-123',
- })
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps({ publicAccessLevel: 'private' }),
- user: {
- id: USER_ID,
- email: USER_EMAIL,
- activeProfessionalGroupSubscriptions: [{ _id: 'sub-123' }],
- },
- })
- await screen.findByText('Anyone in your group with the link')
- })
- describe('invited people count', function () {
- beforeEach(function () {
- fetchMock.get(
- `/project/${shareModalProjectDefaults._id}/sharing-link`,
- 404
- )
- })
- it('shows "No one invited yet" when the owner is the only person', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'private' })
- )
- await screen.findByText('No one invited yet')
- expect(screen.queryByText('1 person invited')).to.be.null
- })
- it('shows the invited people count, including the owner, when there are collaborators', async function () {
- const members: ProjectMember[] = [
- {
- _id: 'member-author' as UserId,
- email: 'member-author@example.com',
- privileges: 'readAndWrite',
- first_name: 'Member',
- last_name: 'Author',
- },
- {
- _id: 'member-viewer' as UserId,
- email: 'member-viewer@example.com',
- privileges: 'readOnly',
- first_name: 'Member',
- last_name: 'Viewer',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'private', members })
- )
- await screen.findByText('3 people invited')
- expect(screen.queryByText('No one invited yet')).to.be.null
- })
- })
- describe('copy link button', function () {
- let clipboardWriteTextStub: sinon.SinonStub
- beforeEach(function () {
- clipboardWriteTextStub = sinon.stub().resolves()
- Object.defineProperty(navigator, 'clipboard', {
- value: { writeText: clipboardWriteTextStub },
- configurable: true,
- writable: true,
- })
- })
- afterEach(function () {
- window.metaAttributesCache.delete('ol-splitTestVariants')
- delete (navigator as any).clipboard
- })
- it('shows a disabled copy sharing link button when access is "Only invited people"', async function () {
- fetchMock.get('express:/project/:projectId/sharing-link', 404)
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const copyButton: HTMLButtonElement = await screen.findByRole(
- 'button',
- {
- name: /copy sharing link/i,
- }
- )
- expect(copyButton.disabled).to.be.true
- })
- it('enables the copy sharing link button when access is "Anyone with the link" and copies the correct URL on click', async function () {
- const sharingLinkToken = 'abc123token'
- fetchMock.get('express:/project/:projectId/sharing-link', {
- _id: 'invite-id',
- token: sharingLinkToken,
- privileges: 'readAndWrite',
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const copyButton: HTMLButtonElement = await screen.findByRole(
- 'button',
- {
- name: /copy sharing link/i,
- }
- )
- expect(copyButton.disabled).to.be.false
- await userEvent.click(copyButton)
- expect(clipboardWriteTextStub.calledOnce).to.be.true
- expect(clipboardWriteTextStub.firstCall.args[0]).to.equal(
- `${window.location.origin}/project/${shareModalProjectDefaults._id}/share#${sharingLinkToken}`
- )
- await screen.findByText(/link copied/i)
- })
- })
- })
- it('allows an email address to be selected, removed, then re-added', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const [inputElement] = await screen.findAllByLabelText('Add email address')
- // Wait for contacts to load
- await waitFor(() => {
- expect(fetchMock.callHistory.called('express:/user/contacts')).to.be.true
- })
- // Enter a prefix that matches a contact
- await userEvent.type(inputElement, 'pto')
- // Select the suggested contact
- await userEvent.click(
- screen.getByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- selected: true,
- })
- )
- // Click anywhere on the form to blur the input
- await userEvent.click(screen.getByRole('dialog'))
- // Remove the just-added collaborator
- await userEvent.click(screen.getByRole('button', { name: /Remove/ }))
- // Remove button should now be gone
- expect(screen.queryByRole('button', { name: /Remove/ })).to.be.null
- // Add the same collaborator again
- await userEvent.type(inputElement, 'pto')
- // Click the suggested contact again
- await userEvent.click(
- screen.getByRole('option', {
- name: `Claudius Ptolemy <ptolemy@example.com>`,
- selected: true,
- })
- )
- // Click anywhere on the form to blur the input
- await userEvent.click(screen.getByRole('dialog'))
- // The contact should be added
- await waitFor(() => {
- expect(screen.getAllByRole('button', { name: /Remove/ })).to.have.length(
- 1
- )
- })
- })
- it('does not show the "Give feedback" link when the "sharing-updates" feature flag is disabled', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- expect(screen.queryByRole('link', { name: 'Give feedback' })).to.be.null
- })
- describe('with "sharing-updates" feature flag', function () {
- beforeEach(function () {
- window.metaAttributesCache.set('ol-splitTestVariants', {
- 'sharing-updates': 'enabled',
- })
- })
- afterEach(function () {
- window.metaAttributesCache.set('ol-splitTestVariants', {})
- window.metaAttributesCache.set('ol-splitTestInfo', {})
- delete (navigator as any).clipboard
- })
- it('disables the invite button when no email is entered', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- expect(inviteButton.disabled).to.be.true
- })
- it('enables the invite button once a valid email is typed', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- expect(inviteButton.disabled).to.be.true
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, {
- target: { value: 'new@example.com' },
- })
- await waitFor(() => expect(inviteButton.disabled).to.be.false)
- })
- it('shows a validation error and disables invite button for an invalid email format', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, { target: { value: 'invalid@' } })
- fireEvent.blur(inputElement)
- await screen.findByText('Email addresses must be a valid format.')
- const inviteButton = screen.getByRole('button', {
- name: /invite/i,
- }) as HTMLButtonElement
- expect(inviteButton.disabled).to.be.true
- })
- it('shows a validation error and disables invite button when email already has access', async function () {
- const members: ProjectMember[] = [
- {
- _id: 'existing-member' as UserId,
- email: 'member@example.com',
- privileges: 'readAndWrite',
- first_name: 'Existing',
- last_name: 'Member',
- },
- ]
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased', members })
- )
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, {
- target: { value: 'member@example.com' },
- })
- fireEvent.blur(inputElement)
- await screen.findByText('Only add people who don’t yet have access.')
- const inviteButton = screen.getByRole('button', {
- name: /invite/i,
- }) as HTMLButtonElement
- expect(inviteButton.disabled).to.be.true
- })
- it('shows "invitations sent" message after a successful invite', async function () {
- fetchMock.post('express:/project/:projectId/invite', {
- status: 200,
- body: {
- invite: {
- _id: 'new-invite',
- email: 'new@example.com',
- privileges: 'readAndWrite',
- },
- },
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, { target: { value: 'new@example.com' } })
- fireEvent.blur(inputElement)
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- await waitFor(() => expect(inviteButton.disabled).to.be.false)
- await userEvent.click(inviteButton)
- await screen.findByText('Invitation(s) sent.')
- })
- it('shows a generic error and no success message when an invite fails (e.g. collaborator limit reached)', async function () {
- fetchMock.post('express:/project/:projectId/invite', {
- status: 200,
- body: {
- invite: null,
- },
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps({ publicAccessLevel: 'tokenBased' })
- )
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, { target: { value: 'new@example.com' } })
- fireEvent.blur(inputElement)
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- await waitFor(() => expect(inviteButton.disabled).to.be.false)
- await userEvent.click(inviteButton)
- await screen.findByText('Sorry, something went wrong')
- expect(screen.queryByText('Invitation(s) sent.')).to.be.null
- })
- it('clears "successActionMessage" when invitations are sent', async function () {
- Object.defineProperty(navigator, 'clipboard', {
- value: { writeText: sinon.stub().resolves() },
- configurable: true,
- writable: true,
- })
- const sharingLinkToken = 'abc123token'
- fetchMock.get('express:/project/:projectId/sharing-link', {
- _id: 'invite-id',
- token: sharingLinkToken,
- privileges: 'readAndWrite',
- })
- fetchMock.post('express:/project/:projectId/invite', {
- status: 200,
- body: {
- invite: {
- _id: 'new-invite',
- email: 'new@example.com',
- privileges: 'readAndWrite',
- },
- },
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const copyButton: HTMLButtonElement = await screen.findByRole('button', {
- name: /copy sharing link/i,
- })
- expect(copyButton.disabled).to.be.false
- await userEvent.click(copyButton)
- await screen.findByText(/link copied/i)
- const inputElement = screen.getByTestId('collaborator-email-input')
- fireEvent.change(inputElement, { target: { value: 'new@example.com' } })
- fireEvent.blur(inputElement)
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- await waitFor(() => expect(inviteButton.disabled).to.be.false)
- await userEvent.click(inviteButton)
- await screen.findByText('Invitation(s) sent.')
- expect(screen.queryByText(/link copied/i)).to.be.null
- })
- it('clears "invitations sent" message when input is changed', async function () {
- fetchMock.post('express:/project/:projectId/invite', {
- status: 200,
- body: {
- invite: {
- _id: 'new-invite',
- email: 'new@example.com',
- privileges: 'readAndWrite',
- },
- },
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, { target: { value: 'new@example.com' } })
- fireEvent.blur(inputElement)
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- await waitFor(() => expect(inviteButton.disabled).to.be.false)
- await userEvent.click(inviteButton)
- await screen.findByText('Invitation(s) sent.')
- fireEvent.change(inputElement, { target: { value: 'a' } })
- await waitFor(
- () => expect(screen.queryByText('Invitation(s) sent.')).to.be.null
- )
- })
- it('clears "invitations sent" message when a selected item is removed', async function () {
- fetchMock.post('express:/project/:projectId/invite', {
- status: 200,
- body: {
- invite: {
- _id: 'new-invite',
- email: 'new@example.com',
- privileges: 'readAndWrite',
- },
- },
- })
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- const inputElement = await screen.findByTestId('collaborator-email-input')
- fireEvent.change(inputElement, { target: { value: 'new@example.com' } })
- fireEvent.blur(inputElement)
- const inviteButton = (await screen.findByRole('button', {
- name: /invite/i,
- })) as HTMLButtonElement
- await waitFor(() => expect(inviteButton.disabled).to.be.false)
- await userEvent.click(inviteButton)
- await screen.findByText('Invitation(s) sent.')
- fireEvent.change(inputElement, {
- target: { value: 'another@example.com' },
- })
- fireEvent.blur(inputElement)
- const removeButton = await screen.findByRole('button', {
- name: /remove/i,
- })
- await userEvent.click(removeButton)
- await waitFor(
- () => expect(screen.queryByText('Invitation(s) sent.')).to.be.null
- )
- })
- it('shows the "Give feedback" link for the project owner', async function () {
- renderWithEditorContext(
- <ShareProjectModal {...modalProps} />,
- createContextProps()
- )
- await screen.findByRole('link', { name: 'Give feedback' })
- })
- it('does not show the "Give feedback" link for non-owners', async function () {
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps(),
- user: {
- id: 'non-project-owner' as UserId,
- email: 'non-project-owner@example.com',
- },
- })
- expect(screen.queryByRole('link', { name: 'Give feedback' })).to.be.null
- })
- describe('"Give feedback" link URL based on subscription plan', function () {
- it('links to the professional feedback URL when the user has a professional group plan', async function () {
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps(),
- user: {
- id: USER_ID,
- email: USER_EMAIL,
- isProfessionalGroupPlan: true,
- },
- })
- const feedbackLink = await screen.findByRole('link', {
- name: 'Give feedback',
- })
- expect(feedbackLink.getAttribute('href')).to.equal(
- 'https://forms.gle/rz1JDMuNajWG4ZY49'
- )
- })
- it('links to the standard feedback URL when the user does not have a professional group plan', async function () {
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps(),
- user: {
- id: USER_ID,
- email: USER_EMAIL,
- isProfessionalGroupPlan: false,
- },
- })
- const feedbackLink = await screen.findByRole('link', {
- name: 'Give feedback',
- })
- expect(feedbackLink.getAttribute('href')).to.equal(
- 'https://forms.gle/WLEjzG4Ayp8zFscM9'
- )
- })
- it('links to the Labs feedback URL when the "sharing-updates" feature is in the Labs phase', async function () {
- window.metaAttributesCache.set('ol-splitTestInfo', {
- 'sharing-updates': { phase: 'labs' },
- })
- renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
- ...createContextProps(),
- user: {
- id: USER_ID,
- email: USER_EMAIL,
- isProfessionalGroupPlan: false,
- },
- })
- const feedbackLink = await screen.findByRole('link', {
- name: 'Give feedback',
- })
- expect(feedbackLink.getAttribute('href')).to.equal(
- 'https://docs.google.com/forms/d/e/1FAIpQLSeOsPzSw8lWLY310ZvR7BCK08v3Puc4JWFdV6K3m9QbsL2OSw/viewform'
- )
- })
- })
- })
- })
|