-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add lecture/#77
- Loading branch information
Showing
19 changed files
with
227 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { expect, userEvent } from '@storybook/test'; | ||
import { mockDatabase, resetMockDB } from '@/app/mocks/db.mock'; | ||
import TakenLectureAtomHydrator from '@/app/store/taken-lecture-atom-hydrator'; | ||
import { screen } from '@storybook/testing-library'; | ||
import TakenLectureLabel from '../taken-lecture/taken-lecture-label'; | ||
import TakenLectureList from '../taken-lecture/taken-lecture-list'; | ||
import LectureSearch from '.'; | ||
import { DIALOG_KEY } from '@/app/utils/key/dialog.key'; | ||
import Drawer from '../../view/molecule/drawer/drawer'; | ||
import { delay } from 'msw'; | ||
|
||
const meta = { | ||
title: 'ui/lecture/lecture-search', | ||
component: LectureSearch, | ||
decorators: [ | ||
(Story) => { | ||
resetMockDB(); | ||
const data = mockDatabase.getTakenLectures(); | ||
return ( | ||
<> | ||
<TakenLectureAtomHydrator initialValue={data.takenLectures}> | ||
<TakenLectureLabel /> | ||
<TakenLectureList /> | ||
</TakenLectureAtomHydrator> | ||
<Drawer drawerKey={DIALOG_KEY.LECTURE_SEARCH}> | ||
<Story /> | ||
</Drawer> | ||
</> | ||
); | ||
}, | ||
], | ||
} as Meta<typeof TakenLectureList>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const AddSenario: Story = { | ||
play: async ({ step }) => { | ||
await step('사용자가 추가를 클릭하면 lecture search drawer 창이 띄워진다', async () => { | ||
const toggleLectureSearch = await screen.findByTestId('toggle-lecture-search'); | ||
await userEvent.click(toggleLectureSearch); | ||
|
||
const lectureSearch = await screen.findByTestId('lecture-search'); | ||
expect(lectureSearch).toBeInTheDocument(); | ||
}); | ||
await step('추가 버튼을 클릭하면 추가 버튼이 disabled 된다', async () => { | ||
const addButton = await screen.findAllByTestId('add-taken-lecture-button'); | ||
await userEvent.click(addButton[0]); | ||
|
||
await delay(3000); | ||
expect(addButton[0]).toBeDisabled(); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,41 @@ | ||
import { LectureInfo } from '@/app/type/lecture'; | ||
import Button from '../../view/atom/button/button'; | ||
import Form from '../../view/molecule/form'; | ||
import { addTakenLecture } from '@/app/business/lecture/taken-lecture.command'; | ||
import { useToast } from '../../view/molecule/toast/use-toast'; | ||
import { useState } from 'react'; | ||
|
||
interface AddTakenLectureButtonProps { | ||
lectureItem: LectureInfo; | ||
isTakenLecture: boolean; | ||
} | ||
export default function AddTakenLectureButton({ lectureItem }: AddTakenLectureButtonProps) { | ||
return <Button variant="list" label="추가" onClick={() => {}} />; | ||
export default function AddTakenLectureButton({ lectureItem, isTakenLecture }: AddTakenLectureButtonProps) { | ||
const { toast } = useToast(); | ||
const [disabled, setDisabled] = useState(isTakenLecture); | ||
|
||
const handleSuccessOfAdditionTakenLecture = () => { | ||
setDisabled(true); | ||
return toast({ | ||
title: '과목 추가에 성공했습니다', | ||
}); | ||
}; | ||
|
||
return ( | ||
<Form | ||
id={`과목추가-${lectureItem.id}`} | ||
action={() => { | ||
return addTakenLecture(lectureItem.id); | ||
}} | ||
failMessageControl="toast" | ||
onSuccess={handleSuccessOfAdditionTakenLecture} | ||
> | ||
<Form.SubmitButton | ||
label="추가" | ||
position="center" | ||
variant="list" | ||
disabled={disabled} | ||
size="default" | ||
data-testid="add-taken-lecture-button" | ||
/> | ||
</Form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client'; | ||
import { takenLectureAtom } from '@/app/store/custom-taken-lecture'; | ||
import { TakenLectrueInfo } from '@/app/type/lecture'; | ||
import { useEffect } from 'react'; | ||
import { useAtomValue, useSetAtom } from 'jotai'; | ||
import { updateDialogAtom } from '@/app/store/dialog'; | ||
|
||
export default function UpdateTakenLecture({ data, children }: React.PropsWithChildren<{ data: TakenLectrueInfo[] }>) { | ||
const isLectureSearchOpen = useAtomValue(updateDialogAtom); | ||
const setTakenLectures = useSetAtom(takenLectureAtom); | ||
|
||
useEffect(() => { | ||
setTakenLectures(data); | ||
}, [isLectureSearchOpen]); | ||
|
||
return children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.