|
@@ -2,8 +2,11 @@ import { fireEvent, screen, waitFor } from '@testing-library/dom'
|
|
|
import { expect } from 'chai'
|
|
import { expect } from 'chai'
|
|
|
import fetchMock from 'fetch-mock'
|
|
import fetchMock from 'fetch-mock'
|
|
|
import LoadMore from '../../../../../frontend/js/features/project-list/components/load-more'
|
|
import LoadMore from '../../../../../frontend/js/features/project-list/components/load-more'
|
|
|
-import { Project } from '../../../../../types/project/dashboard/api'
|
|
|
|
|
-import { projectsData } from '../fixtures/projects-data'
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ projectsData,
|
|
|
|
|
+ makeLongProjectList,
|
|
|
|
|
+ currentProjects,
|
|
|
|
|
+} from '../fixtures/projects-data'
|
|
|
import { renderWithProjectListContext } from '../helpers/render-with-context'
|
|
import { renderWithProjectListContext } from '../helpers/render-with-context'
|
|
|
|
|
|
|
|
describe('<LoadMore />', function () {
|
|
describe('<LoadMore />', function () {
|
|
@@ -12,26 +15,17 @@ describe('<LoadMore />', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders on a project list longer than 40', async function () {
|
|
it('renders on a project list longer than 40', async function () {
|
|
|
- // archived and trashed projects are currently not shown
|
|
|
|
|
- const filteredProjects = projectsData.filter(
|
|
|
|
|
- ({ archived, trashed }) => !archived && !trashed
|
|
|
|
|
- )
|
|
|
|
|
- let longProjectsData: Project[] = filteredProjects
|
|
|
|
|
- const MULTIPLY_FACTOR = 10
|
|
|
|
|
- // longProjectsData.length = 55
|
|
|
|
|
- for (let i = 0; i < MULTIPLY_FACTOR; i++) {
|
|
|
|
|
- longProjectsData = [...longProjectsData, ...filteredProjects]
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- renderWithProjectListContext(<LoadMore />, { projects: longProjectsData })
|
|
|
|
|
|
|
+ const { fullList, currentList } = makeLongProjectList(55)
|
|
|
|
|
+
|
|
|
|
|
+ renderWithProjectListContext(<LoadMore />, {
|
|
|
|
|
+ projects: fullList,
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
await screen.findByRole('button', {
|
|
await screen.findByRole('button', {
|
|
|
name: /Show 20 more projects/i,
|
|
name: /Show 20 more projects/i,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- await screen.findByText(
|
|
|
|
|
- `Showing 20 out of ${longProjectsData.length} projects.`
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ await screen.findByText(`Showing 20 out of ${currentList.length} projects.`)
|
|
|
|
|
|
|
|
await screen.findByRole('button', {
|
|
await screen.findByRole('button', {
|
|
|
name: /Show all projects/i,
|
|
name: /Show all projects/i,
|
|
@@ -39,29 +33,15 @@ describe('<LoadMore />', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders on a project list longer than 20 and shorter than 40', async function () {
|
|
it('renders on a project list longer than 20 and shorter than 40', async function () {
|
|
|
- // archived and trashed projects are currently not shown
|
|
|
|
|
- const filteredProjects = projectsData.filter(
|
|
|
|
|
- ({ archived, trashed }) => !archived && !trashed
|
|
|
|
|
- )
|
|
|
|
|
- let longProjectsData: Project[] = filteredProjects
|
|
|
|
|
- const MULTIPLY_FACTOR = 5
|
|
|
|
|
- // longProjectsData.length = 30
|
|
|
|
|
- for (let i = 0; i < MULTIPLY_FACTOR; i++) {
|
|
|
|
|
- longProjectsData = [...longProjectsData, ...filteredProjects]
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- renderWithProjectListContext(<LoadMore />, { projects: longProjectsData })
|
|
|
|
|
|
|
+ const { fullList, currentList } = makeLongProjectList(30)
|
|
|
|
|
+
|
|
|
|
|
+ renderWithProjectListContext(<LoadMore />, { projects: fullList })
|
|
|
|
|
|
|
|
await screen.findByRole('button', {
|
|
await screen.findByRole('button', {
|
|
|
- name: new RegExp(
|
|
|
|
|
- `Show ${longProjectsData.length - 20} more projects`,
|
|
|
|
|
- 'i'
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ name: new RegExp(`Show ${currentList.length - 20} more projects`, 'i'),
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- await screen.findByText(
|
|
|
|
|
- `Showing 20 out of ${longProjectsData.length} projects.`
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ await screen.findByText(`Showing 20 out of ${currentList.length} projects.`)
|
|
|
|
|
|
|
|
await screen.findByRole('button', {
|
|
await screen.findByRole('button', {
|
|
|
name: /Show all projects/i,
|
|
name: /Show all projects/i,
|
|
@@ -69,72 +49,52 @@ describe('<LoadMore />', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders on a project list shorter than 20', async function () {
|
|
it('renders on a project list shorter than 20', async function () {
|
|
|
- // archived and trashed projects are currently not shown
|
|
|
|
|
- // filteredProjects.length = 5
|
|
|
|
|
- const filteredProjects = projectsData.filter(
|
|
|
|
|
- ({ archived, trashed }) => !archived && !trashed
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- renderWithProjectListContext(<LoadMore />, { projects: filteredProjects })
|
|
|
|
|
|
|
+ renderWithProjectListContext(<LoadMore />, { projects: projectsData })
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(screen.queryByRole('button', { name: 'Show all' })).to.not.exist
|
|
expect(screen.queryByRole('button', { name: 'Show all' })).to.not.exist
|
|
|
screen.getByText(
|
|
screen.getByText(
|
|
|
- `Showing ${filteredProjects.length} out of ${filteredProjects.length} projects.`
|
|
|
|
|
|
|
+ `Showing ${currentProjects.length} out of ${currentProjects.length} projects.`
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('change text when pressing the "Show 20 more" once for project list longer than 40', async function () {
|
|
it('change text when pressing the "Show 20 more" once for project list longer than 40', async function () {
|
|
|
- // archived and trashed projects are currently not shown
|
|
|
|
|
- const filteredProjects = projectsData.filter(
|
|
|
|
|
- ({ archived, trashed }) => !archived && !trashed
|
|
|
|
|
- )
|
|
|
|
|
- let longProjectsData: Project[] = filteredProjects
|
|
|
|
|
- const MULTIPLY_FACTOR = 10
|
|
|
|
|
- // longProjectsData.length = 55
|
|
|
|
|
- for (let i = 0; i < MULTIPLY_FACTOR; i++) {
|
|
|
|
|
- longProjectsData = [...longProjectsData, ...filteredProjects]
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- renderWithProjectListContext(<LoadMore />, { projects: longProjectsData })
|
|
|
|
|
|
|
+ const { fullList, currentList } = makeLongProjectList(55)
|
|
|
|
|
+
|
|
|
|
|
+ renderWithProjectListContext(<LoadMore />, { projects: fullList })
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
const showMoreBtn = screen.getByRole('button', {
|
|
const showMoreBtn = screen.getByRole('button', {
|
|
|
name: /Show 20 more projects/i,
|
|
name: /Show 20 more projects/i,
|
|
|
})
|
|
})
|
|
|
fireEvent.click(showMoreBtn)
|
|
fireEvent.click(showMoreBtn)
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- screen.getByRole('button', {
|
|
|
|
|
- name: /Show 15 more/i,
|
|
|
|
|
- })
|
|
|
|
|
- screen.getByText(`Showing 40 out of ${longProjectsData.length} projects.`)
|
|
|
|
|
|
|
+ await waitFor(() => {
|
|
|
|
|
+ screen.getByLabelText(
|
|
|
|
|
+ `Show ${currentList.length - 20 - 20} more projects`
|
|
|
|
|
+ )
|
|
|
|
|
+ screen.getByText(`Showing 40 out of ${currentList.length} projects.`)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('change text when pressing the "Show 20 more" once for project list longer than 20 and shorter than 40', async function () {
|
|
it('change text when pressing the "Show 20 more" once for project list longer than 20 and shorter than 40', async function () {
|
|
|
- // archived and trashed projects are currently not shown
|
|
|
|
|
- const filteredProjects = projectsData.filter(
|
|
|
|
|
- ({ archived, trashed }) => !archived && !trashed
|
|
|
|
|
- )
|
|
|
|
|
- let longProjectsData: Project[] = filteredProjects
|
|
|
|
|
- const MULTIPLY_FACTOR = 5
|
|
|
|
|
- // longProjectsData.length = 30
|
|
|
|
|
- for (let i = 0; i < MULTIPLY_FACTOR; i++) {
|
|
|
|
|
- longProjectsData = [...longProjectsData, ...filteredProjects]
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- renderWithProjectListContext(<LoadMore />, { projects: longProjectsData })
|
|
|
|
|
|
|
+ const { fullList, currentList } = makeLongProjectList(30)
|
|
|
|
|
+
|
|
|
|
|
+ renderWithProjectListContext(<LoadMore />, { projects: fullList })
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
const showMoreBtn = screen.getByRole('button', {
|
|
const showMoreBtn = screen.getByRole('button', {
|
|
|
- name: /Show 10 more projects/i,
|
|
|
|
|
|
|
+ name: /Show 7 more projects/i,
|
|
|
})
|
|
})
|
|
|
fireEvent.click(showMoreBtn)
|
|
fireEvent.click(showMoreBtn)
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
|
|
+ await waitFor(() => {
|
|
|
expect(screen.queryByRole('button', { name: /Show/ })).to.not.exist
|
|
expect(screen.queryByRole('button', { name: /Show/ })).to.not.exist
|
|
|
screen.getByText(
|
|
screen.getByText(
|
|
|
- `Showing ${longProjectsData.length} out of ${longProjectsData.length} projects.`
|
|
|
|
|
|
|
+ `Showing ${currentList.length} out of ${currentList.length} projects.`
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|