Skip to content

Commit

Permalink
Merge pull request #56 from route-master/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
JHyeon0915 authored Dec 7, 2023
2 parents 1748127 + 2d3436c commit fa2c8d6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/components/AddPlanCard/ModalContent/ModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,31 @@ function Modalcontent({ setModalOpen }: Props): JSX.Element {
<div>
<div>여행 일정 선택</div>
<div className={styles.datepickers_wrapper} onClick={handleClick}>
<label htmlFor="beginDate">
<DatePicker
id="beginDate"
showIcon
dateFormat="yyyy-MM-dd"
selectsStart
selected={beginDateInput}
endDate={endDateInput}
calendarClassName={styles.calendar}
onChange={(date: Date) => setBeginDateInput(date)}
/>
</label>
<DatePicker
aria-labelledby="beginDateLabel"
id="beginDate"
showIcon
dateFormat="yyyy-MM-dd"
selectsStart
selected={beginDateInput}
endDate={endDateInput}
calendarClassName={styles.calendar}
onChange={(date: Date) => setBeginDateInput(date)}
/>
-
<label htmlFor="endDate">
<DatePicker
id="endDate"
showIcon
dateFormat="yyyy-MM-dd"
selected={endDateInput}
minDate={beginDateInput}
startDate={beginDateInput}
endDate={endDateInput}
calendarClassName={styles.calendar}
onChange={(date: Date) => setEndDateInput(date)}
selectsEnd
/>
</label>
<DatePicker
aria-labelledby="endDateLabel"
id="endDate"
showIcon
dateFormat="yyyy-MM-dd"
selected={endDateInput}
minDate={beginDateInput}
startDate={beginDateInput}
endDate={endDateInput}
calendarClassName={styles.calendar}
onChange={(date: Date) => setEndDateInput(date)}
selectsEnd
/>
</div>
</div>
<button
Expand Down
48 changes: 48 additions & 0 deletions src/components/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useState } from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import Modal from './Modal';

describe('Modal', () => {
const Content = <div>test</div>;

function MockModal() {
const [modalOpen, setModalOpen] = useState(false);

return (
<div>
<button type="button" onClick={() => setModalOpen(true)}>
Open Modal Btn
</button>
{modalOpen && (
<Modal
setModalOpen={setModalOpen}
Content={Content}
mywidth="100px"
myheight="100px"
/>
)}
</div>
);
}

it('renders Modal with content', () => {
render(<MockModal />);
fireEvent.click(screen.getByText('Open Modal Btn'));
expect(screen.getByText('test')).toBeInTheDocument();
});

it('closes Modal on close button click', () => {
render(<MockModal />);
fireEvent.click(screen.getByText('Open Modal Btn'));
fireEvent.click(screen.getByText('x'));
expect(screen.queryByText('test')).not.toBeInTheDocument();
});

it('closes when clicking on the background', () => {
render(<MockModal />);
fireEvent.click(screen.getByText('Open Modal Btn'));
const background = screen.getByTestId('modal-background'); // Add this data-testid to your background div
fireEvent.click(background);
expect(screen.queryByText('test')).not.toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Modal({
ref={bgRef}
className={styles.background}
onClick={(e) => closeModal(e)}
data-testid="modal-background"
>
<div className={styles.container} style={size}>
<div className={styles.closebtn_wrapper}>
Expand Down

0 comments on commit fa2c8d6

Please sign in to comment.