From 8206ad697dd06e66b882c94185767d97e9b6e5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Thu, 21 Nov 2024 12:34:36 -0300 Subject: [PATCH] test: add unit tests --- .../social-share-modal/SocialShareModal.tsx | 2 -- .../sections/collection/Collection.spec.tsx | 25 ++++++++++++++++++- .../DatasetActionButtons.spec.tsx | 15 +++++++++-- .../ShareDatasetButton.spec.tsx | 16 ++++++++++++ .../SocialShareModal.spec.tsx | 19 ++++++++++++++ 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 tests/component/sections/dataset/dataset-action-buttons/share-dataset-button/ShareDatasetButton.spec.tsx create mode 100644 tests/component/sections/shared/social-share-modal/SocialShareModal.spec.tsx diff --git a/src/sections/shared/social-share-modal/SocialShareModal.tsx b/src/sections/shared/social-share-modal/SocialShareModal.tsx index a73b2ff5a..34957726c 100644 --- a/src/sections/shared/social-share-modal/SocialShareModal.tsx +++ b/src/sections/shared/social-share-modal/SocialShareModal.tsx @@ -3,8 +3,6 @@ import { Button, Modal, Stack } from '@iqss/dataverse-design-system' import { Facebook, Linkedin, TwitterX } from 'react-bootstrap-icons' import styles from './SocialShareModal.module.scss' -// TODO:ME - Add component test to check url is correct - export const LINKEDIN_SHARE_URL = 'https://www.linkedin.com/shareArticle?url=' export const X_SHARE_URL = 'https://x.com/intent/post?url=' export const FACEBOOK_SHARE_URL = 'https://www.facebook.com/sharer/sharer.php?u=' diff --git a/tests/component/sections/collection/Collection.spec.tsx b/tests/component/sections/collection/Collection.spec.tsx index fdb80ac37..e03b383e7 100644 --- a/tests/component/sections/collection/Collection.spec.tsx +++ b/tests/component/sections/collection/Collection.spec.tsx @@ -182,7 +182,7 @@ describe('Collection page', () => { cy.mountAuthenticated( { cy.findByRole('button', { name: /Cancel/i }).click() cy.findByText('Publish Collection').should('not.exist') }) + + it('opens and close the share collection modal', () => { + cy.viewport(1200, 800) + + cy.mountAuthenticated( + + ) + cy.findByRole('button', { name: /Share/i }).should('exist') + + cy.findByRole('button', { name: /Share/i }).click() + cy.findByText('Share this collection on your favorite social media networks.').should('exist') + + cy.findAllByRole('button', { name: /Close/i }).last().click() + cy.findByText('Share this collection on your favorite social media networks.').should( + 'not.exist' + ) + }) }) diff --git a/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx index 00f2dd5c1..5bd905f1e 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/DatasetActionButtons.spec.tsx @@ -1,3 +1,4 @@ +import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' import { DatasetRepository } from '../../../../../src/dataset/domain/repositories/DatasetRepository' import { FileSizeUnit } from '../../../../../src/files/domain/models/FileMetadata' import { DatasetActionButtons } from '../../../../../src/sections/dataset/dataset-action-buttons/DatasetActionButtons' @@ -10,6 +11,8 @@ import { const datasetRepository: DatasetRepository = {} as DatasetRepository +const collectionRepository = {} as CollectionRepository + describe('DatasetActionButtons', () => { it('renders the DatasetActionButtons with the Publish button', () => { const dataset = DatasetMother.create({ @@ -21,7 +24,11 @@ describe('DatasetActionButtons', () => { }) cy.mountAuthenticated( - + ) cy.findByRole('group', { name: 'Dataset Action Buttons' }).should('exist') @@ -45,7 +52,11 @@ describe('DatasetActionButtons', () => { }) cy.mountAuthenticated( - + ) cy.findByRole('group', { name: 'Dataset Action Buttons' }).should('exist') diff --git a/tests/component/sections/dataset/dataset-action-buttons/share-dataset-button/ShareDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/share-dataset-button/ShareDatasetButton.spec.tsx new file mode 100644 index 000000000..d47613c9e --- /dev/null +++ b/tests/component/sections/dataset/dataset-action-buttons/share-dataset-button/ShareDatasetButton.spec.tsx @@ -0,0 +1,16 @@ +import { ShareDatasetButton } from '@/sections/dataset/dataset-action-buttons/share-dataset-button/ShareDatasetButton' + +describe('ShareDatasetButton', () => { + it('opens and close the share dataset modal', () => { + cy.viewport(1200, 800) + + cy.mountAuthenticated() + cy.findByRole('button', { name: /Share/i }).should('exist') + + cy.findByRole('button', { name: /Share/i }).click() + cy.findByText('Share this dataset on your favorite social media networks.').should('exist') + + cy.findAllByRole('button', { name: /Close/i }).last().click() + cy.findByText('Share this dataset on your favorite social media networks.').should('not.exist') + }) +}) diff --git a/tests/component/sections/shared/social-share-modal/SocialShareModal.spec.tsx b/tests/component/sections/shared/social-share-modal/SocialShareModal.spec.tsx new file mode 100644 index 000000000..946c96512 --- /dev/null +++ b/tests/component/sections/shared/social-share-modal/SocialShareModal.spec.tsx @@ -0,0 +1,19 @@ +import { SocialShareModal } from '@/sections/shared/social-share-modal/SocialShareModal' + +describe('SocialShareModal', () => { + it('should render the component title, help text and 3 social links', () => { + cy.mount( + {}} + /> + ) + + cy.findByText('The Title').should('exist') + cy.findByText('The Help Text').should('exist') + cy.get('a').should('have.length', 3) + }) +})