Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 6, 2023
1 parent ceaad2c commit e3a63a2
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { fireEvent, render } from "@testing-library/react";
import { MenuOptionSelectionAll } from "./menu-option-selection-all";

describe("MenuOptionSelectionAll", () => {
it("renders", () => {
render(
<MenuOptionSelectionAll
select={[]}
state={{} as any}
allSelection={() => {}}
/>
);
});

it("renders 2", () => {
render(
<MenuOptionSelectionAll
select={[]}
state={
{
fileIndexItems: []
} as any
}
allSelection={() => {}}
/>
);
});

it("keyDown tab skipped", () => {
const allSelection = jest.fn();
const component = render(
<MenuOptionSelectionAll
select={[]}
state={
{
fileIndexItems: []
} as any
}
allSelection={allSelection}
/>
);
console.log(component.container.innerHTML);

const allItem = component.queryByTestId("select-all") as HTMLElement;
expect(allItem).toBeTruthy();

fireEvent.keyDown(allItem, {
key: "Tab"
});

expect(allSelection).toBeCalledTimes(0);
});

it("keyDown enter continue", () => {
const allSelection = jest.fn();
const component = render(
<MenuOptionSelectionAll
select={[]}
state={
{
fileIndexItems: []
} as any
}
allSelection={allSelection}
/>
);

fireEvent.keyDown(
component.queryByTestId("undo-selection") as HTMLElement,
{ key: "Enter" }
);

expect(allSelection).toBeCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Language } from "../../../shared/language";

export interface IMenuOptionUndoSelectionProps {
select: string[];
state: IArchiveProps;
state?: IArchiveProps;
allSelection: () => void;
}

Expand All @@ -18,7 +18,7 @@ export const MenuOptionSelectionAll: React.FunctionComponent<

return (
<>
{select.length !== state.fileIndexItems.length ? (
{select.length !== state?.fileIndexItems?.length ? (
<li
className="menu-option"
data-test="select-all"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { fireEvent, render } from "@testing-library/react";
import { MenuOptionSelectionUndo } from "./menu-option-selection-undo";

describe("MenuOptionSelectionUndo", () => {
it("renders", () => {
render(
<MenuOptionSelectionUndo
select={[]}
state={{} as any}
undoSelection={() => {}}
/>
);
});

it("renders 2", () => {
render(
<MenuOptionSelectionUndo
select={[]}
state={
{
fileIndexItems: []
} as any
}
undoSelection={() => {}}
/>
);
});

it("keyDown tab skipped", () => {
const undoSelection = jest.fn();
const component = render(
<MenuOptionSelectionUndo
select={[]}
state={
{
fileIndexItems: []
} as any
}
undoSelection={undoSelection}
/>
);

fireEvent.keyDown(
component.queryByTestId("undo-selection") as HTMLElement,
{ key: "Tab" }
);

expect(undoSelection).toBeCalledTimes(0);
});

it("keyDown enter continue", () => {
const undoSelection = jest.fn();
const component = render(
<MenuOptionSelectionUndo
select={[]}
state={
{
fileIndexItems: []
} as any
}
undoSelection={undoSelection}
/>
);

fireEvent.keyDown(
component.queryByTestId("undo-selection") as HTMLElement,
{ key: "Enter" }
);

expect(undoSelection).toBeCalledTimes(1);
});
});

0 comments on commit e3a63a2

Please sign in to comment.