Skip to content

Commit

Permalink
Merge pull request #778 from barrymcgee/type-button
Browse files Browse the repository at this point in the history
Convert Button to Typescript
  • Loading branch information
hatched authored Dec 3, 2020
2 parents 3bc5a04 + 5d00379 commit 17ec233
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, HTMLProps } from "react";
import { useState, useEffect, ReactElement } from "react";
import classnames from "classnames";

import "./_banner.scss";
Expand All @@ -7,13 +7,13 @@ type Props = {
isActive: boolean;
children: any;
variant: "positive" | "caution" | "negative";
} & HTMLProps<HTMLElement>;
};

export default function Banner({
isActive,
children,
variant,
}: Props): React.ReactElement {
}: Props): ReactElement {
const [bannerClosed, setBannerClosed] = useState(false);

// Open banner every time banner variant changes
Expand Down
13 changes: 0 additions & 13 deletions src/components/Button/Button.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/Button/Button.test.js

This file was deleted.

22 changes: 22 additions & 0 deletions src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import { shallow } from "enzyme";

import Button from "./Button";

describe("Button", () => {
it("should display button text", () => {
const wrapper = shallow(
<Button onClick={() => jest.fn()}>Button text</Button>
);
expect(wrapper.find("button").text()).toStrictEqual("Button text");
});

it("should call handler when clicked", () => {
const handleClick = jest.fn();
const wrapper = shallow(
<Button onClick={() => handleClick()}>Button text</Button>
);
wrapper.find("button").simulate("click");
expect(handleClick).toBeCalledTimes(1);
});
});
18 changes: 18 additions & 0 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ReactElement } from "react";

import "./_button.scss";

type Props = {
onClick: () => void;
children: string;
};

const Button = ({ onClick, children }: Props): ReactElement => {
return (
<button className="p-button--filter" onClick={onClick}>
{children}
</button>
);
};

export default Button;
1 change: 1 addition & 0 deletions src/declarations/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "enzyme";

0 comments on commit 17ec233

Please sign in to comment.