Skip to content

Commit

Permalink
add extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 6, 2023
1 parent 3a40ffa commit e4bc88d
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { act, render, screen } from "@testing-library/react";
import {
act,
createEvent,
fireEvent,
render,
screen
} from "@testing-library/react";
import {
IFileIndexItem,
newIFileIndexItemArray
Expand Down Expand Up @@ -64,6 +70,58 @@ describe("archive-sidebar-selection-list", () => {
component.unmount();
});

it("toggleSelection keyboard keyDown it hits", () => {
const component = render(
<ArchiveSidebarSelectionList fileIndexItems={items} />
);

const spy = jest.spyOn(URLPath.prototype, "toggleSelection");

const selectionList = screen.queryByTestId(
"sidebar-selection-list"
) as HTMLElement;
const element = selectionList.children[0].querySelector(
".close"
) as HTMLElement;

act(() => {
const inputEvent = createEvent.keyDown(element, { key: "Enter" });
fireEvent(element, inputEvent);
});

expect(spy).toBeCalledTimes(1);

spy.mockClear();

component.unmount();
});

it("toggleSelection keyboard keyDown it ignores", () => {
const component = render(
<ArchiveSidebarSelectionList fileIndexItems={items} />
);

const spy = jest.spyOn(URLPath.prototype, "toggleSelection");

const selectionList = screen.queryByTestId(
"sidebar-selection-list"
) as HTMLElement;
const element = selectionList.children[0].querySelector(
".close"
) as HTMLElement;

act(() => {
const inputEvent = createEvent.keyDown(element, { key: "Tab" });
fireEvent(element, inputEvent);
});

expect(spy).toBeCalledTimes(0);

spy.mockClear();

component.unmount();
});

it("allSelection", () => {
const component = render(
<ArchiveSidebarSelectionList fileIndexItems={items} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { act, fireEvent, render, screen } from "@testing-library/react";
import {
act,
createEvent,
fireEvent,
render,
screen
} from "@testing-library/react";
import React from "react";
import { Root, createRoot } from "react-dom/client";
import { IDetailView } from "../../../interfaces/IDetailView";
Expand Down Expand Up @@ -36,6 +42,40 @@ describe("DetailViewMp4", () => {
component.unmount();
});

it("keyDown Tab ignore", () => {
const component = render(<DetailViewMp4></DetailViewMp4>);

const playSpy = jest
.spyOn(HTMLMediaElement.prototype, "play")
.mockReset()
.mockImplementationOnce(() => Promise.resolve());

const figure = screen.queryByTestId("video") as HTMLElement;
const inputEvent = createEvent.keyDown(figure, { key: "Tab" });
fireEvent(figure, inputEvent);

expect(playSpy).toBeCalledTimes(0);

component.unmount();
});

it("keyDown Enter video resolve", () => {
const component = render(<DetailViewMp4></DetailViewMp4>);

const playSpy = jest
.spyOn(HTMLMediaElement.prototype, "play")
.mockReset()
.mockImplementationOnce(() => Promise.resolve());

const figure = screen.queryByTestId("video") as HTMLElement;
const inputEvent = createEvent.keyDown(figure, { key: "Enter" });
fireEvent(figure, inputEvent);

expect(playSpy).toBeCalledTimes(1);

component.unmount();
});

it("click to play video rejected", async () => {
const component = render(<DetailViewMp4></DetailViewMp4>);

Expand All @@ -56,6 +96,7 @@ describe("DetailViewMp4", () => {
await component.unmount();
});
});

it("click to play video and timeupdate", () => {
const component = render(<DetailViewMp4></DetailViewMp4>);

Expand All @@ -79,6 +120,54 @@ describe("DetailViewMp4", () => {
component.unmount();
});

it("keyDown Enter to play video and timeupdate", () => {
const component = render(<DetailViewMp4></DetailViewMp4>);

const playSpy = jest
.spyOn(HTMLMediaElement.prototype, "play")
.mockReset()
.mockImplementationOnce(() => {
return Promise.resolve();
});

expect(screen.queryByTestId("video-time")?.textContent).toBe("");

const figure = screen.queryByTestId("video") as HTMLElement;
const inputEvent = createEvent.keyDown(figure, { key: "Enter" });
fireEvent(figure, inputEvent);

expect(screen.queryByTestId("video-time")?.textContent).toBe(
"0:00 / 0:00"
);

expect(playSpy).toBeCalled();

component.unmount();
});

it("keyDown Tab ignored", () => {
const component = render(<DetailViewMp4></DetailViewMp4>);

const playSpy = jest
.spyOn(HTMLMediaElement.prototype, "play")
.mockReset()
.mockImplementationOnce(() => {
return Promise.resolve();
});

expect(screen.queryByTestId("video-time")?.textContent).toBe("");

const figure = screen.queryByTestId("video") as HTMLElement;
const inputEvent = createEvent.keyDown(figure, { key: "Tab" });
fireEvent(figure, inputEvent);

expect(screen.queryByTestId("video-time")?.textContent).toBe("");

expect(playSpy).toBeCalledTimes(0);

component.unmount();
});

it("progress DOM", (done) => {
const component = document.createElement("div");
document.body.appendChild(component); // Append the component to the body
Expand Down

0 comments on commit e4bc88d

Please sign in to comment.