Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into feature/spinner-component
  • Loading branch information
ghdtjgus76 committed Jul 26, 2024
2 parents 87dca04 + d5bd7e9 commit 0b28189
Show file tree
Hide file tree
Showing 23 changed files with 481 additions and 688 deletions.
9 changes: 4 additions & 5 deletions packages/shared-config/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ const config: Config = {
},
],
},

setupFilesAfterEnv: ["../shared-config/jest.setup.ts"],
verbose: true,
collectCoverage: true,
restoreMocks: true,
testMatch: [
"<rootDir>/src/**/*.test.(js|jsx|ts|tsx)",
"<rootDir>/app/**/*.test.(js|jsx|ts|tsx)",
Expand All @@ -32,6 +27,10 @@ const config: Config = {
"^@/(.*)$": "<rootDir>/src/$1",
"^@styled-system(.*)$": "<rootDir>/styled-system/$1",
},
setupFilesAfterEnv: ["../shared-config/jest.setup.ts"],
verbose: true,
collectCoverage: true,
restoreMocks: true,
};

export default config;
2 changes: 1 addition & 1 deletion packages/wow-tokens/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wowds-tokens",
"version": "0.0.2",
"version": "0.0.10",
"description": "",
"repository": {
"type": "git",
Expand Down
4 changes: 0 additions & 4 deletions packages/wow-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,5 @@ const config: StorybookConfig = {
}
return config;
},

typescript: {
reactDocgen: "react-docgen-typescript",
},
};
export default config;
14 changes: 10 additions & 4 deletions packages/wow-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# wowds-ui

## 0.1.5

### Patch Changes

- 0a4cf81: TextField 컴포넌트의 error, success 상태를 typing variant와 분리합니다.

## 0.1.4

### Patch Changes

- 51c6c59: - DropDown 의 value,text 에 대해서 제어할 수 있도록 수정하고 선택된 옵션값에 text 가 나타나도록 수정합니다.
- bd540a1: - Stepper의 CSS 에러를 개선합니다. (마지막 글자 잘림 현상 및 border Style 적용 안됨 이슈 해결)
- Textfield의 border Style이 적용 안되는 이슈를 해결합니다
- 51c6c59: - DropDown 의 value,text 에 대해서 제어할 수 있도록 수정하고 선택된 옵션값에 text 가 나타나도록 수정합니다.
- bd540a1: - Stepper의 CSS 에러를 개선합니다. (마지막 글자 잘림 현상 및 border Style 적용 안됨 이슈 해결)
- Textfield의 border Style이 적용 안되는 이슈를 해결합니다

