From d0cf486d5e14447125505c423b3300e2905ed7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Thu, 16 Jan 2025 09:31:34 -0300 Subject: [PATCH] test: add unrelated test cases to increase coverage branch --- .../CollectionItemsPanel.spec.tsx | 81 +++++++++++++++++++ .../EditDatasetMenu.spec.tsx | 40 +++++++++ .../DatasetUploadFilesButton.spec.tsx | 14 +++- 3 files changed, 134 insertions(+), 1 deletion(-) diff --git a/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx b/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx index 601d0efff..972cf427c 100644 --- a/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx +++ b/tests/component/sections/collection/collection-items-panel/CollectionItemsPanel.spec.tsx @@ -554,4 +554,85 @@ describe('CollectionItemsPanel', () => { }) }) }) + + describe('Sorting', () => { + // These cases about sorting are not possible to test the change in here as they react to the url change + // They are properly tested in the e2e tests and in another unit test. + // This will just click the different sort buttons to go through the code + it('clicks the sort by name A-Z button', () => { + cy.customMount( + + ) + + cy.findByRole('button', { name: /Sort/ }).click() + cy.findByRole('button', { name: /Name \(A-Z\)/ }).click() + }) + + it('clicks the sort by name Z-A button', () => { + cy.customMount( + + ) + + cy.findByRole('button', { name: /Sort/ }).click() + cy.findByRole('button', { name: /Name \(Z-A\)/ }).click() + }) + + it('clicks the sort by newest button', () => { + cy.customMount( + + ) + + cy.findByRole('button', { name: /Sort/ }).click() + cy.findByRole('button', { name: /Newest/ }).click() + }) + + it('clicks the sort by oldest button', () => { + cy.customMount( + + ) + + cy.findByRole('button', { name: /Sort/ }).click() + cy.findByRole('button', { name: /Oldest/ }).click() + }) + }) }) diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx index 59b75f0d6..b0de54996 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx @@ -97,4 +97,44 @@ describe('EditDatasetMenu', () => { .should('have.class', 'disabled') cy.findByRole('button', { name: 'Metadata' }).should('exist').should('have.class', 'disabled') }) + + it('clicks on the Files (Upload) button', () => { + const dataset = DatasetMother.create({ + permissions: DatasetPermissionsMother.createWithAllAllowed(), + locks: [], + hasValidTermsOfAccess: true + }) + + cy.mountAuthenticated() + + cy.findByRole('button', { name: 'Edit Dataset' }).click() + cy.findByRole('button', { name: 'Files (Upload)' }).click() + }) + + it('clicks on the Files (Upload) button and dataset version is DRAFT', () => { + const dataset = DatasetMother.create({ + permissions: DatasetPermissionsMother.createWithAllAllowed(), + locks: [], + hasValidTermsOfAccess: true, + version: DatasetVersionMother.createDraft() + }) + + cy.mountAuthenticated() + + cy.findByRole('button', { name: 'Edit Dataset' }).click() + cy.findByRole('button', { name: 'Files (Upload)' }).click() + }) + + it('clicks on the Metadata button', () => { + const dataset = DatasetMother.create({ + permissions: DatasetPermissionsMother.createWithAllAllowed(), + locks: [], + hasValidTermsOfAccess: true + }) + + cy.mountAuthenticated() + + cy.findByRole('button', { name: 'Edit Dataset' }).click() + cy.findByRole('button', { name: 'Metadata' }).click() + }) }) diff --git a/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx b/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx index c5198a9e5..fe11cad24 100644 --- a/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/dataset-upload-files-button/DatasetUploadFilesButton.spec.tsx @@ -4,7 +4,8 @@ import { DatasetProvider } from '../../../../../../src/sections/dataset/DatasetP import { DatasetLockMother, DatasetMother, - DatasetPermissionsMother + DatasetPermissionsMother, + DatasetVersionMother } from '../../../../dataset/domain/models/DatasetMother' import { DatasetRepository } from '../../../../../../src/dataset/domain/repositories/DatasetRepository' import { Dataset as DatasetModel } from '../../../../../../src/dataset/domain/models/Dataset' @@ -13,6 +14,7 @@ const datasetRepository: DatasetRepository = {} as DatasetRepository const datasetWithUpdatePermissions = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed() }) + describe('DatasetUploadFilesButton', () => { const withDataset = (component: ReactNode, dataset: DatasetModel | undefined) => { datasetRepository.getByPersistentId = cy.stub().resolves(dataset) @@ -61,4 +63,14 @@ describe('DatasetUploadFilesButton', () => { cy.findByRole('button', { name: 'Upload Files' }).click() }) + + it('test click with a draft dataset version', () => { + const draftDatasetVersion = DatasetMother.create({ + permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), + version: DatasetVersionMother.createDraft() + }) + cy.mountAuthenticated(withDataset(, draftDatasetVersion)) + + cy.findByRole('button', { name: 'Upload Files' }).click() + }) })