Skip to content

Commit

Permalink
Merge pull request #158 from DaleStudy/157-grade-enum
Browse files Browse the repository at this point in the history
Grade의 타입을 Enum에서 Union으로 변경
  • Loading branch information
DaleSeo authored Dec 24, 2024
2 parents e5f777a + 138eb40 commit e79c418
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 69 deletions.
34 changes: 17 additions & 17 deletions src/api/services/process/processService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,29 @@ test("remove member with no submissions", () => {
});

test.each([
[1, Grade.SEED],
[2, Grade.SPROUT],
[3, Grade.SPROUT],
[4, Grade.LEAF],
[5, Grade.LEAF],
[6, Grade.BRANCH],
[7, Grade.BRANCH],
[8, Grade.FRUIT],
[9, Grade.FRUIT],
[10, Grade.TREE],
[11, Grade.TREE],
[1, "SEED"],
[2, "SPROUT"],
[3, "SPROUT"],
[4, "LEAF"],
[5, "LEAF"],
[6, "BRANCH"],
[7, "BRANCH"],
[8, "FRUIT"],
[9, "FRUIT"],
[10, "TREE"],
[11, "TREE"],
])(
"assign grades based on submissions: totalSubmissions: %i, expectedGrade: %s",
(totalSubmissions, expectedGrade) => {
// Arrange
const config: Partial<Config> = {
gradeThresholds: [
[Grade.SEED, 0],
[Grade.SPROUT, 2],
[Grade.LEAF, 4],
[Grade.BRANCH, 6],
[Grade.FRUIT, 8],
[Grade.TREE, 10],
["SEED", 0],
["SPROUT", 2],
["LEAF", 4],
["BRANCH", 6],
["FRUIT", 8],
["TREE", 10],
],
};
const processService = createMockProcessService(config);
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/process/processService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const initializeMemberMap = (
...member,
solvedProblems: [],
progress: 0,
grade: Grade.SEED,
grade: "SEED",
};
});

Expand Down Expand Up @@ -104,5 +104,5 @@ const determineGrade = (
([, threshold]) => totalSubmissions >= threshold,
);

return grade ? grade[0] : Grade.SEED;
return grade ? grade[0] : "SEED";
};
9 changes: 1 addition & 8 deletions src/api/services/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
export enum Grade {
SEED = "SEED",
SPROUT = "SPROUT",
LEAF = "LEAF",
BRANCH = "BRANCH",
FRUIT = "FRUIT",
TREE = "TREE",
}
export type Grade = "SEED" | "SPROUT" | "LEAF" | "BRANCH" | "FRUIT" | "TREE";

