Skip to content

Commit

Permalink
Add component tests for ShareLinkModal
Browse files Browse the repository at this point in the history
Partially resolves: Add E2E and component tests #33
  • Loading branch information
GodHermit committed Jul 26, 2023
1 parent 2b35af7 commit 2752d9f
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/components/ShareLinkModal/ShareLinkModal.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { useDisclosure } from '@chakra-ui/react';
import { useEffectOnce } from 'usehooks-ts';
import ShareLinkModal from './index';

describe('<ShareLinkModal />', () => {
function Disclosure() {
const disclosure = useDisclosure();

useEffectOnce(() => {
disclosure.onOpen();
});

return <ShareLinkModal {...disclosure} />
}

beforeEach(() => {
cy.viewport(800, 800);
cy.mountWithProviders(<Disclosure />);

cy.wait(500); // Wait for the modal to open
});

it('renders', () => {
cy
.findByText('ShareLinkModal.title')
.should('be.visible'); // Check that the title is visible

cy
.get('.chakra-input')
.should('contain.value', window.location.origin); // Check that the input is readonly

cy
.findByText('ShareLinkModal.copyButton')
.should('be.visible'); // Check that the copy button is visible

cy
.findByText('ShareLinkModal.doneButton')
.should('be.visible') // Check that the close button is visible
});

it('shows toast after coping', () => {
cy
.findByText('ShareLinkModal.copyButton')
.click(); // Click the copy button

cy.wait(800); // Wait for the toast to appear
cy
.findByText('ShareLinkModal.copySuccess')
.should('be.visible'); // Check that the success toast is visible
});

it('closes after clicking the done button', () => {
cy
.findByText('ShareLinkModal.doneButton')
.click(); // Click the done button

cy
.findByText('ShareLinkModal.title')
.should('not.exist'); // Check that the modal is closed
});
})

0 comments on commit 2752d9f

Please sign in to comment.