Skip to content

Commit

Permalink
Merge pull request #101 from appsmithorg/release
Browse files Browse the repository at this point in the history
feat: Button component
  • Loading branch information
Tanvi Bhakta committed Aug 8, 2022
2 parents af368e5 + 4c35768 commit 96ee6b2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-wasps-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@appsmithorg/design-system": patch
---

feat: Added button test
46 changes: 46 additions & 0 deletions packages/design-system/src/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import Button, { Size } from "./index";
import { create } from "react-test-renderer";

describe("<Button /> component - render", () => {
it("renders the button component with text passed as input", () => {
render(<Button size={Size.medium} tag="button" text="Run" />);
expect(screen.getByRole("button")).toHaveTextContent("Run");
});
});

describe("<Button /> component - loading behaviour", () => {
it("calls the onclick handler when not in loading state", () => {
const fn = jest.fn();
const tree = create(
<Button
isLoading={false}
onClick={fn}
size={Size.medium}
tag="button"
text="Run"
/>,
);
const button = tree.root.findByType("button");
button.props.onClick();
expect(fn.mock.calls.length).toBe(1);
});

it("does not call the onclick handler when in loading state", () => {
const fn = jest.fn();
const tree = create(
<Button
isLoading
onClick={fn}
size={Size.medium}
tag="button"
text="Run"
/>,
);
const button = tree.root.findByType("button");
button.props.onClick();
expect(fn.mock.calls.length).toBe(0);
});
});

1 comment on commit 96ee6b2

@vercel
Copy link

@vercel vercel bot commented on 96ee6b2 Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.