Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 21, 2024
1 parent a3c9982 commit 8206ad6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/sections/shared/social-share-modal/SocialShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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='
Expand Down
25 changes: 24 additions & 1 deletion tests/component/sections/collection/Collection.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('Collection page', () => {
cy.mountAuthenticated(
<Collection
collectionRepository={collectionRepository}
collectionId="collection"
collectionIdFromParams="collection"
created={false}
published={false}
collectionQueryParams={{ pageQuery: 1 }}
Expand All @@ -196,4 +196,27 @@ describe('Collection page', () => {
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(
<Collection
collectionRepository={collectionRepository}
collectionIdFromParams="collection"
created={false}
published={false}
collectionQueryParams={{ pageQuery: 1 }}
/>
)
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'
)
})
})
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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({
Expand All @@ -21,7 +24,11 @@ describe('DatasetActionButtons', () => {
})

cy.mountAuthenticated(
<DatasetActionButtons dataset={dataset} datasetRepository={datasetRepository} />
<DatasetActionButtons
dataset={dataset}
datasetRepository={datasetRepository}
collectionRepository={collectionRepository}
/>
)

cy.findByRole('group', { name: 'Dataset Action Buttons' }).should('exist')
Expand All @@ -45,7 +52,11 @@ describe('DatasetActionButtons', () => {
})

cy.mountAuthenticated(
<DatasetActionButtons dataset={dataset} datasetRepository={datasetRepository} />
<DatasetActionButtons
dataset={dataset}
datasetRepository={datasetRepository}
collectionRepository={collectionRepository}
/>
)

cy.findByRole('group', { name: 'Dataset Action Buttons' }).should('exist')
Expand Down
Original file line number Diff line number Diff line change
@@ -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(<ShareDatasetButton />)
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')
})
})
Original file line number Diff line number Diff line change
@@ -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(
<SocialShareModal
show={true}
title="The Title"
helpText="The Help Text"
shareUrl="shareUrl"
handleClose={() => {}}
/>
)

cy.findByText('The Title').should('exist')
cy.findByText('The Help Text').should('exist')
cy.get('a').should('have.length', 3)
})
})

0 comments on commit 8206ad6

Please sign in to comment.