export type MemberIdentity = {
id: string; // lowercase
Expand Down
13 changes: 6 additions & 7 deletions src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import Card from "./Card";
import { Grade } from "../../api/services/types";

const meta: Meta<typeof Card> = {
component: Card,
Expand All @@ -14,47 +13,47 @@ export default meta;
export const Seed: StoryObj<typeof Card> = {
args: {
name: "seed",
grade: Grade.SEED,
grade: "SEED",
cohorts: [1],
},
};

export const Sprout: StoryObj<typeof Card> = {
args: {
name: "sprout",
grade: Grade.SPROUT,
grade: "SPROUT",
cohorts: [2],
},
};

export const Leaf: StoryObj<typeof Card> = {
args: {
name: "leaf",
grade: Grade.LEAF,
grade: "LEAF",
cohorts: [3],
},
};

export const Branch: StoryObj<typeof Card> = {
args: {
name: "branch",
grade: Grade.BRANCH,
grade: "BRANCH",
cohorts: [4],
},
};

export const Fruit: StoryObj<typeof Card> = {
args: {
name: "fruit",
grade: Grade.FRUIT,
grade: "FRUIT",
cohorts: [5],
},
};

export const Tree: StoryObj<typeof Card> = {
args: {
name: "tree",
grade: Grade.TREE,
grade: "TREE",
cohorts: [6],
},
};
15 changes: 6 additions & 9 deletions src/components/Card/Card.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { render, screen, within } from "@testing-library/react";
import { expect, test } from "vitest";

import { Grade } from "../../api/services/types";

import Card from "./Card";

test("render grade image", () => {
render(
<Card
id="test"
name="test"
grade={Grade.TREE}
grade={"TREE"}
currentCohort={1}
cohorts={[1]}
/>,
);

expect(
screen.getByRole("img", { name: `${Grade.TREE} image` }),
screen.getByRole("img", { name: `${"TREE"} image` }),
).toBeInTheDocument();
});

Expand All @@ -27,7 +24,7 @@ test("render github name", () => {
<Card
id="test"
name={name}
grade={Grade.TREE}
grade={"TREE"}
currentCohort={1}
cohorts={[1]}
/>,
Expand All @@ -42,7 +39,7 @@ test("render cohort", () => {
<Card
id="test"
name="user123"
grade={Grade.TREE}
grade={"TREE"}
currentCohort={currentCohort}
cohorts={[currentCohort]}
/>,
Expand All @@ -59,7 +56,7 @@ test("render progress link", () => {
<Card
id={id}
name="user123"
grade={Grade.TREE}
grade={"TREE"}
currentCohort={1}
cohorts={[1]}
/>,
Expand All @@ -79,7 +76,7 @@ test("render certificate link", () => {
<Card
id={id}
name="user123"
grade={Grade.TREE}
grade={"TREE"}
currentCohort={1}
cohorts={[1]}
/>,
Expand Down
11 changes: 2 additions & 9 deletions src/components/GradeImage/GradeImage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import type { Meta, StoryObj } from "@storybook/react";
import Card from "./GradeImage";
import { Grade } from "../../api/services/types";

const meta: Meta<typeof Card> = {
component: Card,
args: {
grade: Grade.SEED,
grade: "SEED",
width: 105,
height: 128,
},
};

export default meta;

export const Seed: StoryObj<typeof Card> = {
args: {
grade: Grade.SEED,
width: 105,
height: 128,
},
};
export const Default: StoryObj<typeof Card> = {};
13 changes: 9 additions & 4 deletions src/components/GradeImage/GradeImage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { faker } from "@faker-js/faker";
import { render, screen } from "@testing-library/react";
import { expect, test } from "vitest";

import { Grade } from "../../api/services/types";

import GradeImage from "./GradeImage";

test.each(Object.values(Grade))(
test.each(["SEED", "SPROUT", "LEAF", "BRANCH", "FRUIT", "TREE"] as const)(
"attach alternative text for %s image",
(grade) => {
render(
Expand All @@ -24,7 +22,14 @@ test.each(Object.values(Grade))(
test("set width and height", () => {
render(
<GradeImage
grade={faker.helpers.arrayElement(Object.values(Grade))}
grade={faker.helpers.arrayElement([
"SEED",
"SPROUT",
"LEAF",
"BRANCH",
"FRUIT",
"TREE",
])}
width={105}
height={128}
/>,
Expand Down
9 changes: 4 additions & 5 deletions src/components/Sidebar/Sidebar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import Sidebar from "./Sidebar.tsx";
import { Grade } from "../../api/services/types";

const meta = {
component: Sidebar,
Expand All @@ -14,7 +13,7 @@ const meta = {
profileUrl: "https://avatars.githubusercontent.com/u/104721736?v=4",
currentCohort: 3,
cohorts: [1, 2, 3],
grade: Grade.LEAF,
grade: "LEAF",
},
} satisfies Meta<typeof Sidebar>;

Expand All @@ -27,7 +26,7 @@ export const Default: StoryObj<typeof meta> = {
hardProgress: "3/5",
solvedProblems: 16,
totalProblems: 25,
grade: Grade.LEAF,
grade: "LEAF",
cohorts: [1, 2, 3],
currentCohort: 3,
githubUsername: "testuser",
Expand All @@ -42,7 +41,7 @@ export const HighProgress: StoryObj<typeof meta> = {
easyProgress: "10/10",
mediumProgress: "10/10",
hardProgress: "8/10",
grade: Grade.FRUIT,
grade: "FRUIT",
currentCohort: 3,
cohorts: [1, 2, 3],
githubUsername: "testuser",
Expand All @@ -57,7 +56,7 @@ export const NoProblems: StoryObj<typeof meta> = {
hardProgress: "0/0",
solvedProblems: 0,
totalProblems: 0,
grade: Grade.SEED,
grade: "SEED",
currentCohort: 3,
cohorts: [1, 2, 3],
githubUsername: "testuser",
Expand Down
3 changes: 1 addition & 2 deletions src/components/Sidebar/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import Sidebar from "./Sidebar.tsx";
import { Grade } from "../../api/services/types";

test("renders Sidebar with all elements", () => {
render(
Expand All @@ -15,7 +14,7 @@ test("renders Sidebar with all elements", () => {
profileUrl="example.png"
currentCohort={3}
cohorts={[1, 2, 3]}
grade={Grade.TREE}
grade={"TREE"}
/>,
);

Expand Down
11 changes: 9 additions & 2 deletions src/hooks/useMembers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, renderHook, waitFor } from "@testing-library/react";
import { expect, test, vi } from "vitest";
import { faker } from "@faker-js/faker";

import { Grade, type Member } from "../api/services/types";
import { type Member } from "../api/services/types";
import useMembers from "./useMembers";
import { problems } from "../api/constants/problems";

Expand All @@ -15,7 +15,14 @@ function createMockMember(custom: Partial<Member> = {}): Member {
cohorts: [currentCohort],
profileUrl: faker.internet.url(),
progress: faker.number.int({ min: 0, max: 100 }),
grade: faker.helpers.arrayElement(Object.values(Grade)),
grade: faker.helpers.arrayElement([
"SEED",
"SPROUT",
"LEAF",
"BRANCH",
"FRUIT",
"TREE",
]),
solvedProblems: faker.helpers.arrayElements(
problems,
faker.number.int({ min: 0, max: 5 }),
Expand Down
11 changes: 9 additions & 2 deletions src/pages/Leaderboard/Leaderboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from "@testing-library/react";
import { describe, expect, test, vi } from "vitest";
import { mock } from "vitest-mock-extended";

import { type Member, Grade } from "../../api/services/types";
import { type Member } from "../../api/services/types";
import useMembers from "../../hooks/useMembers";
import Leaderboard from "./Leaderboard";

Expand Down Expand Up @@ -139,6 +139,13 @@ function mockMember() {
name: userName,
currentCohort,
cohorts: [currentCohort],
grade: faker.helpers.arrayElement(Object.values(Grade)),
grade: faker.helpers.arrayElement([
"SEED",
"SPROUT",
"LEAF",
"BRANCH",
"FRUIT",
"TREE",
]),
});
}
11 changes: 9 additions & 2 deletions src/pages/Progress/Progress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen, within } from "@testing-library/react";
import { describe, expect, test, vi } from "vitest";
import { mock } from "vitest-mock-extended";

import { type Member, Grade } from "../../api/services/types";
import { type Member } from "../../api/services/types";
import useMembers from "../../hooks/useMembers";
import Progress from "./Progress";

Expand Down Expand Up @@ -166,7 +166,14 @@ function mockMember({ id = faker.internet.username() }: { id?: string } = {}) {
name: id,
currentCohort,
cohorts: [currentCohort],
grade: faker.helpers.arrayElement(Object.values(Grade)),
grade: faker.helpers.arrayElement([
"SEED",
"SPROUT",
"LEAF",
"BRANCH",
"FRUIT",
"TREE",
]),
profileUrl: faker.internet.url(),
solvedProblems: [],
});
Expand Down

0 comments on commit e79c418

Please sign in to comment.