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

refactor: update dependencies and add tests #72

Merged
merged 28 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6869513
chore: update dependencies
brankoconjic May 10, 2024
89d0bf5
chore: update dependencies
brankoconjic May 10, 2024
3d5a40f
fix: fix typo
brankoconjic May 10, 2024
daab957
fix(docs): add missing CSS
brankoconjic May 11, 2024
448d409
docs(wedges): add changesets
brankoconjic May 11, 2024
1a8aba3
chore: bump node version
brankoconjic May 11, 2024
0d9e4e0
style: fix CSS inconsistencies
brankoconjic May 11, 2024
c2a3422
refactor: improve jest coverage report
brankoconjic May 11, 2024
015651b
test(wedges): add Alert tests
brankoconjic May 11, 2024
7201787
chore: update dependencies
brankoconjic May 11, 2024
5b28a44
test(wedges): update AvatarGroup tests
brankoconjic May 11, 2024
e8779b5
feat(Avatar): add delayMs prop
brankoconjic May 11, 2024
3b2b341
test(wedges): improve Avatar tests
brankoconjic May 11, 2024
a0150e1
refactor(Avatar): remove default value
brankoconjic May 11, 2024
0847e24
test: improve Badge tests
brankoconjic May 11, 2024
aa1a227
test(AvatarGroup): improve coverage
brankoconjic May 11, 2024
3e13d3d
test(wedges): improve test cases
brankoconjic May 11, 2024
19a10a2
fix(Kbd): allow keys to be a string
brankoconjic May 11, 2024
436ada5
fix(Kbd): don't render if invalid key
brankoconjic May 11, 2024
be18ecf
test(Kbd): add Kbd tests
brankoconjic May 11, 2024
7ba8c81
fix(docs): fix type error
brankoconjic May 11, 2024
21b1cfb
test(Tag): refactor tests
brankoconjic May 11, 2024
ed7cf26
test(wedges): set verbose inline
brankoconjic May 11, 2024
c8c1c54
test(Textarea): add tests
brankoconjic May 11, 2024
1cc3ce8
test(Toggle): add tests
brankoconjic May 11, 2024
9962ee8
refactor: merge main
brankoconjic May 11, 2024
8871463
build: run build
brankoconjic May 11, 2024
70ee5ef
docs: add changesets
brankoconjic May 11, 2024
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
5 changes: 5 additions & 0 deletions .changeset/fluffy-dogs-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": minor
---

add Kbd tests
5 changes: 5 additions & 0 deletions .changeset/fuzzy-spoons-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": minor
---

add Textarea tests
5 changes: 5 additions & 0 deletions .changeset/large-apes-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": patch
---

improve Badge tests
5 changes: 5 additions & 0 deletions .changeset/silent-books-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": patch
---

improve AvatarGroup test coverage
5 changes: 5 additions & 0 deletions .changeset/silver-lobsters-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": minor
---

add Toggle tests
5 changes: 5 additions & 0 deletions .changeset/soft-jobs-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": minor
---

add `delayMs` prop for the Avatar component
5 changes: 5 additions & 0 deletions .changeset/sour-walls-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": minor
---

add Avatar tests
5 changes: 5 additions & 0 deletions .changeset/stale-rings-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lemonsqueezy/wedges": patch
---

improve Tag tests
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ In the Wedges project, we utilize a variety of tools to ensure code quality, con

