Skip to content

Commit

Permalink
Fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Nov 21, 2024
1 parent 12b828a commit b465b2b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/components/Checkbox.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describe('Checkbox', () => {
).toJSON();
expect(tree).toMatchSnapshot();
});
it('handles disabled state', () => {
const tree = renderer.create(
<Checkbox disabled>Click Me</Checkbox>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
11 changes: 6 additions & 5 deletions src/components/SidebarNav.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe("SidebarNav", () => {
});

describe("SidebarNavBase", () => {
it("outside clicks don't set nav to collapsed if the ref is null", async () => {
it("outside clicks don't set nav to collapsed if the ref is null", () => {
const setNavCollapsedFn = jest.fn();
render(
<SidebarNavBase
Expand All @@ -179,12 +179,13 @@ describe("SidebarNav", () => {
setNavIsCollapsed={setNavCollapsedFn}
>
Content
</SidebarNavBase>,
</SidebarNavBase>
);
// setNavIsCollapsed fires on mount
expect(setNavCollapsedFn).toHaveBeenCalledTimes(1);
setNavCollapsedFn.mockReset();
fireEvent.mouseDown(document);

fireEvent.click(document);

expect(setNavCollapsedFn).not.toHaveBeenCalled();

Expand All @@ -198,11 +199,11 @@ describe("SidebarNav", () => {
sidebarNavRef={{ current: null }}
>
Content
</SidebarNavBase>,
</SidebarNavBase>
);

setNavCollapsedFn.mockReset();
fireEvent.mouseDown(document);
fireEvent.click(document);

expect(setNavCollapsedFn).not.toHaveBeenCalled();
});
Expand Down
5 changes: 3 additions & 2 deletions src/components/SidebarNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LeftArrow } from "../svgs/LeftArrow";
import { RightArrow } from "../svgs/RightArrow";
import { FocusScope } from "react-aria";
import { BodyPortal } from "../BodyPortal";

import {
NavBody,
NavFooter,
Expand Down Expand Up @@ -64,7 +65,7 @@ export const SidebarNavBase = ({
isMobile &&
!navIsCollapsed &&
sidebarNavRef?.current &&
!sidebarNavRef?.current.contains(event.target)
!sidebarNavRef.current.contains(event.target)
) {
setNavIsCollapsed(true);
}
Expand Down Expand Up @@ -95,7 +96,7 @@ export const SidebarNavBase = ({

React.useEffect(() => {
if (navAnimation === "idle") {
toggleButtonRef.current?.focus();
(toggleButtonRef.current as HTMLButtonElement).focus();
}
}, [navAnimation]);

Expand Down
12 changes: 12 additions & 0 deletions src/components/__snapshots__/Checkbox.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ exports[`Checkbox allows setting props on label 1`] = `
</label>
`;

exports[`Checkbox handles disabled state 1`] = `
<label
className="sc-bczRLJ hizTBt"
>
<input
className="sc-gsnTZi cZFRiM"
type="checkbox"
/>
Click Me
</label>
`;

exports[`Checkbox handles options 1`] = `
<label
className="sc-bczRLJ brUlbM"
Expand Down

0 comments on commit b465b2b

Please sign in to comment.