Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Oct 26, 2024
1 parent ae32e6c commit 4c7f434
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('LoggedInHeaderActions', () => {
canAddCollection: false
})
)

collectionRepository.getById = cy.stub().resolves(CollectionMother.create())
cy.customMount(
<LoggedInHeaderActions user={testUser} collectionRepository={collectionRepository} />
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import AddDataActionsButton from '../../../../../src/sections/shared/add-data-ac

describe('AddDataActionsButton', () => {
it('renders the button', () => {
cy.customMount(<AddDataActionsButton canAddCollection={true} canAddDataset={true} />)
cy.customMount(
<AddDataActionsButton
collectionId={'testCollectionId'}
canAddCollection={true}
canAddDataset={true}
/>
)

cy.findByRole('button', { name: /Add Data/i }).should('exist')
cy.findByRole('button', { name: /Add Data/ }).click()
cy.findByText('New Collection').should('be.visible')
cy.findByText('New Dataset').should('be.visible')
})

it('renders the new dataset button with the correct generated link', () => {
cy.customMount(<AddDataActionsButton canAddCollection={true} canAddDataset={true} />)

cy.findByRole('button', { name: /Add Data/i }).click()
cy.findByText('New Dataset')
.should('be.visible')
.should('have.attr', 'href', '/datasets/root/create')
})

it('renders the new dataset button with the correct generated link for specified collectionId', () => {
const collectionId = 'some-collection-id'
cy.customMount(
Expand All @@ -36,7 +33,14 @@ describe('AddDataActionsButton', () => {
})

it('shows New Collection button enabled if user has permissions to create collection', () => {
cy.customMount(<AddDataActionsButton canAddCollection={true} canAddDataset={true} />)
const collectionId = 'some-collection-id'
cy.customMount(
<AddDataActionsButton
collectionId={collectionId}
canAddCollection={true}
canAddDataset={true}
/>
)

cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn')
cy.get('@addDataBtn').should('exist')
Expand All @@ -47,7 +51,14 @@ describe('AddDataActionsButton', () => {
})

it('shows New Dataset button enabled if user has permissions to create dataset', () => {
cy.customMount(<AddDataActionsButton canAddCollection={true} canAddDataset={true} />)
const collectionId = 'some-collection-id'
cy.customMount(
<AddDataActionsButton
collectionId={collectionId}
canAddCollection={true}
canAddDataset={true}
/>
)

cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn')
cy.get('@addDataBtn').should('exist')
Expand All @@ -58,7 +69,14 @@ describe('AddDataActionsButton', () => {
})

it('shows New Collection button disabled if user does not have permissions to create collection', () => {
cy.customMount(<AddDataActionsButton canAddCollection={false} canAddDataset={true} />)
const collectionId = 'some-collection-id'
cy.customMount(
<AddDataActionsButton
collectionId={collectionId}
canAddCollection={false}
canAddDataset={true}
/>
)

cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn')
cy.get('@addDataBtn').should('exist')
Expand All @@ -69,7 +87,14 @@ describe('AddDataActionsButton', () => {
})

it('shows New Dataset button disabled if user does not have permissions to create dataset', () => {
cy.customMount(<AddDataActionsButton canAddCollection={true} canAddDataset={false} />)
const collectionId = 'some-collection-id'
cy.customMount(
<AddDataActionsButton
collectionId={collectionId}
canAddCollection={true}
canAddDataset={false}
/>
)

cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn')
cy.get('@addDataBtn').should('exist')
Expand Down

0 comments on commit 4c7f434

Please sign in to comment.