- **[ESLint](https://eslint.org/)**: for code linting. Make sure to check and fix any linting issues before submitting your code.

- **[Jest](https://jestjs.io/)**: for testing. We encourage writing tests for new features and bug fixes.
- **[React Testing Library](https://testing-library.com/)**: for testing. We encourage writing tests for new features and bug fixes.

- **[Jest Framework](https://jestjs.io/)**: for running tests.

- **[husky](https://typicode.github.io/husky/#/)**: for Git hooks. It ensures that linters, and other checks are passed before commits and pushes.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,7 @@ export function Example() {
return (
<Tag
closable
onClose={(e) => {
onClose={(e: React.MouseEvent) => {
e.preventDefault();
// eslint-disable-next-line no-console
alert("Custom onClose callback with preventDefault()");
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/examples/tag/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function Example() {
return (
<Tag
closable
onClose={(e) => {
onClose={(e: React.MouseEvent) => {
e.preventDefault();
// eslint-disable-next-line no-console
alert("Custom onClose callback with preventDefault()");
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/src/styles/docsearch.css
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
.DocSearch-NoResults .DocSearch-Help {
margin-left: 0.75rem;
margin-bottom: 0.5rem;
font-family: theme("fontFamily.display");
font-family: theme("fontFamily.sans");
color: var(--docsearch-heading-color);
font-size: 0.875rem;
font-weight: 500;
Expand Down
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ const config = {
},
testEnvironment: "jsdom",
collectCoverageFrom: [
"packages/**/*.tsx",
"packages/wedges/src/components/**/*.tsx",
"!packages/**/icons/**/*", // Exclude files in the 'icons' folder
],
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
preset: "ts-jest",
testMatch: ["**/?(*.)+(test).+(ts|tsx|js)"],
verbose: true,
};

export default config;
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"format:fix": "prettier --write ./packages/**/src ./apps/** --cache",
"lint": "turbo run lint",
"lint:fix": "turbo run lint:fix",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest --passWithNoTests",
"test:coverage": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage --passWithNoTests",
"test": "NODE_OPTIONS='--experimental-vm-modules' jest --passWithNoTests --coverage --coverageReporters=\"text-summary\"",
"test:coverage": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage --verbose --passWithNoTests",
"prepare": "husky",
"version": "changeset version",
"version:dev": "changeset version --snapshot --no-git-tag --tag dev",
Expand All @@ -26,12 +26,14 @@
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.11",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@wedges/eslint-config": "workspace:*",
"clsx": "^2.1.1",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand All @@ -40,12 +42,11 @@
"react": "^18.3.1",
"react-dom": "18.3.1",
"rimraf": "^5.0.6",
"tailwind-merge": "^2.3.0",
"tailwindcss": "3.4.3",
"ts-jest": "^29.1.2",
"turbo": "^1.13.3",
"typescript": "^5.4.5",
"tailwind-merge": "^2.3.0",
"clsx": "^2.1.1"
"typescript": "^5.4.5"
},
"packageManager": "pnpm@9.1.0",
"dependencies": {
Expand Down
73 changes: 73 additions & 0 deletions packages/wedges/src/components/Alert/Alert.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as React from "react";
import { jest } from "@jest/globals";
import { fireEvent, render, screen } from "@testing-library/react";

import "@testing-library/jest-dom";

import { Alert } from ".";

const TEST_TEXT = "Warning!";

describe("Alert", () => {
it("should forward ref to the HTMLDivElement", () => {
const ref = React.createRef<HTMLDivElement>();
render(<Alert ref={ref}>{TEST_TEXT}</Alert>);

if (ref.current !== null) {
expect(ref.current).toBeInstanceOf(HTMLDivElement);
expect(ref.current.textContent).toBe(TEST_TEXT);
} else {
fail("ref.current is null");
}
});

test("should render alert role", () => {
render(<Alert>{TEST_TEXT}</Alert>);
expect(screen.getByRole("alert")).toBeInTheDocument();
});

describe("when the close button is clicked", () => {
test("then it should invoke onClose callback", () => {
const handleClose = jest.fn();
render(<Alert closable={true} onClose={handleClose} />);
fireEvent.click(screen.getByLabelText("Close"));
expect(handleClose).toHaveBeenCalled();
});

test("then it should no longer be visible", () => {
const { queryByRole } = render(<Alert closable={true} />);
fireEvent.click(screen.getByLabelText("Close"));
expect(queryByRole("alert")).not.toBeInTheDocument();
});
});

describe("given it has a string title", () => {
test("then it should display the title within an AlertTitle component", () => {
render(<Alert title={TEST_TEXT} />);
expect(screen.getByText(TEST_TEXT)).toBeInTheDocument();
});
});

describe("given it has a component as a title", () => {
test("then it should render the title as-is", () => {
const titleElement = <span style={{ fontWeight: "bold" }}>{TEST_TEXT}</span>;
render(<Alert title={titleElement} />);
expect(screen.getByText(TEST_TEXT)).toHaveStyle("font-weight: bold");
});
});

describe("given it has a custom before and after slot", () => {
test("then it should render these elements correctly", () => {
render(<Alert before={<span>Before</span>} after={<button>After</button>} />);
expect(screen.getByText("Before")).toBeInTheDocument();
expect(screen.getByText("After")).toBeInTheDocument();
});
});

describe("given children are provided", () => {
test("Then it should render the children inside the Alert", () => {
render(<Alert>{TEST_TEXT}</Alert>);
expect(screen.getByText(TEST_TEXT)).toBeInTheDocument();
});
});
});
Loading
Loading