## 0.1.3

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/wow-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wowds-ui",
"version": "0.1.4",
"version": "0.1.5",
"description": "",
"author": "gdsc-hongik",
"repository": {
Expand Down Expand Up @@ -127,6 +127,7 @@
"@storybook/test": "^8.1.9",
"@storybook/test-runner": "^0.18.2",
"@storybook/testing-library": "^0.2.2",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.11.24",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
Expand Down
10 changes: 5 additions & 5 deletions packages/wow-ui/src/components/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe("Checkbox component", () => {
expect(checkbox.checked).toBe(true);

await waitFor(() => {
expect(checkbox).toHaveAttribute("aria-checked", "true");
expect(checkbox).toBeChecked();
expect(checkbox).toHaveAttribute("aria-disabled", "false");
});

await userEvent.click(checkbox);
expect(checkbox.checked).toBe(false);

await waitFor(() => {
expect(checkbox).toHaveAttribute("aria-checked", "false");
expect(checkbox).not.toBeChecked();
expect(checkbox).toHaveAttribute("aria-disabled", "false");
});
});
Expand All @@ -48,7 +48,7 @@ describe("Checkbox component", () => {
const checkbox = getByLabelText("checkbox") as HTMLInputElement;

await userEvent.click(checkbox);
expect(checkbox.checked).toBe(true);
expect(checkbox).not.toBeChecked();
});

test("calls onMouseEnter and onMouseLeave", async () => {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("Checkbox component", () => {
expect(checkbox.checked).toBe(false);

await waitFor(() => {
expect(checkbox).toHaveAttribute("aria-checked", "false");
expect(checkbox).not.toBeChecked();
expect(checkbox).toHaveAttribute("aria-disabled", "false");
});
});
Expand All @@ -90,7 +90,7 @@ describe("Checkbox component", () => {
expect(checkbox.checked).toBe(false);

await waitFor(() => {
expect(checkbox).toHaveAttribute("aria-checked", "false");
expect(checkbox).not.toBeChecked();
expect(checkbox).toHaveAttribute("aria-disabled", "false");
});
});
Expand Down
4 changes: 3 additions & 1 deletion packages/wow-ui/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
onClick,
onKeyDown,
});

return (
<styled.label
alignItems="center"
Expand All @@ -101,12 +102,13 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
>
<styled.span alignItems="center" display="flex" position="relative">
<styled.input
aria-checked={checked}
aria-disabled={disabled}
aria-label={inputProps?.["aria-label"] ?? "checkbox"}
checked={checked}
{...(pressed && { "data-pressed": true })}
id={id}
ref={ref}
role="checkbox"
tabIndex={0}
type="checkbox"
className={checkboxStyle({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const meta = {
type: "boolean",
},
},
isChecked: {
ischecked: {
description: "isChecked는 외부에서 제어할 활성 상태를 나타냅니다.",
table: {
type: { summary: "boolean" },
Expand All @@ -59,7 +59,7 @@ const meta = {
label: {
description: "칩에 들어가게 될 텍스트입니다.",
table: {
type: { summary: "string", required: true },
type: { summary: "string" },
},
control: {
type: "text",
Expand All @@ -70,28 +70,22 @@ const meta = {
table: {
type: { summary: "() => void" },
},
control: {
type: "function",
},
control: false,
},
onDelete: {
description: "칩에 대한 필터를 제거하기 위한 함수입니다.",
table: {
type: { summary: "() => void" },
},
control: {
type: "function",
},
control: false,
},
onKeyDown: {
description:
"칩이 포커스됐을 때 엔터 키 또는 스페이스 바를 눌렀을 때 동작할 이벤트입니다.",
table: {
type: { summary: "() => void" },
},
control: {
type: "function",
},
control: false,
},
style: {
description: "칩의 커스텀 스타일을 설정합니다.",
Expand Down
124 changes: 124 additions & 0 deletions packages/wow-ui/src/components/Chip/Chip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { render, type RenderResult, waitFor } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";

import Chip from "@/components/Chip";

describe("Chip rendering Test", () => {
let renderChip: RenderResult;
beforeEach(() => {
renderChip = render(<Chip as="div" label="Chip" />);
});

it("should render Chip", () => {
const { getByText } = renderChip;
expect(getByText("Chip")).toBeInTheDocument();
});

it("should render with attributes aria-disabled to be false by default", () => {
const chipComponent = renderChip.container.querySelector("div");

expect(chipComponent).toHaveAttribute("aria-disabled", "false");
});
});

describe("Chip toggle Test", () => {
let renderChip: RenderResult;
beforeEach(() => {
renderChip = render(<Chip as="button" clickable={true} label="Chip" />);
});

it("should toggle state when onClick event is fired", async () => {
const chipComponent = renderChip.getByRole("checkbox");
const user = userEvent.setup();

await user.click(chipComponent);
expect(chipComponent).toHaveAttribute("aria-checked", "true");
await user.click(chipComponent);
expect(chipComponent).toHaveAttribute("aria-checked", "false");
});

it("should toggle state when Enter key is pressed", async () => {
const chipComponent = renderChip.getByRole("checkbox");
userEvent.type(chipComponent, "{enter}");
await waitFor(() => {
expect(chipComponent).toHaveAttribute("aria-checked", "true");
});
userEvent.type(chipComponent, "{enter}");
await waitFor(() => {
expect(chipComponent).toHaveAttribute("aria-checked", "false");
});
});

it("should toggle state when Space key is pressed", async () => {
const chipComponent = renderChip.getByRole("checkbox");

await userEvent.type(chipComponent, "{space}");
expect(chipComponent).toHaveAttribute("aria-checked", "true");
await userEvent.type(chipComponent, "{space}");
expect(chipComponent).toHaveAttribute("aria-checked", "false");
});
});

describe("Chip disabled Test", () => {
let renderChip: RenderResult;
beforeEach(() => {
renderChip = render(<Chip disabled={true} label="Chip" />);
});

it("should render with attributes aria-disabled to be true", () => {
const chipComponent = renderChip.container.querySelector("button");

expect(chipComponent).toHaveAttribute("aria-disabled", "true");
});

it("should not allow focusing", () => {
const chipComponent = renderChip.container.querySelector("button");
userEvent.click(chipComponent!!);

expect(chipComponent).not.toHaveFocus();
});
});

describe("external control and events", () => {
let renderChip: RenderResult;

it("should fire external onClick event", async () => {
renderChip = render(<Chip clickable label="Chip" />);
const chipComponent = renderChip.getByRole("checkbox");
const user = userEvent.setup();
const onClickHandler = jest.fn();
chipComponent.onclick = onClickHandler;

await user.click(chipComponent);
expect(onClickHandler).toHaveBeenCalled();
});

it("should fire external onKeyDown event", async () => {
renderChip = render(<Chip clickable as="button" label="Chip" />);
const user = userEvent.setup();
const chipComponent = renderChip.getByRole("checkbox");
const onKeyDownHandler = jest.fn();
chipComponent.onkeydown = onKeyDownHandler;

await user.type(chipComponent, "{enter}");
expect(onKeyDownHandler).toHaveBeenCalled();
await user.type(chipComponent, "{space}");
expect(onKeyDownHandler).toHaveBeenCalled();
});

it("should toggle external checked state when onClick event fired", async () => {
const user = userEvent.setup();
let checked = false;
const handleChange = () => {
checked = !checked;
};
const rendered = render(<Chip clickable as="button" label="Chip" />);
const chipComponent = rendered.getByRole("checkbox");
chipComponent.onchange = handleChange;

await user.click(chipComponent);

expect(chipComponent).toHaveAttribute("aria-checked", "true");
expect(chipComponent).toHaveAttribute("aria-disabled", "false");
});
});
Loading

0 comments on commit 0b28189

Please sign in to comment.