-
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.
rename: export name modify fix: function keyword, div tag remove fix: convert CSF 3.0 fix: test label fix: local variable position fix: reset mock window.print fix: apply userEvent.setUp fix: change method name from test to it fix: mock reset fix: aria-labelledby test fire: Certificate/index.tsx rename: file name temp 변경 rename: Certificate로 변경 fix: Certificate import 수정 fix: tag, useParams query fix: change to test
- Loading branch information
Showing
6 changed files
with
96 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { MemoryRouter, Route, Routes } from "react-router-dom"; | ||
|
||
import Certificate from "./Certificate"; | ||
|
||
const username = "testUser"; | ||
const pathname = `/members/${username}/certificate`; | ||
|
||
const meta: Meta<typeof Certificate> = { | ||
component: Certificate, | ||
decorators: [ | ||
(Story) => ( | ||
<MemoryRouter initialEntries={[pathname]}> | ||
<Routes> | ||
<Route path="/members/:member/certificate" element={<Story />} /> | ||
</Routes> | ||
</MemoryRouter> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default: StoryObj<typeof Certificate> = {}; |
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,57 @@ | ||
import { afterAll, beforeEach, expect, test, vi } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { MemoryRouter, Route, Routes } from "react-router-dom"; | ||
import Certificate from "./Certificate"; | ||
|
||
const username = "testUser"; | ||
const pathname = `/members/${username}/certificate`; | ||
|
||
beforeEach(() => { | ||
render( | ||
<MemoryRouter initialEntries={[pathname]}> | ||
<Routes> | ||
<Route path="/members/:member/certificate" element={<Certificate />} /> | ||
</Routes> | ||
</MemoryRouter>, | ||
); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.mocked(window.print).mockRestore(); | ||
}); | ||
|
||
test("render title", () => { | ||
const heading = screen.getByRole("region", { | ||
name: `${username}님의 수료증`, | ||
}); | ||
expect(heading).toBeInTheDocument(); | ||
}); | ||
|
||
test("render content", () => { | ||
const content = screen.getByText("귀하는 어쩌구 저쩌구"); | ||
expect(content).toBeInTheDocument(); | ||
}); | ||
|
||
test("render print button", () => { | ||
const printButton = screen.getByRole("button", { name: "출력" }); | ||
expect(printButton).toBeInTheDocument(); | ||
}); | ||
|
||
test("calls window.print when the print button is clicked", async () => { | ||
vi.spyOn(window, "print").mockImplementation(() => {}); | ||
const printButton = screen.getByRole("button", { name: "출력" }); | ||
const user = userEvent.setup(); | ||
await user.click(printButton); | ||
expect(window.print).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
test("render LinkedIn link", () => { | ||
const linkedInLink = screen.getByRole("link", { | ||
name: "링크드인에 공유하기", | ||
}); | ||
expect(linkedInLink).toHaveAttribute( | ||
"href", | ||
`https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&name=${username}&organizationId=104834174&certUrl=${pathname}`, | ||
); | ||
}); |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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