Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Certificate page implement #18

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/components/Certificate/certificate.stories.tsx
DaleSeo marked this conversation as resolved.
Show resolved Hide resolved
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/:username/certificate" element={<Story />} />
</Routes>
</MemoryRouter>
),
],
};

export default meta;

export const Default: StoryObj<typeof Certificate> = {};
56 changes: 56 additions & 0 deletions src/components/Certificate/certificate.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { beforeEach, describe, expect, it, 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";

describe("<Certificate />", () => {
const username = "testUser";
const pathname = `/members/${username}/certificate`;

beforeEach(() => {
vi.spyOn(window, "print").mockImplementation(() => {});
render(
<MemoryRouter initialEntries={[pathname]}>
<Routes>
<Route
path="/members/:username/certificate"
element={<Certificate />}
/>
</Routes>
</MemoryRouter>,
);
});

it("render title", () => {
const heading = screen.getByRole("heading", { level: 2 });
expect(heading).toHaveTextContent(`${username}님의 수료증`);
});

it("render content", () => {
const content = screen.getByText("귀하는 어쩌구 저쩌구");
expect(content).toBeInTheDocument();
});

it("render print button", () => {
const printButton = screen.getByRole("button", { name: "출력" });
expect(printButton).toBeInTheDocument();
});

it("calls window.print when the print button is clicked", async () => {
const printButton = screen.getByRole("button", { name: "출력" });
const user = userEvent.setup();
await user.click(printButton);
expect(window.print).toHaveBeenCalledOnce();
});

it("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}`,
);
});
});
33 changes: 33 additions & 0 deletions src/components/Certificate/certificate.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#22 (comment) 에 👍 하셨으니 파일명을 대문자로 시작하도록 고치면 어떨까요?

Copy link
Contributor Author

@Sunjae95 Sunjae95 Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일명 변경하는 부분에서 시간이 걸렸네요.
문제가 되는 부분은 두가지였어요.

1. 깃은 파일, 폴더의 대소문자를 구분못한다.

해결방법

  • git config core.ignorecase false 로 대소문자 변경시 깃이 트래킹하도록 변경하는 옵션
  • git mv certificate Certificate 명령어를 통한 파일명 변경

2. 이름을 변경해도 이전 파일이 유령파일로 남아있어 로컬작업이 불가능함

예시)
image
해결방법
원격레포지토리에 1번에 변경된 내용을 push하고 로컬 프로젝트를 제거하고 다시 clone 받는다.
참고) 커밋 5a3c108 0d7b58d

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useLocation, useParams } from "react-router-dom";
import { css } from "../../../styled-system/css";

export default function Certificate() {
const { username } = useParams();
const { pathname } = useLocation();

/**
* @description https://addtoprofile.linkedin.com/#header2
* @argument field를 어디까지 채울것인가
* @argument 프로필에 등록이라는 이미지가 존재하기에 대체할 것인가?
*/
const linkedInURL = `https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&name=${username}&organizationId=104834174&certUrl=${pathname}`;

return (
<main>
<section>
<h2>{username}님의 수료증</h2>
DaleSeo marked this conversation as resolved.
Show resolved Hide resolved
<article>
<p>귀하는 어쩌구 저쩌구</p>
</article>
DaleSeo marked this conversation as resolved.
Show resolved Hide resolved
</section>
<section className={invisiblePrint}>
<button onClick={() => window.print()}>출력</button>
<a href={linkedInURL}>링크드인에 공유하기</a>
</section>
</main>
);
}

const invisiblePrint = css({
"@media print": { display: "none" },
});
3 changes: 3 additions & 0 deletions src/components/Certificate/index.tsx
DaleSeo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Certificate from "./certificate";

export default Certificate;
9 changes: 0 additions & 9 deletions src/components/certificate/certificate.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import Certificate from "./components/certificate/certificate";
import Certificate from "./components/Certificate";
import ErrorPage from "./components/ErrorPage/ErrorPage";
import Leaderboard from "./components/leaderboard/leaderboard";
import Progress from "./components/progress/progress";
Expand Down