Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

208 - Fix Files table incorrect behavior when changing page size #212

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/files/domain/models/FilePaginationInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class FilePaginationInfo {

withPageSize(pageSize: number): FilePaginationInfo {
const getNewPage = (oldPageSize: number, newPageSize: number) => {
const newPage = Math.ceil((this.page * oldPageSize) / newPageSize)
const newPage = Math.ceil(((this.page - 1) * oldPageSize + 1) / newPageSize)
return newPage > 0 ? newPage : 1
}
return new FilePaginationInfo(getNewPage(this.pageSize, pageSize), pageSize, this.totalFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('DatasetFiles', () => {

cy.findByLabelText('Files per page').select('25')

cy.findByRole('columnheader', { name: '26 to 50 of 200 Files' }).should('exist')
cy.findByRole('columnheader', { name: '1 to 25 of 200 Files' }).should('exist')
})

it('renders the files table with the correct header with a different page size ', () => {
Expand All @@ -116,6 +116,81 @@ describe('DatasetFiles', () => {
cy.findByRole('columnheader', { name: '101 to 150 of 200 Files' }).should('exist')
})

it('renders the first page if there is only one page and the user changes to a lower page size', () => {
const testFilesCountInfo = FilesCountInfoMother.create({
total: 32
})
fileRepository.getAllByDatasetPersistentId = cy.stub().resolves(testFiles)
fileRepository.getFilesCountInfoByDatasetPersistentId = cy.stub().resolves(testFilesCountInfo)
fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId = cy.stub().resolves(19900)

cy.customMount(
<DatasetFiles
filesRepository={fileRepository}
datasetPersistentId={datasetPersistentId}
datasetVersion={datasetVersion}
/>
)

cy.findByRole('button', { name: '1' }).should('not.exist')
cy.findByRole('button', { name: '2' }).should('exist')
cy.findByRole('button', { name: '3' }).should('exist')
cy.findByRole('button', { name: '4' }).should('exist')

cy.findByLabelText('Files per page').select('50')

cy.findByRole('button', { name: '1' }).should('not.exist')
cy.findByRole('button', { name: '2' }).should('not.exist')
cy.findByRole('button', { name: '3' }).should('not.exist')
cy.findByRole('columnheader', { name: '1 to 32 of 32 Files' }).should('exist')

cy.findByLabelText('Files per page').select('10')

cy.findByRole('button', { name: '1' }).should('not.exist')
cy.findByRole('button', { name: '2' }).should('exist')
cy.findByRole('button', { name: '3' }).should('exist')
cy.findByRole('button', { name: '4' }).should('exist')
cy.findByRole('columnheader', { name: '1 to 10 of 32 Files' }).should('exist')
})

it('renders the page that includes the first element of the current page when changing the page size', () => {
const testFilesCountInfo = FilesCountInfoMother.create({
total: 32
})
fileRepository.getAllByDatasetPersistentId = cy.stub().resolves(testFiles)
fileRepository.getFilesCountInfoByDatasetPersistentId = cy.stub().resolves(testFilesCountInfo)
fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId = cy.stub().resolves(19900)

cy.customMount(
<DatasetFiles
filesRepository={fileRepository}
datasetPersistentId={datasetPersistentId}
datasetVersion={datasetVersion}
/>
)

cy.findByRole('button', { name: '1' }).should('not.exist')
cy.findByRole('button', { name: '2' }).should('exist')
cy.findByRole('button', { name: '3' }).should('exist')
cy.findByRole('button', { name: '4' }).should('exist')

cy.findByLabelText('Files per page').select('25')

cy.findByRole('button', { name: '1' }).should('not.exist')
cy.findByRole('button', { name: '2' }).should('exist')
cy.findByRole('button', { name: '3' }).should('not.exist')
cy.findByRole('columnheader', { name: '1 to 25 of 32 Files' }).should('exist')

cy.findByRole('button', { name: '2' }).click()
cy.findByLabelText('Files per page').select('10')

cy.findByRole('button', { name: '1' }).should('exist')
cy.findByRole('button', { name: '2' }).should('exist')
cy.findByRole('button', { name: '3' }).should('not.exist')
cy.findByRole('button', { name: '4' }).should('exist')
cy.findByRole('columnheader', { name: '21 to 30 of 32 Files' }).should('exist')
})

it('maintains the selection when the page changes', () => {
cy.customMount(
<DatasetFiles
Expand Down