Merge pull request #9676 from overleaf/jel-project-tools-unarchive

[web] Add unarchive button to project tools

GitOrigin-RevId: d1c7c693eb13cb7473b65e311f09ffe7a7f0d88f
This commit is contained in:
Jessica Lawshe
2022-10-04 08:02:47 +00:00
committed by Copybot
parent 9b09f8426d
commit 30fd0bfc9d
5 changed files with 69 additions and 9 deletions
@@ -4,7 +4,11 @@ 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 { owner, makeLongProjectList } from '../fixtures/projects-data'
import {
owner,
archivedProjects,
makeLongProjectList,
} from '../fixtures/projects-data'
const { fullList, currentList, trashedList } = makeLongProjectList(40)
const userId = owner.id
@@ -191,10 +195,43 @@ describe('<ProjectListRoot />', function () {
// first one is the select all checkbox
fireEvent.click(allCheckboxes[1])
project1Id = allCheckboxes[1].getAttribute('data-project-id')
actionsToolbar = screen.getAllByRole('toolbar')[0]
})
it('does not show the archive button in toolbar when archive view selected', function () {
expect(screen.queryByLabelText('Archive')).to.be.null
})
it('restores all projects when selected', async function () {
fetchMock.delete(`express:/project/:id/archive`, {
status: 200,
})
const unarchiveButton =
within(actionsToolbar).getByText<HTMLInputElement>('Restore')
fireEvent.click(unarchiveButton)
await fetchMock.flush(true)
expect(fetchMock.done()).to.be.true
screen.getByText('No projects')
})
it('only unarchive the selected projects', async function () {
// beforeEach selected all, so uncheck the 1st project
fireEvent.click(allCheckboxes[1])
const allCheckboxesChecked = allCheckboxes.filter(c => c.checked)
expect(allCheckboxesChecked.length).to.equal(
archivedProjects.length - 1
)
await fetchMock.flush(true)
expect(fetchMock.done()).to.be.true
expect(screen.queryByText('No projects')).to.be.null
})
})
describe('trashed projects', function () {
@@ -132,13 +132,13 @@ export const projectsData: Array<Project> = [
trashedAndNotOwnedProject,
]
export const currentProjects: Array<Project> = projectsData.filter(
export const archivedProjects = projectsData.filter(({ archived }) => archived)
export const currentProjects = projectsData.filter(
({ archived, trashed }) => !archived && !trashed
)
export const trashedProjects: Array<Project> = projectsData.filter(
({ trashed }) => trashed
)
export const trashedProjects = projectsData.filter(({ trashed }) => trashed)
export const makeLongProjectList = (listLength: number) => {
const longList = [...projectsData]