From 9da05809f20348bab641ffcb7ed938f4837f5de5 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 26 Sep 2022 12:40:11 -0500 Subject: [PATCH] Merge pull request #9664 from overleaf/jel-copy-shared [web] Fix view when copying shared project GitOrigin-RevId: a5e9360434032718ad9cb231f90c3f9c72e955f6 --- .../context/project-list-context.tsx | 1 + .../components/project-list-root.test.tsx | 72 +++++++++++++++---- .../project-list/fixtures/projects-data.ts | 16 +++-- 3 files changed, 70 insertions(+), 19 deletions(-) diff --git a/services/web/frontend/js/features/project-list/context/project-list-context.tsx b/services/web/frontend/js/features/project-list/context/project-list-context.tsx index e5f2f7d570..245cb0ff30 100644 --- a/services/web/frontend/js/features/project-list/context/project-list-context.tsx +++ b/services/web/frontend/js/features/project-list/context/project-list-context.tsx @@ -342,6 +342,7 @@ export function ProjectListProvider({ children }: ProjectListProviderProps) { source: 'owner', trashed: false, archived: false, + accessLevel: 'owner', } setLoadedProjects(loadedProjects => { diff --git a/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx b/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx index 09229664cc..6457fcb963 100644 --- a/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx +++ b/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx @@ -4,15 +4,19 @@ import fetchMock from 'fetch-mock' import sinon from 'sinon' import ProjectListRoot from '../../../../../frontend/js/features/project-list/components/project-list-root' import { renderWithProjectListContext } from '../helpers/render-with-context' -import { currentProjects, trashedProjects } from '../fixtures/projects-data' +import { + currentProjects, + owner, + trashedProjects, +} from '../fixtures/projects-data' -const userId = '624333f147cfd8002622a1d3' +const userId = owner.id describe('', function () { const originalLocation = window.location const locationStub = sinon.stub() - beforeEach(function () { + beforeEach(async function () { window.metaAttributesCache = new Map() window.metaAttributesCache.set('ol-tags', []) window.metaAttributesCache.set('ol-ExposedSettings', { templateLinks: [] }) @@ -21,6 +25,12 @@ describe('', function () { Object.defineProperty(window, 'location', { value: { assign: locationStub }, }) + + renderWithProjectListContext() + await fetchMock.flush(true) + await waitFor(() => { + screen.findByRole('table') + }) }) afterEach(function () { @@ -36,14 +46,6 @@ describe('', function () { let actionsToolbar: HTMLElement let project1Id: string | null, project2Id: string | null - beforeEach(async function () { - renderWithProjectListContext() - await fetchMock.flush(true) - await waitFor(() => { - screen.findByRole('table') - }) - }) - describe('all projects', function () { beforeEach(function () { allCheckboxes = screen.getAllByRole('checkbox') @@ -247,7 +249,6 @@ describe('', function () { describe('search', function () { it('shows only projects based on the input', async function () { - renderWithProjectListContext() await fetchMock.flush(true) await waitFor(() => { screen.findByRole('table') @@ -264,4 +265,51 @@ describe('', function () { expect(results.length).to.equal(2) // first is header }) }) + + describe('copying project', function () { + it('correctly updates the view after copying a shared project', async function () { + const filterButton = screen.getAllByText('Shared with you')[0] + fireEvent.click(filterButton) + + const tableRows = screen.getAllByRole('row') + + const linkForProjectToCopy = within(tableRows[1]).getByRole('link') + const projectNameToCopy = linkForProjectToCopy.textContent + const copiedProjectName = `${projectNameToCopy} Copy` + fetchMock.post(`express:/project/:id/clone`, { + status: 200, + body: { + name: copiedProjectName, + lastUpdated: new Date(), + project_id: userId, + owner_ref: userId, + owner, + id: '6328e14abec0df019fce0be5', + lastUpdatedBy: owner, + accessLevel: 'owner', + source: 'owner', + trashed: false, + archived: false, + }, + }) + const copyButton = within(tableRows[1]).getAllByLabelText('Copy')[0] + fireEvent.click(copyButton) + + // confirm in modal + // const copyConfirmButton = screen.getByText('Copy') + const copyConfirmButton = document.querySelector( + 'button[type="submit"]' + ) as HTMLElement + fireEvent.click(copyConfirmButton) + + await fetchMock.flush(true) + expect(fetchMock.done()).to.be.true + + expect(screen.queryByText(copiedProjectName)).to.be.null + + const yourProjectFilter = screen.getAllByText('Your Projects')[0] + fireEvent.click(yourProjectFilter) + screen.findByText(copiedProjectName) + }) + }) }) diff --git a/services/web/test/frontend/features/project-list/fixtures/projects-data.ts b/services/web/test/frontend/features/project-list/fixtures/projects-data.ts index 8a32b6bd9a..f390f2f399 100644 --- a/services/web/test/frontend/features/project-list/fixtures/projects-data.ts +++ b/services/web/test/frontend/features/project-list/fixtures/projects-data.ts @@ -1,6 +1,13 @@ import { Project } from '../../../../../types/project/dashboard/api' const moment = require('moment') +export const owner = { + id: '624333f147cfd8002622a1d3', + email: 'riker@overleaf.com', + firstName: 'William', + lastName: 'Riker', +} + const users = { laforge: { id: '624371e98a21dd0026a5bfef', @@ -14,12 +21,7 @@ const users = { firstName: 'Jean-Luc', lastName: 'Picard', }, - riker: { - id: '624333f147cfd8002622a1d3', - email: 'riker@overleaf.com', - firstName: 'William', - lastName: 'Riker', - }, + riker: owner, worf: { id: '624371708a21dd0026a5bf86', email: 'worf@overleaf.com', @@ -77,7 +79,7 @@ export const archivedProject = { } export const trashedAndNotOwnedProject = { - id: '62d6d3721357e20a682110d5', + id: '63d6d3721357e20a682110d5', name: "Captain's logs very old (Trashed & Read Only & Not Owned)", lastUpdated: moment().subtract(11, 'year').toDate(), lastUpdatedBy: users.picard,