diff --git a/src/api/services/process/processService.test.ts b/src/api/services/process/processService.test.ts index 68c6cdcc..97f46ae8 100644 --- a/src/api/services/process/processService.test.ts +++ b/src/api/services/process/processService.test.ts @@ -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 = { 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); diff --git a/src/api/services/process/processService.ts b/src/api/services/process/processService.ts index 88a5bf70..dfa7c157 100644 --- a/src/api/services/process/processService.ts +++ b/src/api/services/process/processService.ts @@ -35,7 +35,7 @@ const initializeMemberMap = ( ...member, solvedProblems: [], progress: 0, - grade: Grade.SEED, + grade: "SEED", }; }); @@ -104,5 +104,5 @@ const determineGrade = ( ([, threshold]) => totalSubmissions >= threshold, ); - return grade ? grade[0] : Grade.SEED; + return grade ? grade[0] : "SEED"; }; diff --git a/src/api/services/types.ts b/src/api/services/types.ts index f884ff1a..8c84e4f8 100644 --- a/src/api/services/types.ts +++ b/src/api/services/types.ts @@ -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 diff --git a/src/components/Card/Card.stories.tsx b/src/components/Card/Card.stories.tsx index d5a1b6e7..06eab90c 100644 --- a/src/components/Card/Card.stories.tsx +++ b/src/components/Card/Card.stories.tsx @@ -1,6 +1,5 @@ import type { Meta, StoryObj } from "@storybook/react"; import Card from "./Card"; -import { Grade } from "../../api/services/types"; const meta: Meta = { component: Card, @@ -14,7 +13,7 @@ export default meta; export const Seed: StoryObj = { args: { name: "seed", - grade: Grade.SEED, + grade: "SEED", cohorts: [1], }, }; @@ -22,7 +21,7 @@ export const Seed: StoryObj = { export const Sprout: StoryObj = { args: { name: "sprout", - grade: Grade.SPROUT, + grade: "SPROUT", cohorts: [2], }, }; @@ -30,7 +29,7 @@ export const Sprout: StoryObj = { export const Leaf: StoryObj = { args: { name: "leaf", - grade: Grade.LEAF, + grade: "LEAF", cohorts: [3], }, }; @@ -38,7 +37,7 @@ export const Leaf: StoryObj = { export const Branch: StoryObj = { args: { name: "branch", - grade: Grade.BRANCH, + grade: "BRANCH", cohorts: [4], }, }; @@ -46,7 +45,7 @@ export const Branch: StoryObj = { export const Fruit: StoryObj = { args: { name: "fruit", - grade: Grade.FRUIT, + grade: "FRUIT", cohorts: [5], }, }; @@ -54,7 +53,7 @@ export const Fruit: StoryObj = { export const Tree: StoryObj = { args: { name: "tree", - grade: Grade.TREE, + grade: "TREE", cohorts: [6], }, }; diff --git a/src/components/Card/Card.test.tsx b/src/components/Card/Card.test.tsx index 24ab4e2a..b76cfec9 100644 --- a/src/components/Card/Card.test.tsx +++ b/src/components/Card/Card.test.tsx @@ -1,8 +1,5 @@ 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", () => { @@ -10,14 +7,14 @@ test("render grade image", () => { , ); expect( - screen.getByRole("img", { name: `${Grade.TREE} image` }), + screen.getByRole("img", { name: `${"TREE"} image` }), ).toBeInTheDocument(); }); @@ -27,7 +24,7 @@ test("render github name", () => { , @@ -42,7 +39,7 @@ test("render cohort", () => { , @@ -59,7 +56,7 @@ test("render progress link", () => { , @@ -79,7 +76,7 @@ test("render certificate link", () => { , diff --git a/src/components/GradeImage/GradeImage.stories.tsx b/src/components/GradeImage/GradeImage.stories.tsx index a764b8dc..235faef2 100644 --- a/src/components/GradeImage/GradeImage.stories.tsx +++ b/src/components/GradeImage/GradeImage.stories.tsx @@ -1,11 +1,10 @@ import type { Meta, StoryObj } from "@storybook/react"; import Card from "./GradeImage"; -import { Grade } from "../../api/services/types"; const meta: Meta = { component: Card, args: { - grade: Grade.SEED, + grade: "SEED", width: 105, height: 128, }, @@ -13,10 +12,4 @@ const meta: Meta = { export default meta; -export const Seed: StoryObj = { - args: { - grade: Grade.SEED, - width: 105, - height: 128, - }, -}; +export const Default: StoryObj = {}; diff --git a/src/components/GradeImage/GradeImage.test.tsx b/src/components/GradeImage/GradeImage.test.tsx index 34fc262b..855c3838 100644 --- a/src/components/GradeImage/GradeImage.test.tsx +++ b/src/components/GradeImage/GradeImage.test.tsx @@ -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( @@ -24,7 +22,14 @@ test.each(Object.values(Grade))( test("set width and height", () => { render( , diff --git a/src/components/Sidebar/Sidebar.stories.tsx b/src/components/Sidebar/Sidebar.stories.tsx index 43c2ce47..43ee54b0 100644 --- a/src/components/Sidebar/Sidebar.stories.tsx +++ b/src/components/Sidebar/Sidebar.stories.tsx @@ -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, @@ -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; @@ -27,7 +26,7 @@ export const Default: StoryObj = { hardProgress: "3/5", solvedProblems: 16, totalProblems: 25, - grade: Grade.LEAF, + grade: "LEAF", cohorts: [1, 2, 3], currentCohort: 3, githubUsername: "testuser", @@ -42,7 +41,7 @@ export const HighProgress: StoryObj = { easyProgress: "10/10", mediumProgress: "10/10", hardProgress: "8/10", - grade: Grade.FRUIT, + grade: "FRUIT", currentCohort: 3, cohorts: [1, 2, 3], githubUsername: "testuser", @@ -57,7 +56,7 @@ export const NoProblems: StoryObj = { hardProgress: "0/0", solvedProblems: 0, totalProblems: 0, - grade: Grade.SEED, + grade: "SEED", currentCohort: 3, cohorts: [1, 2, 3], githubUsername: "testuser", diff --git a/src/components/Sidebar/Sidebar.test.tsx b/src/components/Sidebar/Sidebar.test.tsx index 3fd03e34..030ed28a 100644 --- a/src/components/Sidebar/Sidebar.test.tsx +++ b/src/components/Sidebar/Sidebar.test.tsx @@ -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( @@ -15,7 +14,7 @@ test("renders Sidebar with all elements", () => { profileUrl="example.png" currentCohort={3} cohorts={[1, 2, 3]} - grade={Grade.TREE} + grade={"TREE"} />, ); diff --git a/src/hooks/useMembers.test.ts b/src/hooks/useMembers.test.ts index e464acbb..8f0ec4a9 100644 --- a/src/hooks/useMembers.test.ts +++ b/src/hooks/useMembers.test.ts @@ -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"; @@ -15,7 +15,14 @@ function createMockMember(custom: Partial = {}): 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 }), diff --git a/src/pages/Leaderboard/Leaderboard.test.tsx b/src/pages/Leaderboard/Leaderboard.test.tsx index fff92958..0df89961 100644 --- a/src/pages/Leaderboard/Leaderboard.test.tsx +++ b/src/pages/Leaderboard/Leaderboard.test.tsx @@ -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"; @@ -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", + ]), }); } diff --git a/src/pages/Progress/Progress.test.tsx b/src/pages/Progress/Progress.test.tsx index 42afff2e..1cb11d59 100644 --- a/src/pages/Progress/Progress.test.tsx +++ b/src/pages/Progress/Progress.test.tsx @@ -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"; @@ -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: [], });