-
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 #168 from YAPP-Github/feature/DEV-97
[ Feature/dev 97 -> Main ]
- Loading branch information
Showing
19 changed files
with
305 additions
and
13 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,16 @@ | ||
import { XIcon } from "lucide-react"; | ||
import { HTMLAttributes } from "react"; | ||
|
||
interface CancelButtonProps extends HTMLAttributes<HTMLDivElement> { | ||
handleToggle: () => void; | ||
} | ||
|
||
export default function CancelButton({ handleToggle, ...props }: CancelButtonProps) { | ||
const { className } = props | ||
|
||
return ( | ||
<div className={className}> | ||
<XIcon data-testid="x-menu" width={36} height={36} className="mr-[23px]" onClick={handleToggle} /> | ||
</div> | ||
) | ||
} |
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,14 @@ | ||
"use client"; | ||
|
||
import { useProblemIdsViewModel } from "@shared/models/useProblemIdsViewModel"; | ||
import ProblemArticleTemplate from "../ProblemArticleTemplate"; | ||
|
||
export function ArticleDropDown() { | ||
const { getArticleId } = useProblemIdsViewModel(); | ||
|
||
return ( | ||
<div className="absolute left-0 top-[66px] z-20 h-screen w-full bg-white overflow-y-scroll px-[20px] pb-[100px]"> | ||
<ProblemArticleTemplate articleId={getArticleId()} /> | ||
</div> | ||
); | ||
} |
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,28 @@ | ||
import { ArticleDropDown } from "../ArticleDropDown"; | ||
import CancelButton from "@common/components/CancelButton"; | ||
|
||
interface ArticleDropDownWrapperProps { | ||
toggleArticle: boolean; | ||
handleToggleArticle: () => void; | ||
} | ||
|
||
export default function ArticleDropDownWrapper({ | ||
toggleArticle, | ||
handleToggleArticle, | ||
}: ArticleDropDownWrapperProps) { | ||
return ( | ||
<> | ||
{toggleArticle && ( | ||
<div className="fixed inset-0 z-50 flex justify-center bg-white"> | ||
<div className="relative w-full max-w-[480px] bg-white"> | ||
<CancelButton | ||
handleToggle={handleToggleArticle} | ||
className="absolute right-0 top-0 p-4" | ||
/> | ||
<ArticleDropDown /> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/problem/components/BackToArticle/BackToArticle.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,62 @@ | ||
import { beforeAll, beforeEach,describe, expect, it, vi } from "vitest"; | ||
|
||
import BackToArticle from "./"; | ||
import { BACK_TO_ARTICLE_WORDS } from "@problem/constants/backToArticle"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import QueryClientProviders from "@shared/components/queryClientProvider"; | ||
|
||
// Mocking the useParams hook from next/navigation | ||
vi.mock("next/navigation", () => ({ | ||
useParams: vi.fn(), | ||
})); | ||
|
||
const renderWithQueryClient = () => { | ||
return render( | ||
<QueryClientProviders> | ||
<BackToArticle /> | ||
</QueryClientProviders>, | ||
); | ||
}; | ||
|
||
describe("BackToArticle Component 동작 테스트", () => { | ||
beforeAll(() => { | ||
vi.mock("next/navigation", async () => { | ||
const actual = | ||
await vi.importActual<typeof import("next/navigation")>( | ||
"next/navigation", | ||
); | ||
return { | ||
...actual, | ||
useParams: vi.fn(() => ({ | ||
problemId: "1", | ||
})), | ||
}; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
renderWithQueryClient(); | ||
}); | ||
|
||
it("아티클 다시보기 버튼 클릭 시 문제에 해당하는 아티클이 보인다.", async () => { | ||
|
||
expect(screen.queryByText(BACK_TO_ARTICLE_WORDS.ARTICLE)).toBeInTheDocument(); | ||
|
||
const articleLink = screen.getByText(BACK_TO_ARTICLE_WORDS.ARTICLE); | ||
await userEvent.click(articleLink); | ||
|
||
expect(screen.getByTestId("x-menu")).toBeInTheDocument(); | ||
}); | ||
|
||
it("X 버튼 클릭 시 아티클 뷰가 없어진다.", async () => { | ||
|
||
const articleLink = screen.getByText(BACK_TO_ARTICLE_WORDS.ARTICLE); | ||
await userEvent.click(articleLink); | ||
|
||
const cancelButton = screen.getByTestId("x-menu"); | ||
await userEvent.click(cancelButton); | ||
|
||
expect(screen.queryByTestId("x-menu")).not.toBeInTheDocument(); | ||
}); | ||
}); |
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,74 @@ | ||
"use client"; | ||
import { useParams } from "next/navigation"; | ||
|
||
import { HTMLAttributes, useState } from "react"; | ||
|
||
import { useMutationState } from "@tanstack/react-query"; | ||
|
||
import { ApiResponse } from "@api/fewFetch"; | ||
|
||
import { cn } from "@shared/utils/cn"; | ||
|
||
import { BACK_TO_ARTICLE_WORDS } from "@problem/constants/backToArticle"; | ||
import { QUERY_KEY } from "@problem/remotes/api"; | ||
import { | ||
AnswerCheckInfo, | ||
ProblemAnswerBody, | ||
ProblemAnswerMuationState, | ||
} from "@problem/types/problemInfo"; | ||
import { Button } from "@shared/components/ui/button"; | ||
import ArticleDropDownWrapper from "../ArticleDropDownWrapper"; | ||
import { AnswerStatusModel } from "@problem/models/AnswerStatusModel"; | ||
|
||
interface BackToArticleProps extends HTMLAttributes<HTMLDivElement> {} | ||
|
||
export default function BackToArticle({ className }: BackToArticleProps) { | ||
const [toggleArticle, setToggleArticle] = useState(false); | ||
|
||
const handleToggleArticle = () => { | ||
setToggleArticle((prev) => !prev); | ||
}; | ||
|
||
const { problemId } = useParams<{ problemId: string }>(); | ||
const problemAnswersInfo = useMutationState<ProblemAnswerMuationState>({ | ||
filters: { | ||
mutationKey: [QUERY_KEY.POST_PROBLEM_ANSWER, problemId], | ||
}, | ||
select: (mutation) => { | ||
return { | ||
data: mutation.state.data as ApiResponse<AnswerCheckInfo>, | ||
variables: mutation.state.variables as ProblemAnswerBody, | ||
}; | ||
}, | ||
}); | ||
|
||
const answerStatus = new AnswerStatusModel({ | ||
problemAnswerInfo: problemAnswersInfo[0], | ||
}); | ||
|
||
const backToArticleWords = answerStatus.problemSolvedStatus | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
"flex flex-row space-x-[3px] relative", | ||
className, | ||
!answerStatus.isProblemAnswerInfo && "mt-[91px]", | ||
)} | ||
> | ||
<ArticleDropDownWrapper | ||
toggleArticle={toggleArticle} | ||
handleToggleArticle={handleToggleArticle} | ||
/> | ||
<span className="text-sm font-medium text-black"> | ||
{backToArticleWords} | ||
</span> | ||
<span | ||
onClick={handleToggleArticle} | ||
className="cursor-pointer text-sm font-bold text-main underline" | ||
> | ||
{BACK_TO_ARTICLE_WORDS.ARTICLE} | ||
</span> | ||
</div> | ||
); | ||
} |
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,43 @@ | ||
"use client"; | ||
|
||
import { useQueries } from "@tanstack/react-query"; | ||
|
||
import ArticleSkeleton from "@article/components/ArticleSkeleton"; | ||
import { ARTICLE_INFO_TYPE } from "@article/constants/articleCase"; | ||
import { getArticleQueryOptions } from "@article/remotes/getArticleQueryOptions"; | ||
|
||
interface ProblemArticleTemplateProps { | ||
articleId: string | ||
} | ||
|
||
export default function ProblemArticleTemplate({ articleId }: ProblemArticleTemplateProps) { | ||
|
||
const results = useQueries({ | ||
queries: [ | ||
{ | ||
...getArticleQueryOptions({ articleId }), | ||
staleTime: Infinity, | ||
}, | ||
], | ||
}); | ||
const { | ||
data: articleInfo, | ||
isLoading, | ||
isError, | ||
} = results[ARTICLE_INFO_TYPE.ONLY_ARTICLE]; | ||
|
||
if (isLoading || isError || !articleInfo) | ||
return <ArticleSkeleton.EmailContentTemplateSkeleton />; | ||
|
||
const { content } = articleInfo; | ||
|
||
return ( | ||
<table> | ||
<tbody> | ||
<tr style={{}}> | ||
<td dangerouslySetInnerHTML={{ __html: content }}></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
} |
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,5 @@ | ||
export const BACK_TO_ARTICLE_WORDS = { | ||
BEFORE: "정답을 모르겠다면?", | ||
AFTER: "복습을 하고 싶다면?", | ||
ARTICLE: "아티클 다시보기" | ||
} |
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,24 @@ | ||
import { BACK_TO_ARTICLE_WORDS } from "@problem/constants/backToArticle"; | ||
import { ProblemAnswerMuationState } from "@problem/types/problemInfo"; | ||
|
||
export class AnswerStatusModel { | ||
constructor({ | ||
problemAnswerInfo, | ||
}: { | ||
problemAnswerInfo: ProblemAnswerMuationState | undefined; | ||
}) { | ||
this.problemAnswerInfo = problemAnswerInfo; | ||
} | ||
|
||
get problemSolvedStatus() { | ||
return this.problemAnswerInfo | ||
? BACK_TO_ARTICLE_WORDS.AFTER | ||
: BACK_TO_ARTICLE_WORDS.BEFORE; | ||
} | ||
|
||
get isProblemAnswerInfo() { | ||
return Boolean(this.problemAnswerInfo); | ||
} | ||
|
||
private problemAnswerInfo: ProblemAnswerMuationState | undefined; | ||
} |
Oops, something went wrong.