From 9f99be9196ee41aadb60d455ad422164ae7afb1e Mon Sep 17 00:00:00 2001 From: Thien Do <5953369+thien-do@users.noreply.github.com> Date: Tue, 23 Jul 2024 21:58:25 +0700 Subject: [PATCH] remove test --- test/.gitignore | 3 - test/.swcrc | 31 ---------- test/jest.config.js | 16 ------ test/package.json | 24 -------- test/src/button.test.tsx | 92 ------------------------------ test/src/checkbox.test.tsx | 49 ---------------- test/src/config/jest-setup.js | 1 - test/src/input.test.tsx | 65 --------------------- test/src/radio.test.tsx | 58 ------------------- test/src/select.test.tsx | 103 ---------------------------------- test/tsconfig.json | 11 ---- 11 files changed, 453 deletions(-) delete mode 100644 test/.gitignore delete mode 100644 test/.swcrc delete mode 100644 test/jest.config.js delete mode 100644 test/package.json delete mode 100644 test/src/button.test.tsx delete mode 100644 test/src/checkbox.test.tsx delete mode 100644 test/src/config/jest-setup.js delete mode 100644 test/src/input.test.tsx delete mode 100644 test/src/radio.test.tsx delete mode 100644 test/src/select.test.tsx delete mode 100644 test/tsconfig.json diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index 521a8db6..00000000 --- a/test/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/dist -/node_modules -/coverage diff --git a/test/.swcrc b/test/.swcrc deleted file mode 100644 index 30025bf1..00000000 --- a/test/.swcrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "jsc": { - "target": "es2017", - "parser": { - "syntax": "typescript", - "tsx": true, - "decorators": false, - "dynamicImport": false - }, - "transform": { - "react": { - "pragma": "React.createElement", - "pragmaFrag": "React.Fragment", - "throwIfNamespace": true, - "development": false, - "useBuiltins": false, - "runtime": "automatic" - }, - "hidden": { - "jest": true - } - } - }, - "module": { - "type": "commonjs", - "strict": false, - "strictMode": true, - "lazy": false, - "noInterop": false - } -} diff --git a/test/jest.config.js b/test/jest.config.js deleted file mode 100644 index dafd42c8..00000000 --- a/test/jest.config.js +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-env node */ - -// https://jestjs.io/docs/configuration -module.exports = { - collectCoverage: true, - coverageDirectory: "coverage", - coverageProvider: "v8", - testEnvironment: "jsdom", - testMatch: ["/src/**/*.test.ts?(x)"], - setupFilesAfterEnv: ["/src/config/jest-setup.js"], - resetMocks: true, - restoreMocks: true, - transform: { - "^.+\\.(ts|js|tsx|jsx)$": "@swc/jest", - }, -}; diff --git a/test/package.json b/test/package.json deleted file mode 100644 index 729b1dbd..00000000 --- a/test/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@moai/test", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "private": true, - "scripts": { - "_test": "jest" - }, - "devDependencies": { - "@moai/core": "*", - "@swc/core": "^1.2.174", - "@swc/jest": "^0.2.20", - "@testing-library/dom": "^8.1.0", - "@testing-library/jest-dom": "^5.14.1", - "@testing-library/react": "^12.0.0", - "@testing-library/user-event": "^13.2.0", - "@types/jest": "^26.0.24", - "jest": "^27.0.6", - "react": "^17.0.2", - "react-dom": "^17.0.2", - "typescript": "^4.3.5" - } -} diff --git a/test/src/button.test.tsx b/test/src/button.test.tsx deleted file mode 100644 index 0c660c48..00000000 --- a/test/src/button.test.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { render, screen } from "@testing-library/react"; -import { Button, ButtonProps } from "@moai/core"; -import { useState } from "react"; -import userEvent from "@testing-library/user-event"; - -describe("Button", () => { - test("Should throws if has no content", () => { - jest.spyOn(console, "error").mockImplementation(() => void 0); - expect(() => { - render( - - ); - }; - - test("Should trigger `onClick` handler", () => { - render(); - const button = screen.getByRole("button", { name: buttonLabel }); - userEvent.click(button); - const div = screen.getByText("Name is", { exact: false }); - expect(div).toHaveTextContent("Name is Eevee"); - }); - - test("Should not trigger `onClick` when `disabled` is set", () => { - render(); - const button = screen.getByRole("button", { name: buttonLabel }); - expect(button).toBeDisabled(); - userEvent.click(button); - const div = screen.getByText("Name is", { exact: false }); - expect(div).toHaveTextContent("Name is Pikachu"); - }); - - test("Should be disabled when `busy` is set", () => { - render(); - const button = screen.getByRole("button", { name: buttonLabel }); - expect(button).toBeDisabled(); - userEvent.click(button); - const div = screen.getByText("Name is", { exact: false }); - expect(div).toHaveTextContent("Name is Pikachu"); - }); - - describe("Render an a if `href` is provided", () => { - test("Renders correctly", () => { - render( - - ); - - expect( - screen.queryByRole("button", { name: buttonLabel }) - ).not.toBeInTheDocument(); - const link = screen.getByRole("link", { name: buttonLabel }); - expect(link).toHaveAttribute("rel", "noopener"); - }); - - test("Should trigger `onClick` event", () => { - const onClickMockFn = jest.fn(); - render( - - ); - const link = screen.getByRole("link", { name: buttonLabel }); - userEvent.click(link); - expect(onClickMockFn).toHaveBeenCalledTimes(1); - }); - }); - - test("Should contain id attribute", () => { - render(); - const button = screen.getByRole("button", { name: buttonLabel }); - expect(button.id).toBe("submit-button"); - }); -}); diff --git a/test/src/checkbox.test.tsx b/test/src/checkbox.test.tsx deleted file mode 100644 index 58e6e954..00000000 --- a/test/src/checkbox.test.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { render, screen, fireEvent } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; -import "@testing-library/jest-dom"; -import { useState } from "react"; -import { Checkbox, Button } from "@moai/core"; - -describe("Testing Checkbox Uncontrolled Prop", () => { - test("Checkbox should be checked when set DefaultChecked", () => { - render(foo); - - const checkboxElement = screen.getByRole("checkbox"); - - expect(checkboxElement).toBeChecked(); - }); -}); - -describe("Testing Checkbox Disabled Prop", () => { - test("Checkbox shouldn't change state when disabled", () => { - render(foo); - - const checkboxElement = screen.getByRole("checkbox"); - userEvent.click(checkboxElement); - - expect(checkboxElement).not.toBeChecked(); - }); -}); - -describe("Testing Checkbox Controlled Prop", () => { - const TestingCheckbox = () => { - const [checked, setChecked] = useState(false); - return ( -
- - foo - - -
- ); - }; - test("Checkbox should be checked when set DefaultChecked", () => { - render(); - - const checkboxElement = screen.getByRole("checkbox"); - const buttonElement = screen.getByRole("button"); - - fireEvent.click(buttonElement); - expect(checkboxElement).toBeChecked(); - }); -}); diff --git a/test/src/config/jest-setup.js b/test/src/config/jest-setup.js deleted file mode 100644 index d0de870d..00000000 --- a/test/src/config/jest-setup.js +++ /dev/null @@ -1 +0,0 @@ -import "@testing-library/jest-dom"; diff --git a/test/src/input.test.tsx b/test/src/input.test.tsx deleted file mode 100644 index 5321556d..00000000 --- a/test/src/input.test.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { Button, Input } from "@moai/core"; -import { render, screen } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; -import { useState } from "react"; - -describe("Input Controlled", () => { - const ControlledInput = () => { - const [value, setValue] = useState("Pikachu"); - return ( -
- - -
Pokemon is {value}
- -
- ); - }; - test("Changes in the Input should be reflected outside", () => { - render(); - const input = screen.getByRole("textbox", { name: "Name" }); - userEvent.clear(input); - userEvent.type(input, "Mew"); - const div = screen.getByText("Pokemon is", { exact: false }); - expect(div).toHaveTextContent("Pokemon is Mew"); - }); - test("Changes outside should be reflected in the Input", () => { - render(); - const button = screen.getByRole("button", { name: "Change" }); - userEvent.click(button); - const input = screen.getByRole("textbox", { name: "Name" }); - expect(input).toHaveDisplayValue("Eevee"); - }); -}); - -describe("Input Uncontrolled", () => { - const UncontrolledInput = () => ( -
- - -
- ); - test("Direct changes to the Input should work", () => { - render(); - const input = screen.getByRole("textbox", { name: "Name" }); - userEvent.clear(input); - userEvent.type(input, "Mew"); - expect(input).toHaveDisplayValue("Mew"); - }); -}); - -describe("Input Props", () => { - test("Should not allow letters when type is `number`", () => { - render(); - const input = screen.getByRole("spinbutton"); - userEvent.type(input, "foo4"); - expect(input).toHaveDisplayValue("1234"); - }); - test("Should not change when `disabled` is set", async () => { - render(); - const input = screen.getByRole("textbox"); - userEvent.type(input, "bar"); - expect(input).toBeDisabled(); - expect(input).toHaveDisplayValue("foo"); - }); -}); diff --git a/test/src/radio.test.tsx b/test/src/radio.test.tsx deleted file mode 100644 index d1a26918..00000000 --- a/test/src/radio.test.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { render, screen, fireEvent } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; -import "@testing-library/jest-dom"; -import { useState } from "react"; -import { Radio, Button } from "@moai/core"; - -describe("Testing Checkbox Uncontrolled Prop", () => { - test("Checkbox should be checked when set DefaultChecked", () => { - render( - - foo - - ); - - const radioElement = screen.getByRole("radio"); - - expect(radioElement).toBeChecked(); - }); -}); - -describe("Testing Checkbox Disabled Prop", () => { - test("Checkbox shouldn't change state when disabled", () => { - render( - - foo - - ); - - const radioElement = screen.getByRole("radio"); - userEvent.click(radioElement); - - expect(radioElement).not.toBeChecked(); - }); -}); - -describe("Testing Checkbox Controlled Prop", () => { - const TestingCheckbox = () => { - const [checked, setChecked] = useState(false); - return ( -
- - foo - - -
- ); - }; - - test("Checkbox should be checked when set DefaultChecked", () => { - render(); - - const radioElement = screen.getByRole("radio"); - const buttonElement = screen.getByRole("button"); - - fireEvent.click(buttonElement); - expect(radioElement).toBeChecked(); - }); -}); diff --git a/test/src/select.test.tsx b/test/src/select.test.tsx deleted file mode 100644 index 8a8f85d9..00000000 --- a/test/src/select.test.tsx +++ /dev/null @@ -1,103 +0,0 @@ -import { render, screen, fireEvent } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; -import "@testing-library/jest-dom"; -import { useState } from "react"; -import { Select, Button } from "@moai/core"; - -const SELECTIONS = [ - { value: "red", id: "red", label: "Red" }, - { value: "blue", id: "blue", label: "Blue" }, - { value: "green", id: "green", label: "Green" }, -]; - -describe("Testing Select Uncontrolled Props", () => { - test("Select value should be default value", () => { - render( -
- - -
- ); - - const selectElement = screen.getByLabelText("select"); - - userEvent.selectOptions(selectElement, "green"); - expect(selectElement).toHaveValue("red"); - }); - - test("Disabled option shouldn't change Select value", () => { - render( -
- -