-
Notifications
You must be signed in to change notification settings - Fork 4
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
6 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
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
78 changes: 71 additions & 7 deletions
78
packages/react/src/composite/Collapsible/src/collapsible.spec.tsx
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,17 +1,81 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
|
||
import { Collapsible } from "./Collapsible"; | ||
import { CollapsibleProperties } from "./collapsible.types"; | ||
import { CollapsibleBodyProps } from "./components/CollapsibleBody/collapsibleBody.types"; | ||
|
||
const makeSut = (props: CollapsibleProperties) => { | ||
render(<Collapsible {...props} data-testid="collapsible-element" />); | ||
}; | ||
const clickMock = jest.fn(); | ||
|
||
describe("GIVEN <Box />", () => { | ||
const makeSut = (props: CollapsibleBodyProps, open = false) => | ||
render( | ||
<Collapsible open={open}> | ||
<Collapsible.Item> | ||
<button data-testid="click" type="button" onClick={clickMock}> | ||
Click | ||
</button> | ||
</Collapsible.Item> | ||
<Collapsible.Body {...props} data-testid="collapsible-body-element" /> | ||
</Collapsible> | ||
); | ||
|
||
describe("GIVEN <Collapsible />", () => { | ||
describe("WHEN rendered", () => { | ||
it("THEN should render the submitted content", async () => { | ||
it("THEN should render content", () => { | ||
makeSut({ children: "My content" }); | ||
expect(screen.queryByText("My content")).toBeDefined(); | ||
}); | ||
|
||
it("THEN should render content and click in button", async () => { | ||
makeSut({ children: "My content" }); | ||
expect(screen.queryByText("My content")).toBeNull(); | ||
await fireEvent.click(screen.getByTestId("click")); | ||
expect(clickMock).toBeCalledTimes(1); | ||
}); | ||
|
||
it("THEN should render content from body", () => { | ||
makeSut({ children: "My content" }, true); | ||
expect(screen.queryByText("My content")).not.toBeNull(); | ||
}); | ||
|
||
it("THEN should not render content from body when collapsible is open but body is visible when closed", () => { | ||
makeSut({ children: "My content", visibleWhen: "closed" }, true); | ||
expect(screen.queryByText("My content")).toBeNull(); | ||
}); | ||
|
||
it("THEN should not render content from body when collapsible is closed but body is visible when open", () => { | ||
makeSut({ children: "My content", visibleWhen: "open" }, false); | ||
expect(screen.queryByText("My content")).toBeNull(); | ||
}); | ||
|
||
it("THEN should open body with no animation", () => { | ||
makeSut({ children: "My content", direction: "none" }, true); | ||
expect(screen.queryByText("My content")).not.toBeNull(); | ||
expect( | ||
screen | ||
.queryByText("My content") | ||
?.classList.contains("nimbus-collapsible_body__63v3i0") | ||
).toBe(true); | ||
}); | ||
|
||
it("THEN should open body with animation from top", () => { | ||
makeSut({ children: "My content", direction: "top" }, true); | ||
expect(screen.queryByText("My content")).not.toBeNull(); | ||
expect( | ||
screen | ||
.queryByText("My content") | ||
?.classList.contains( | ||
"nimbus-collapsible_bodyReversalAnimation__63v3i4" | ||
) | ||
).toBe(true); | ||
}); | ||
it("THEN should open body with animation from bottom", () => { | ||
makeSut({ children: "My content", direction: "bottom" }, true); | ||
expect(screen.queryByText("My content")).not.toBeNull(); | ||
expect( | ||
screen | ||
.queryByText("My content") | ||
?.classList.contains("nimbus-collapsible_bodyAnimation__63v3i2") | ||
).toBe(true); | ||
}); | ||
}); | ||
}); |
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
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