-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
142 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { render } from "@testing-library/react"; | ||
import App from "./App"; | ||
|
||
test("renders app component", () => { | ||
render(<App />); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { render } from "@testing-library/react"; | ||
import Badge from "components/Badge"; | ||
|
||
describe("Badge", () => { | ||
it("should render badge content", () => { | ||
const { container } = render(<Badge color="red" content="badge content" />); | ||
expect(container.firstChild).toHaveTextContent("badge content"); | ||
}); | ||
|
||
it("should render correctly", () => { | ||
const { asFragment } = render(<Badge color="red" content="badge content" />); | ||
|
||
expect(asFragment()).toMatchInlineSnapshot(` | ||
<DocumentFragment> | ||
<span | ||
class="MuiTypography-root MuiTypography-caption" | ||
> | ||
badge content | ||
<span | ||
class="makeStyles-root-3 makeStyles-root-4" | ||
color="red" | ||
/> | ||
</span> | ||
</DocumentFragment> | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
import CreateSecretForm from "components/CreateSecretForm"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
describe("CreateSecretForm", () => { | ||
describe("Should generate token with valid inputs", () => { | ||
it("should call submit function", async () => { | ||
const onSubmitMock = jest.fn(); | ||
const initialValues = { | ||
secret: "", | ||
password: "", | ||
accessType: true, | ||
accesses: 1, | ||
lifetime: { value: "168h", label: "7 days" } | ||
}; | ||
|
||
render(<CreateSecretForm onSubmit={onSubmitMock} initialValues={initialValues} />); | ||
|
||
const messageInput = screen.getByPlaceholderText(/type your secret here/i); | ||
const submitButton = screen.getByRole("button", { name: /get token/i }); | ||
|
||
userEvent.type(messageInput, "the eagle flies at midnight"); | ||
userEvent.click(submitButton); | ||
waitFor(() => expect(onSubmitMock).toHaveBeenCalledTimes(1)); | ||
}); | ||
}); | ||
|
||
describe("Should not generate token with invalid inputs", () => { | ||
it("render the message validation error", async () => { | ||
const onSubmitMock = jest.fn(); | ||
const { getByPlaceholderText, container } = render( | ||
<CreateSecretForm onSubmit={onSubmitMock} initialValues={{}} /> | ||
); | ||
const messageInput = getByPlaceholderText(/type your secret here/i); | ||
|
||
act(() => { | ||
fireEvent.blur(messageInput); | ||
}); | ||
|
||
waitFor(() => expect(container.innerHTML).toMatch(/you must add a secret/i)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { render } from "@testing-library/react"; | ||
import Footer from "components/Footer"; | ||
|
||
describe("Footer", () => { | ||
it("should render correctly", () => { | ||
const { asFragment } = render(<Footer />); | ||
|
||
expect(asFragment()).toMatchInlineSnapshot(` | ||
<DocumentFragment> | ||
<footer | ||
class="makeStyles-root-1" | ||
> | ||
<p | ||
class="MuiTypography-root MuiTypography-body1" | ||
> | ||
Made with ♠ by | ||
<a | ||
class="MuiTypography-root MuiLink-root MuiLink-underlineHover makeStyles-text__white-2 MuiTypography-colorPrimary" | ||
href="https://rotational.io" | ||
target="_blank" | ||
> | ||
Rotational Labs | ||
</a> | ||
</p> | ||
<div | ||
class="MuiBox-root MuiBox-root-3" | ||
> | ||
<div | ||
aria-label="add" | ||
class="MuiBox-root MuiBox-root-4" | ||
style="cursor: pointer;" | ||
title="connected to " | ||
> | ||
<span | ||
class="MuiTypography-root MuiTypography-caption" | ||
> | ||
status | ||
<span | ||
class="makeStyles-root-5 makeStyles-root-6" | ||
color="green" | ||
/> | ||
</span> | ||
<span | ||
class="MuiTypography-root MuiTypography-caption" | ||
> | ||
version: | ||
</span> | ||
</div> | ||
</div> | ||
</footer> | ||
</DocumentFragment> | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { FormikHelpers, FormikValues } from "formik"; | ||
import { ObjectSchema } from "yup"; | ||
|
||
export type CreateSecretFormProps = { | ||
onSubmit: (values: FormikValues, helpers: FormikHelpers<any>) => void; | ||
validationSchema: ObjectSchema<any>; | ||
initialValues: FormikValues; | ||
}; |