From eb156610809b0859d1a15413a53459b416ca38b0 Mon Sep 17 00:00:00 2001 From: Dion Date: Mon, 16 Dec 2024 21:10:37 +0100 Subject: [PATCH] #1866 remove any | eslint --- .../detail-view-media/detail-view-gpx.tsx | 3 +- .../containers/detailview/detailview.spec.tsx | 12 ++--- .../detailview/helpers/prev-next.spec.tsx | 15 +++--- .../clientapp/src/containers/login.spec.tsx | 6 +-- .../clientapp/src/containers/login.tsx | 4 +- .../src/containers/media-content.spec.tsx | 2 +- .../archive-wrapper.spec.tsx | 12 +++-- .../detailview-wrapper.spec.tsx | 21 ++++---- .../clientapp/src/contexts/sorter.spec.ts | 2 +- .../src/hooks/___tests___/test-hook.tsx | 4 +- .../clientapp/src/hooks/use-fetch.spec.tsx | 7 ++- .../clientapp/src/hooks/use-filelist.spec.tsx | 8 +-- .../hooks/use-gestures/use-gestures.spec.tsx | 49 ++++++++++++++----- .../hooks/use-keyboard/use-hotkeys.spec.tsx | 33 +++++++------ .../src/hooks/use-searchlist.spec.tsx | 10 ++-- .../clientapp/src/shared/filelist-cache.ts | 5 +- 16 files changed, 118 insertions(+), 75 deletions(-) diff --git a/starsky/starsky/clientapp/src/components/organisms/detail-view-media/detail-view-gpx.tsx b/starsky/starsky/clientapp/src/components/organisms/detail-view-media/detail-view-gpx.tsx index db95202ad0..3eb1e258c6 100644 --- a/starsky/starsky/clientapp/src/components/organisms/detail-view-media/detail-view-gpx.tsx +++ b/starsky/starsky/clientapp/src/components/organisms/detail-view-media/detail-view-gpx.tsx @@ -32,8 +32,7 @@ const DetailViewGpx: React.FC = () => { mapReference.current.innerHTML = ""; const container = L.DomUtil.get(mapReference.current); if (container != null) { - const containerCasted = container as HTMLElement; - (containerCasted as unknown as { _leaflet_id: null })._leaflet_id = null; + (container as HTMLElement as unknown as { _leaflet_id: null })._leaflet_id = null; } const tracks: [number, number][] = []; diff --git a/starsky/starsky/clientapp/src/containers/detailview/detailview.spec.tsx b/starsky/starsky/clientapp/src/containers/detailview/detailview.spec.tsx index e7e0b3b5af..0a25410f3f 100644 --- a/starsky/starsky/clientapp/src/containers/detailview/detailview.spec.tsx +++ b/starsky/starsky/clientapp/src/containers/detailview/detailview.spec.tsx @@ -87,7 +87,7 @@ describe("DetailView", () => { } as IDetailView; describe("With context and test if image is loaded", () => { - let contextProvider: any; + let contextProvider: ContextDetailview.IDetailViewContext; let TestComponent: () => JSX.Element; let Component: RenderResult; @@ -309,7 +309,7 @@ describe("DetailView", () => { .mockImplementationOnce(() => locationObject); jest.spyOn(UpdateRelativeObject.prototype, "Update").mockImplementationOnce(() => { - return Promise.resolve() as any; + return Promise.resolve({} as IRelativeObjects); }); const detailview = render(); @@ -358,7 +358,7 @@ describe("DetailView", () => { .spyOn(UpdateRelativeObject.prototype, "Update") .mockReset() .mockImplementationOnce(() => { - return Promise.resolve() as any; + return Promise.resolve({} as IRelativeObjects); }); const component = render(); @@ -461,7 +461,7 @@ describe("DetailView", () => { .mockImplementationOnce(() => locationObject) .mockImplementationOnce(() => locationObject); jest.spyOn(UpdateRelativeObject.prototype, "Update").mockImplementationOnce(() => { - return Promise.resolve() as any; + return Promise.resolve({} as IRelativeObjects); }); const component = render(); @@ -503,7 +503,7 @@ describe("DetailView", () => { const updateRelativeObjectSpy = jest .spyOn(UpdateRelativeObject.prototype, "Update") - .mockImplementationOnce(() => Promise.resolve() as any); + .mockImplementationOnce(() => Promise.resolve({} as IRelativeObjects)); let handlerOnSwipeLeft: () => void; jest @@ -563,7 +563,7 @@ describe("DetailView", () => { const updateRelativeObjectSpy = jest .spyOn(UpdateRelativeObject.prototype, "Update") - .mockImplementationOnce(() => Promise.resolve() as any); + .mockImplementationOnce(() => Promise.resolve({} as IRelativeObjects)); let handlerOnSwipeLeft: () => void; jest diff --git a/starsky/starsky/clientapp/src/containers/detailview/helpers/prev-next.spec.tsx b/starsky/starsky/clientapp/src/containers/detailview/helpers/prev-next.spec.tsx index 49c8c08a51..b8f8e28f93 100644 --- a/starsky/starsky/clientapp/src/containers/detailview/helpers/prev-next.spec.tsx +++ b/starsky/starsky/clientapp/src/containers/detailview/helpers/prev-next.spec.tsx @@ -1,4 +1,5 @@ import { IUseLocation } from "../../../hooks/use-location/interfaces/IUseLocation"; +import { NavigateFunction } from "../../../hooks/use-location/type/NavigateFunction"; import { IDetailView, IRelativeObjects } from "../../../interfaces/IDetailView"; import { UpdateRelativeObject } from "../../../shared/update-relative-object"; import { PrevNext } from "./prev-next"; @@ -34,7 +35,7 @@ describe("statusRemoved", () => { it("not called 2", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); @@ -67,7 +68,7 @@ describe("statusRemoved", () => { it("called 3", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); @@ -104,7 +105,7 @@ describe("statusRemoved", () => { it("called 4", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); @@ -143,7 +144,7 @@ describe("statusRemoved", () => { it("called 5", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); @@ -179,7 +180,7 @@ describe("statusRemoved", () => { it("called 6", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); @@ -220,7 +221,7 @@ describe("statusRemoved", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); @@ -250,7 +251,7 @@ describe("statusRemoved", () => { const history = { location: {} } as IUseLocation; const navigate = jest.fn(); - history.navigate = () => Promise.resolve(navigate) as any; + history.navigate = () => Promise.resolve(navigate) as unknown as NavigateFunction; const setIsLoading = jest.fn(); diff --git a/starsky/starsky/clientapp/src/containers/login.spec.tsx b/starsky/starsky/clientapp/src/containers/login.spec.tsx index 5c2920ce3f..0a8982b226 100644 --- a/starsky/starsky/clientapp/src/containers/login.spec.tsx +++ b/starsky/starsky/clientapp/src/containers/login.spec.tsx @@ -201,7 +201,7 @@ describe("Login", () => { .mockImplementationOnce(() => connectionDefaultExample) .mockImplementationOnce(() => connectionDefaultExample); - const mockPost: Promise = Promise.resolve({ + const mockPost: Promise = Promise.resolve({ statusCode: 200, data: "ok" }); @@ -255,7 +255,7 @@ describe("Login", () => { .mockImplementationOnce(() => connectionDefaultExample) .mockImplementationOnce(() => connectionDefaultExample); - const mockPost: Promise = Promise.resolve({ + const mockPost: Promise = Promise.resolve({ statusCode: 401, data: "fail" }); @@ -307,7 +307,7 @@ describe("Login", () => { .mockImplementationOnce(() => connectionDefaultExample) .mockImplementationOnce(() => connectionDefaultExample); - const mockPost: Promise = Promise.resolve({ + const mockPost: Promise = Promise.resolve({ statusCode: 423, data: "fail" }); diff --git a/starsky/starsky/clientapp/src/containers/login.tsx b/starsky/starsky/clientapp/src/containers/login.tsx index e36e5f7f93..0193d72a8f 100755 --- a/starsky/starsky/clientapp/src/containers/login.tsx +++ b/starsky/starsky/clientapp/src/containers/login.tsx @@ -93,9 +93,9 @@ export const Login: React.FC = () => { history.navigate(returnUrl, { replace: true }); } - } catch (err: any) { + } catch (err: unknown) { setLoading(false); - setError(err.message); + setError((err as { message: string }).message); } }; diff --git a/starsky/starsky/clientapp/src/containers/media-content.spec.tsx b/starsky/starsky/clientapp/src/containers/media-content.spec.tsx index 6d26a44044..7ba462134e 100644 --- a/starsky/starsky/clientapp/src/containers/media-content.spec.tsx +++ b/starsky/starsky/clientapp/src/containers/media-content.spec.tsx @@ -36,7 +36,7 @@ describe("MediaContent", () => { return { archive: { ...newIArchive() }, pageType: PageType.Loading - } as any; + } as useFileList.IFileList; }); // import * as useSockets from "../hooks/realtime/use-sockets"; diff --git a/starsky/starsky/clientapp/src/contexts-wrappers/archive-wrapper.spec.tsx b/starsky/starsky/clientapp/src/contexts-wrappers/archive-wrapper.spec.tsx index 84992b363c..2799b0c542 100644 --- a/starsky/starsky/clientapp/src/contexts-wrappers/archive-wrapper.spec.tsx +++ b/starsky/starsky/clientapp/src/contexts-wrappers/archive-wrapper.spec.tsx @@ -167,7 +167,7 @@ describe("ArchiveContextWrapper", () => { }); it("Check if event is received", () => { - const dispatch = (e: any) => { + const dispatch = (e: { add: IFileIndexItem[]; type: string }) => { // should ignore the first one expect(e).toStrictEqual({ add: [ @@ -186,7 +186,10 @@ describe("ArchiveContextWrapper", () => { }); }; - const result = mountReactHook(ArchiveEventListenerUseEffect, [dispatch]); + const result = mountReactHook( + ArchiveEventListenerUseEffect as (...args: unknown[]) => unknown, + [dispatch] + ); const detail = { data: [ { @@ -217,7 +220,10 @@ describe("ArchiveContextWrapper", () => { }); }; - const result = mountReactHook(ArchiveEventListenerUseEffect, [dispatch]); + const result = mountReactHook( + ArchiveEventListenerUseEffect as (...args: unknown[]) => unknown, + [dispatch] + ); const detail = { data: [ { diff --git a/starsky/starsky/clientapp/src/contexts-wrappers/detailview-wrapper.spec.tsx b/starsky/starsky/clientapp/src/contexts-wrappers/detailview-wrapper.spec.tsx index 2728c6b2cd..62a48a7871 100644 --- a/starsky/starsky/clientapp/src/contexts-wrappers/detailview-wrapper.spec.tsx +++ b/starsky/starsky/clientapp/src/contexts-wrappers/detailview-wrapper.spec.tsx @@ -1,4 +1,4 @@ -import { render } from "@testing-library/react"; +import { render, RenderResult } from "@testing-library/react"; import { MemoryRouter } from "react-router-dom"; import * as DetailView from "../containers/detailview/detailview"; import * as useDetailViewContext from "../contexts/detailview-context"; @@ -33,13 +33,13 @@ describe("DetailViewWrapper", () => { const contextValues = { state: { fileIndexItem: newIFileIndexItem() }, dispatch: jest.fn() - } as any; + } as unknown as useDetailViewContext.IDetailViewContext; jest .spyOn(useDetailViewContext, "useDetailViewContext") - .mockImplementationOnce(() => contextValues as any) - .mockImplementationOnce(() => contextValues as any) - .mockImplementationOnce(() => contextValues as any); + .mockImplementationOnce(() => contextValues) + .mockImplementationOnce(() => contextValues) + .mockImplementationOnce(() => contextValues); const args = { ...newDetailView(), @@ -64,12 +64,12 @@ describe("DetailViewWrapper", () => { const contextValues = { state: null, dispatch: jest.fn() - } as any; + } as unknown as useDetailViewContext.IDetailViewContext; jest .spyOn(useDetailViewContext, "useDetailViewContext") .mockReset() - .mockImplementationOnce(() => contextValues as any); + .mockImplementationOnce(() => contextValues); const args = { ...newDetailView() } as IDetailView; const component = render(); @@ -103,7 +103,10 @@ describe("DetailViewWrapper", () => { it("Check if event is received", () => { const dispatch = jest.fn(); document.body.innerHTML = ""; - const result = mountReactHook(DetailViewEventListenerUseEffect, [dispatch]); + const result = mountReactHook( + DetailViewEventListenerUseEffect as (...args: unknown[]) => unknown, + [dispatch] + ); const detail = { data: [ @@ -128,7 +131,7 @@ describe("DetailViewWrapper", () => { expect(dispatch).toHaveBeenCalled(); expect(dispatch).toHaveBeenCalledWith(detail.data[1]); - const element = result.componentMount as any; + const element = result.componentMount as unknown as RenderResult; element.unmount(); }); }); diff --git a/starsky/starsky/clientapp/src/contexts/sorter.spec.ts b/starsky/starsky/clientapp/src/contexts/sorter.spec.ts index 46d6194ee4..33d0de0de2 100644 --- a/starsky/starsky/clientapp/src/contexts/sorter.spec.ts +++ b/starsky/starsky/clientapp/src/contexts/sorter.spec.ts @@ -13,7 +13,7 @@ describe("sorter", () => { } as IFileIndexItem ] as IFileIndexItem[]; - const resultList = sorter(list, null as any); + const resultList = sorter(list, null as unknown as SortType); expect(resultList.length).toBe(0); }); diff --git a/starsky/starsky/clientapp/src/hooks/___tests___/test-hook.tsx b/starsky/starsky/clientapp/src/hooks/___tests___/test-hook.tsx index b57378354e..fde6960b4b 100644 --- a/starsky/starsky/clientapp/src/hooks/___tests___/test-hook.tsx +++ b/starsky/starsky/clientapp/src/hooks/___tests___/test-hook.tsx @@ -2,10 +2,10 @@ import { render } from "@testing-library/react"; import { act } from "react"; type ModalPropTypes = { - children: (hookValues: any) => any; + children: (hookValues: unknown) => React.ReactNode; }; -export const mountReactHook = (hook: any, args: any[]) => { +export const mountReactHook = (hook: (...args: unknown[]) => unknown, args: unknown[]) => { const Component = ({ children }: ModalPropTypes) => { return children(hook(...args)); }; diff --git a/starsky/starsky/clientapp/src/hooks/use-fetch.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-fetch.spec.tsx index 276f43f439..ab42a4e6d1 100644 --- a/starsky/starsky/clientapp/src/hooks/use-fetch.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-fetch.spec.tsx @@ -2,8 +2,8 @@ import { newIArchive } from "../interfaces/IArchive"; import { IConnectionDefault } from "../interfaces/IConnectionDefault"; import { PageType } from "../interfaces/IDetailView"; import { newIFileIndexItemArray } from "../interfaces/IFileIndexItem"; -import useFetch, { fetchContent } from "./use-fetch"; import { mountReactHook } from "./___tests___/test-hook"; +import useFetch, { fetchContent } from "./use-fetch"; describe("UseFetch", () => { let setupComponent; @@ -31,7 +31,10 @@ describe("UseFetch", () => { } beforeEach(() => { - setupComponent = mountReactHook(useFetch, ["/default/", "get"]); // Mount a Component with our hook + setupComponent = mountReactHook(useFetch as (...args: unknown[]) => unknown, [ + "/default/", + "get" + ]); // Mount a Component with our hook hook = setupComponent.componentHook as IConnectionDefault; }); diff --git a/starsky/starsky/clientapp/src/hooks/use-filelist.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-filelist.spec.tsx index a092665934..655ce7955f 100644 --- a/starsky/starsky/clientapp/src/hooks/use-filelist.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-filelist.spec.tsx @@ -1,11 +1,10 @@ -import { act } from "react"; +import React, { act } from "react"; import { IArchive, newIArchive } from "../interfaces/IArchive"; import { IDetailView, IRelativeObjects, PageType } from "../interfaces/IDetailView"; import { newIFileIndexItem, newIFileIndexItemArray } from "../interfaces/IFileIndexItem"; import { FileListCache } from "../shared/filelist-cache"; import { mountReactHook } from "./___tests___/test-hook"; import useFileList, { IFileList, fetchContentUseFileList } from "./use-filelist"; -import React from "react"; describe("UseFileList", () => { describe("Archive", () => { @@ -32,7 +31,10 @@ describe("UseFileList", () => { } function mounter(path: string = "/default/") { - const setupComponent = mountReactHook(useFileList, [path, "1"]); + const setupComponent = mountReactHook(useFileList as (...args: unknown[]) => unknown, [ + path, + "1" + ]); // Mount a Component with our hook const hook = setupComponent.componentHook as IFileList; return { diff --git a/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx index 64eb5ab478..1503766f63 100644 --- a/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-gestures/use-gestures.spec.tsx @@ -28,7 +28,7 @@ function Rotate() { ); } -describe("useGestures", () => { +describe("useGestures as (...args: unknown[]) => unknown", () => { describe("Pointer", () => { it("check output of pointer", () => { const p = new Pointer({ clientX: 10, clientY: 11 }); @@ -155,7 +155,7 @@ describe("useGestures", () => { }); }); - describe("useGestures", () => { + describe("useGestures as (...args: unknown[]) => unknown", () => { const exampleSingleTouches = { touches: [ { @@ -202,7 +202,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchstart", exampleSingleTouches); @@ -224,7 +226,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchstart", exampleDoubleTouches); @@ -246,7 +250,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleSingleTouches); @@ -281,7 +287,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleSingleTouches); @@ -314,7 +322,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleSingleTouches); @@ -348,7 +358,9 @@ describe("useGestures", () => { .mockImplementationOnce(() => debounceAnonymousFnSpy); const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleSingleTouches); @@ -382,7 +394,9 @@ describe("useGestures", () => { .mockImplementationOnce(() => debounceAnonymousFnSpy); const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleSingleTouches); @@ -417,7 +431,9 @@ describe("useGestures", () => { .mockImplementationOnce(() => debounceAnonymousFnSpy); const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleSingleTouches); @@ -442,7 +458,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); const event = new TouchEvent("touchmove", exampleDoubleTouches); @@ -496,7 +514,9 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook(useGestures as (...args: unknown[]) => unknown, [ + { current: demoElement } + ]); act(() => { demoElement.dispatchEvent(touchEndEvent); @@ -526,7 +546,10 @@ describe("useGestures", () => { const demoElement = document.createElement("div"); - const hook = mountReactHook(useGestures, [{ current: demoElement }]); + const hook = mountReactHook( + useGestures as (...args: unknown[]) => unknown as (...args: unknown[]) => unknown, + [{ current: demoElement }] + ); act(() => { demoElement.dispatchEvent(touchEndEvent); diff --git a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.spec.tsx index 4d0aad437a..db8fac6cd4 100644 --- a/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-keyboard/use-hotkeys.spec.tsx @@ -6,7 +6,7 @@ describe("useHotKeys", () => { describe("should ignore", () => { it("missing input as empty object", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [{}, callback]); + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [{}, callback]); const event = new KeyboardEvent("keydown", { bubbles: true, @@ -22,7 +22,10 @@ describe("useHotKeys", () => { it("missing input as undefined", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [undefined, callback]); + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ + undefined, + callback + ]); const event = new KeyboardEvent("keydown", { bubbles: true, @@ -41,7 +44,7 @@ describe("useHotKeys", () => { jest.spyOn(Keyboard.prototype, "isInForm").mockImplementationOnce(() => true); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", altKey: true @@ -65,7 +68,7 @@ describe("useHotKeys", () => { describe("pressing key with q", () => { it("should return when pressing alt+q and expect alt+q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", altKey: true @@ -87,7 +90,7 @@ describe("useHotKeys", () => { it("should return when pressing control q and expect key:q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKey: true @@ -109,7 +112,7 @@ describe("useHotKeys", () => { it("should return when pressing command/meta q and expect cmd/meta+q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", metaKey: true @@ -131,7 +134,7 @@ describe("useHotKeys", () => { it("should return when pressing shift+q and expect shift+q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", shiftKey: true @@ -153,7 +156,7 @@ describe("useHotKeys", () => { it("should not return when pressing q and expect shift+q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", shiftKey: true @@ -174,7 +177,7 @@ describe("useHotKeys", () => { it("should not return when pressing shift+q and expect q only", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", shiftKey: true @@ -195,7 +198,7 @@ describe("useHotKeys", () => { it("ctrlKeyOrMetaKey - should return when pressing command/meta with combination option enabled q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKeyOrMetaKey: true @@ -217,7 +220,7 @@ describe("useHotKeys", () => { it("ctrlKeyOrMetaKey - should return when pressing ctrlKey with combination option enabled q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKeyOrMetaKey: true @@ -239,7 +242,7 @@ describe("useHotKeys", () => { it("ctrlKeyOrMetaKey - should return when pressing cmdOrCtlr+shift+q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKeyOrMetaKey: true, @@ -263,7 +266,7 @@ describe("useHotKeys", () => { it("ctrlKeyOrMetaKey - should not return when pressing shiftKey with combination option enabled q", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKeyOrMetaKey: true @@ -285,7 +288,7 @@ describe("useHotKeys", () => { it("ctrlKeyOrMetaKey - should not return when pressing q only with combination option enabled", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKeyOrMetaKey: true @@ -308,7 +311,7 @@ describe("useHotKeys", () => { it("ctrlKeyOrMetaKey - should not return when pressing t only with combination option enabled", () => { const callback = jest.fn(); - const test = mountReactHook(useHotKeys, [ + const test = mountReactHook(useHotKeys as (...args: unknown[]) => unknown, [ { key: "q", ctrlKeyOrMetaKey: true diff --git a/starsky/starsky/clientapp/src/hooks/use-searchlist.spec.tsx b/starsky/starsky/clientapp/src/hooks/use-searchlist.spec.tsx index 4f0a836e05..5e9733e769 100644 --- a/starsky/starsky/clientapp/src/hooks/use-searchlist.spec.tsx +++ b/starsky/starsky/clientapp/src/hooks/use-searchlist.spec.tsx @@ -2,15 +2,15 @@ import { act } from "react"; import { newIArchive } from "../interfaces/IArchive"; import { PageType } from "../interfaces/IDetailView"; import { newIFileIndexItem, newIFileIndexItemArray } from "../interfaces/IFileIndexItem"; -import useSearchList, { fetchContentUseSearchList, ISearchList } from "./use-searchlist"; import { mountReactHook } from "./___tests___/test-hook"; +import useSearchList, { fetchContentUseSearchList, ISearchList } from "./use-searchlist"; describe("UseSearchList", () => { describe("Search", () => { let setupComponent; let hook: ISearchList; - let fetchSpy: jest.SpyInstance; + let fetchSpy: jest.SpyInstance>; function setFetchSpy(statusCode: number, pageType: PageType) { const mockSuccessResponse = { @@ -33,7 +33,11 @@ describe("UseSearchList", () => { } beforeEach(() => { - setupComponent = mountReactHook(useSearchList, ["test", "1", "true"]); // Mount a Component with our hook + setupComponent = mountReactHook(useSearchList as (...args: unknown[]) => unknown, [ + "test", + "1", + "true" + ]); // Mount a Component with our hook hook = setupComponent.componentHook as ISearchList; }); diff --git a/starsky/starsky/clientapp/src/shared/filelist-cache.ts b/starsky/starsky/clientapp/src/shared/filelist-cache.ts index a74bd433f1..cfb3cca669 100644 --- a/starsky/starsky/clientapp/src/shared/filelist-cache.ts +++ b/starsky/starsky/clientapp/src/shared/filelist-cache.ts @@ -188,13 +188,12 @@ export class FileListCache { */ public ParseJson(cacheString: string | null): IArchive | IDetailView | null { if (!cacheString) return null; - let cacheData = {} as IArchive | IDetailView | null; try { - cacheData = JSON.parse(cacheString) as IArchive | IDetailView; + const cacheData = JSON.parse(cacheString) as IArchive | IDetailView; + return cacheData.dateCache ? cacheData : null; } catch (error) { console.error(error); return null; } - return cacheData.dateCache ? cacheData : null; } }