diff --git a/src/files/domain/models/FilePaginationInfo.ts b/src/files/domain/models/FilePaginationInfo.ts
index 5f0e1ddcc..fbef8d177 100644
--- a/src/files/domain/models/FilePaginationInfo.ts
+++ b/src/files/domain/models/FilePaginationInfo.ts
@@ -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)
diff --git a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx
index 32cd4f0fe..77c287336 100644
--- a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx
+++ b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx
@@ -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 ', () => {
@@ -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(
+
+ )
+
+ 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(
+
+ )
+
+ 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(