Skip to content

Commit

Permalink
#1866 remove any | eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Dec 16, 2024
1 parent ca2925e commit eb15661
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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][] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -309,7 +309,7 @@ describe("DetailView", () => {
.mockImplementationOnce(() => locationObject);

jest.spyOn(UpdateRelativeObject.prototype, "Update").mockImplementationOnce(() => {
return Promise.resolve() as any;
return Promise.resolve<IRelativeObjects>({} as IRelativeObjects);
});

const detailview = render(<TestComponent />);
Expand Down Expand Up @@ -358,7 +358,7 @@ describe("DetailView", () => {
.spyOn(UpdateRelativeObject.prototype, "Update")
.mockReset()
.mockImplementationOnce(() => {
return Promise.resolve() as any;
return Promise.resolve<IRelativeObjects>({} as IRelativeObjects);
});

const component = render(<TestComponent />);
Expand Down Expand Up @@ -461,7 +461,7 @@ describe("DetailView", () => {
.mockImplementationOnce(() => locationObject)
.mockImplementationOnce(() => locationObject);
jest.spyOn(UpdateRelativeObject.prototype, "Update").mockImplementationOnce(() => {
return Promise.resolve() as any;
return Promise.resolve<IRelativeObjects>({} as IRelativeObjects);
});

const component = render(<TestComponent />);
Expand Down Expand Up @@ -503,7 +503,7 @@ describe("DetailView", () => {

const updateRelativeObjectSpy = jest
.spyOn(UpdateRelativeObject.prototype, "Update")
.mockImplementationOnce(() => Promise.resolve() as any);
.mockImplementationOnce(() => Promise.resolve<IRelativeObjects>({} as IRelativeObjects));

let handlerOnSwipeLeft: () => void;
jest
Expand Down Expand Up @@ -563,7 +563,7 @@ describe("DetailView", () => {

const updateRelativeObjectSpy = jest
.spyOn(UpdateRelativeObject.prototype, "Update")
.mockImplementationOnce(() => Promise.resolve() as any);
.mockImplementationOnce(() => Promise.resolve<IRelativeObjects>({} as IRelativeObjects));

let handlerOnSwipeLeft: () => void;
jest
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions starsky/starsky/clientapp/src/containers/login.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("Login", () => {
.mockImplementationOnce(() => connectionDefaultExample)
.mockImplementationOnce(() => connectionDefaultExample);

const mockPost: Promise<any> = Promise.resolve({
const mockPost: Promise<IConnectionDefault> = Promise.resolve({
statusCode: 200,
data: "ok"
});
Expand Down Expand Up @@ -255,7 +255,7 @@ describe("Login", () => {
.mockImplementationOnce(() => connectionDefaultExample)
.mockImplementationOnce(() => connectionDefaultExample);

const mockPost: Promise<any> = Promise.resolve({
const mockPost: Promise<IConnectionDefault> = Promise.resolve({
statusCode: 401,
data: "fail"
});
Expand Down Expand Up @@ -307,7 +307,7 @@ describe("Login", () => {
.mockImplementationOnce(() => connectionDefaultExample)
.mockImplementationOnce(() => connectionDefaultExample);

const mockPost: Promise<any> = Promise.resolve({
const mockPost: Promise<IConnectionDefault> = Promise.resolve({
statusCode: 423,
data: "fail"
});
Expand Down
4 changes: 2 additions & 2 deletions starsky/starsky/clientapp/src/containers/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export const Login: React.FC<ILoginProps> = () => {

history.navigate(returnUrl, { replace: true });
}
} catch (err: any) {
} catch (err: unknown) {
setLoading(false);
setError(err.message);
setError((err as { message: string }).message);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -186,7 +186,10 @@ describe("ArchiveContextWrapper", () => {
});
};

const result = mountReactHook(ArchiveEventListenerUseEffect, [dispatch]);
const result = mountReactHook(
ArchiveEventListenerUseEffect as (...args: unknown[]) => unknown,
[dispatch]
);
const detail = {
data: [
{
Expand Down Expand Up @@ -217,7 +220,10 @@ describe("ArchiveContextWrapper", () => {
});
};

const result = mountReactHook(ArchiveEventListenerUseEffect, [dispatch]);
const result = mountReactHook(
ArchiveEventListenerUseEffect as (...args: unknown[]) => unknown,
[dispatch]
);
const detail = {
data: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(),
Expand All @@ -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(<DetailViewWrapper {...args} />);
Expand Down Expand Up @@ -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: [
Expand All @@ -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();
});
});
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky/clientapp/src/contexts/sorter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions starsky/starsky/clientapp/src/hooks/___tests___/test-hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand Down
7 changes: 5 additions & 2 deletions starsky/starsky/clientapp/src/hooks/use-fetch.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});

Expand Down
8 changes: 5 additions & 3 deletions starsky/starsky/clientapp/src/hooks/use-filelist.spec.tsx
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit eb15661

Please sign in to comment.