-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from YAPP-Github/feature/DEV-104
- Loading branch information
Showing
38 changed files
with
1,064 additions
and
39 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,85 @@ | ||
import React, { useState } from "react"; | ||
|
||
import { useMutation } from "@tanstack/react-query"; | ||
|
||
import { Button } from "@shared/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@shared/components/ui/dialog"; | ||
import useModalWidthControl from "@shared/hooks/useModalWidthControl"; | ||
import { cn } from "@shared/utils/cn"; | ||
|
||
import { SUBSCRIPTION_EMAIL_CLIENT_INFO } from "@main/constants/emailInfo"; | ||
import { SubscriptionManagementModel } from "@main/models/SubscriptionManagementModel"; | ||
import { patchWorkbookEmailDayMutationOptions } from "@main/remotes/patchWorkbookEmailDayMutationOptions"; | ||
import { SubscriptionEmailClientInfo } from "@main/types/emailInfo"; | ||
|
||
export default function EmailDayManagementDialog({ | ||
day, | ||
}: Pick<SubscriptionEmailClientInfo, "day">) { | ||
const [currentDay, setCurrentDay] = useState(day); | ||
useModalWidthControl(); | ||
|
||
const { mutate: patchWorkbookEmailDay } = useMutation({ | ||
...patchWorkbookEmailDayMutationOptions(), | ||
}); | ||
|
||
const onClickUpdateWorkbookEmailDay = () => { | ||
patchWorkbookEmailDay({ | ||
date: SubscriptionManagementModel.getDayPostInfo({ day: currentDay }), | ||
}); | ||
}; | ||
|
||
return ( | ||
<Dialog> | ||
<DialogTrigger className="sub2-medium rounded-lg bg-text-gray3 px-2 py-1"> | ||
{SUBSCRIPTION_EMAIL_CLIENT_INFO.DAY[currentDay]} | ||
</DialogTrigger> | ||
<DialogContent className="z-50 w-full max-w-[380px] rounded bg-white"> | ||
<DialogHeader> | ||
<DialogTitle className="h3-bold mb-[35px]"> | ||
이메일을 받고 싶은 요일을 | ||
<br /> 선택해주세요. | ||
</DialogTitle> | ||
<DialogDescription className="flex justify-between"> | ||
{Object.keys(SUBSCRIPTION_EMAIL_CLIENT_INFO.DAY).map((key) => { | ||
const currentKey = | ||
key as keyof typeof SUBSCRIPTION_EMAIL_CLIENT_INFO.DAY; | ||
const value = SUBSCRIPTION_EMAIL_CLIENT_INFO.DAY[currentKey]; | ||
return ( | ||
<Button | ||
className={cn( | ||
"body3-medium bg-white text-text-gray2", | ||
"min-w-[150px] p-[12px]", | ||
"rounded-[10px] border-[1px] border-text-gray2", | ||
"hover:bg-main hover:text-white", | ||
key === currentDay && "bg-main text-white", | ||
)} | ||
key={`email-day-${key}`} | ||
onClick={() => setCurrentDay(currentKey)} | ||
> | ||
{value} | ||
</Button> | ||
); | ||
})} | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<DialogClose | ||
className="body3-medium mt-[34px] bg-black py-[12px] text-white" | ||
onClick={onClickUpdateWorkbookEmailDay} | ||
> | ||
완료 | ||
</DialogClose> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/components/EmailManagementMenu/EmailManagementMenu.test.tsx
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,103 @@ | ||
import { useMutation, useQuery } from "@tanstack/react-query"; | ||
|
||
import { beforeEach, describe, expect, it } from "vitest"; | ||
|
||
import QueryClientProviders from "@shared/components/queryClientProvider"; | ||
import { createQueryProviderWrapper } from "@shared/constants/createQueryProvider"; | ||
|
||
import { getSubscriptionWorkbooksQueryOptions } from "@main/remotes/getSubscriptionWorkbooksQueryOptions"; | ||
import { patchWorkbookEmailDayMutationOptions } from "@main/remotes/patchWorkbookEmailDayMutationOptions"; | ||
import { patchWorkbookEmailTimeMutationOptions } from "@main/remotes/patchWorkbookEmailTimeMutationOptions"; | ||
|
||
import SubscriptionEmailManagement from "."; | ||
import { render, renderHook, screen, waitFor } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
describe("이메일 관련 구독 관리 컴포넌트 테스트", () => { | ||
const renderWithClient = () => { | ||
return render( | ||
<QueryClientProviders> | ||
<SubscriptionEmailManagement /> | ||
</QueryClientProviders>, | ||
); | ||
}; | ||
|
||
beforeEach(async () => { | ||
renderWithClient(); | ||
const { result } = renderHook( | ||
() => | ||
useQuery({ | ||
...getSubscriptionWorkbooksQueryOptions(), | ||
}), | ||
{ wrapper: createQueryProviderWrapper() }, | ||
); | ||
await waitFor(async () => result.current.isLoading); | ||
await waitFor(async () => result.current.isSuccess); | ||
}); | ||
|
||
it("이메일 시간 변경하기 테스트", async () => { | ||
const { result } = renderHook( | ||
() => | ||
useMutation({ | ||
...patchWorkbookEmailTimeMutationOptions(), | ||
}), | ||
{ wrapper: createQueryProviderWrapper() }, | ||
); | ||
|
||
const user = userEvent.setup(); | ||
const emialTimeButton = screen.getByRole("button", { name: "오전 9시" }); | ||
|
||
await user.click(emialTimeButton); | ||
const popupHeading = screen.getByRole("heading", { | ||
level: 2, | ||
}); | ||
|
||
expect(popupHeading).toHaveTextContent("아침에 이메일을 받고 싶은 시간을"); | ||
|
||
const tenTimeButton = screen.getByRole("button", { name: "10시" }); | ||
await user.click(tenTimeButton); | ||
|
||
const closeButton = screen.getByRole("button", { name: "완료" }); | ||
await user.click(closeButton); | ||
|
||
result.current.mutate({ time: "10:00" }); | ||
await waitFor(() => expect(result.current.isSuccess).toBeTruthy()); | ||
|
||
expect(screen.getByRole("button", { name: "오전 10시" })); | ||
}); | ||
|
||
it("이메일 요일 변경하기 테스트", async () => { | ||
const { result } = renderHook( | ||
() => | ||
useMutation({ | ||
...patchWorkbookEmailDayMutationOptions(), | ||
}), | ||
{ wrapper: createQueryProviderWrapper() }, | ||
); | ||
|
||
const user = userEvent.setup(); | ||
const emialDayButton = screen.getByRole("button", { | ||
name: "매일 받을래요", | ||
}); | ||
|
||
await user.click(emialDayButton); | ||
const popupHeading = screen.getByRole("heading", { | ||
level: 2, | ||
}); | ||
|
||
expect(popupHeading).toHaveTextContent("이메일을 받고 싶은 요일을"); | ||
|
||
const notWeekButton = screen.getByRole("button", { | ||
name: "주말에는 안 받을래요", | ||
}); | ||
await user.click(notWeekButton); | ||
|
||
const closeButton = screen.getByRole("button", { name: "완료" }); | ||
await user.click(closeButton); | ||
|
||
result.current.mutate({ date: "0011111" }); | ||
await waitFor(() => expect(result.current.isSuccess).toBeTruthy()); | ||
|
||
expect(screen.getByRole("button", { name: "주말에는 안 받을래요" })); | ||
}); | ||
}); |
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,38 @@ | ||
import React from "react"; | ||
|
||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { SubscriptionManagementModel } from "@main/models/SubscriptionManagementModel"; | ||
import { getSubscriptionWorkbooksQueryOptions } from "@main/remotes/getSubscriptionWorkbooksQueryOptions"; | ||
|
||
import EmailDayManagementDialog from "../EmailDayManagementDialog"; | ||
import EmailTimeManagementDialog from "../EmailTimeManagementDialog"; | ||
|
||
export default function SubscriptionEmailManagement() { | ||
const { data } = useQuery({ | ||
...getSubscriptionWorkbooksQueryOptions(), | ||
select: ({ data }) => { | ||
const subscriptionManagementModel = new SubscriptionManagementModel({ | ||
initSubscriptionManagementServerList: data.data.workbooks, | ||
}); | ||
return subscriptionManagementModel.SubscriptionEmailManagementClientInfo; | ||
}, | ||
}); | ||
|
||
return ( | ||
<section className="flex flex-col"> | ||
{data && ( | ||
<> | ||
<article className="flex h-[66px] items-center justify-between py-[10px]"> | ||
<p className="sub2-medium">이메일 받는 시간</p> | ||
<EmailTimeManagementDialog {...data} /> | ||
</article> | ||
<article className="flex h-[66px] items-center justify-between py-[10px]"> | ||
<p className="sub2-medium">이메일 받는 요일</p> | ||
<EmailDayManagementDialog {...data} /> | ||
</article> | ||
</> | ||
)} | ||
</section> | ||
); | ||
} |
Oops, something went wrong.