Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Oct 16, 2024
1 parent c7e39cc commit 4ddc5df
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { act } from "react";
import { IDetailView } from "../../../../interfaces/IDetailView";
import { Orientation } from "../../../../interfaces/IFileIndexItem";
import * as RequestNewFileHash from "./request-new-filehash";
import { TriggerFileHashRequest } from "./trigger-file-hash-request";

describe("TriggerFileHashRequest", () => {
const state: IDetailView = {
subPath: "/test/image.jpg",
fileIndexItem: {
fileHash: "123",
filePath: "/test/image.jpg",
orientation: Orientation.Horizontal
}
} as IDetailView;

it("returns immediately when the file hash changes on the first attempt", () => {
jest.useFakeTimers();

const requestSpy = jest
.spyOn(RequestNewFileHash, "RequestNewFileHash")
.mockResolvedValueOnce(true);

const setIsLoading = jest.fn();
TriggerFileHashRequest(state, setIsLoading, jest.fn(), 1, 1);

act(() => {
jest.advanceTimersByTime(100);
});

console.log("after TriggerFileHashRequest");

jest.advanceTimersByTime(1);
jest.runAllTimers();
expect(requestSpy).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 4ddc5df

Please sign in to comment.