Skip to content

Commit

Permalink
fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengShi-1 committed Feb 21, 2025
1 parent b4fc949 commit f84a677
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sections/contact/ContactButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const ContactButton = ({
<ContactModal
show={showContactModal}
handleClose={closeContactModal}
title={t('contact.contactCollection')}
title={t('contact.contactDataset')}
onSuccess={onSuccess}
toContactName={toContactName}
id={id}
Expand Down
56 changes: 55 additions & 1 deletion tests/component/sections/contact/ContactButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@ describe('ContactButton', () => {
contactRepository={contactRepository}
/>
)

cy.findByRole('button', { name: /Contact/i })
.should('exist')
.click()
})
it('shows contact button if it is in collection page ', () => {
cy.findByRole('dialog').should('exist')
cy.findByText(/Email Collection Contact/i).should('exist')
})

it('shows contact button if it is in collection page with numeric id', () => {
cy.customMount(
<ContactButton
onSuccess={() => {}}
toContactName="Test Dataset"
isCollection={true}
id={1}
contactRepository={contactRepository}
/>
)

cy.findByRole('button', { name: /Contact/i })
.should('exist')
.click()
cy.findByRole('dialog').should('exist')
})

it('shows contact owner button if it is in dataset page ', () => {
Expand All @@ -36,6 +53,7 @@ describe('ContactButton', () => {
cy.findByRole('button', { name: /Contact Owner/i })
.should('exist')
.click()
cy.findByText(/Email Dataset Contact/i).should('exist')
cy.findByRole('dialog').should('exist')
})

Expand Down Expand Up @@ -93,3 +111,39 @@ describe('ContactButton', () => {
cy.findByRole('dialog').should('not.exist')
})
})

describe('ContactButton Error', () => {
it('should send alert if the submission is failed', () => {
const contactRepository = new ContactJSDataverseRepository()
cy.stub(ContactJSDataverseRepository.prototype, 'submitContactInfo').rejects(new Error('Error'))
cy.customMount(
<ContactButton
onSuccess={() => {}}
toContactName="Test Dataset"
isCollection={true}
id="root"
contactRepository={contactRepository}
/>
)

cy.findByRole('button', { name: /Contact/i })
.should('exist')
.click()
cy.findByTestId('captchaNumbers')
.invoke('text')
.then((text) => {
const matches = text.match(/(\d+)\s*\+\s*(\d+)\s*=/)
if (matches) {
const num1 = parseInt(matches[1], 10)
const num2 = parseInt(matches[2], 10)
const answer = num1 + num2
cy.findByTestId('fromEmail').type('email@dataverse.com')
cy.findByTestId('subject').type('subject')
cy.findByTestId('body').type('message')
cy.findByTestId('captchaInput').type(answer.toString())
cy.findByRole('button', { name: /Submit/i }).click()
}
})
cy.findByText('Error').should('exist')
})
})
2 changes: 1 addition & 1 deletion tests/component/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,6 @@ describe('Dataset', () => {
}
})
cy.findByRole('dialog').should('not.exist')
cy.findByText('Success!').should('exist')
cy.findByText(/Message sent./).should('exist')
})
})

0 comments on commit f84a677

Please sign in to comment.