Skip to content

Commit

Permalink
#1866 eslint fixxes
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Dec 16, 2024
1 parent f2e7c9c commit 75395bd
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { act, fireEvent, render, RenderResult, screen, waitFor } from "@testing-library/react";
import { fireEvent, render, RenderResult, screen, waitFor } from "@testing-library/react";
import { act } from "react";
import { DetailViewContext } from "../../../contexts/detailview-context";
import * as useKeyboardEvent from "../../../hooks/use-keyboard/use-keyboard-event";
import { IConnectionDefault, newIConnectionDefault } from "../../../interfaces/IConnectionDefault";
import { IRelativeObjects, PageType } from "../../../interfaces/IDetailView";
import { IDetailView, IRelativeObjects, PageType } from "../../../interfaces/IDetailView";
import { IExifStatus } from "../../../interfaces/IExifStatus";
import { IFileIndexItem } from "../../../interfaces/IFileIndexItem";
import { ClipboardHelper } from "../../../shared/clipboard-helper";
Expand All @@ -22,7 +23,7 @@ describe("DetailViewSidebar", () => {
<DetailViewSidebar
status={IExifStatus.Default}
filePath={"/t"}
state={{ fileIndexItem: { lastEdited: "" } } as any}
state={{ fileIndexItem: { lastEdited: "" } } as unknown as IDetailView}
dispatch={jest.fn()}
></DetailViewSidebar>
);
Expand All @@ -37,7 +38,7 @@ describe("DetailViewSidebar", () => {
<DetailViewSidebar
status={IExifStatus.Default}
filePath={"/t"}
state={undefined as any}
state={undefined as unknown as IDetailView}
dispatch={jest.fn()}
></DetailViewSidebar>
);
Expand All @@ -48,7 +49,10 @@ describe("DetailViewSidebar", () => {
});

describe("useContext-test", () => {
let contextProvider: any;
let contextProvider: {
dispatch: () => void;
state: IDetailView;
};
let TestComponent: () => JSX.Element;
let Component: RenderResult;

Expand Down Expand Up @@ -79,7 +83,7 @@ describe("DetailViewSidebar", () => {
status: IExifStatus.Default,
pageType: PageType.DetailView,
colorClassActiveList: []
} as any
} as unknown as IDetailView
};

TestComponent = () => (
Expand Down Expand Up @@ -339,7 +343,10 @@ describe("DetailViewSidebar", () => {
});

describe("Special status", () => {
let contextProvider: any;
let contextProvider: {
dispatch: () => void;
state: IDetailView;
};

beforeEach(() => {
contextProvider = {
Expand Down Expand Up @@ -367,7 +374,7 @@ describe("DetailViewSidebar", () => {
status: IExifStatus.Default,
pageType: PageType.DetailView,
colorClassActiveList: []
} as any
} as unknown as IDetailView
};
});

Expand All @@ -390,7 +397,7 @@ describe("DetailViewSidebar", () => {
></DetailViewSidebar>
</DetailViewContext.Provider>
);
const component = render(<DeletedTestComponent />);
const component = render(<DeletedTestComponent />) as RenderResult;

const statusDeleted = component.queryByTestId("detailview-exifstatus-status-deleted");
expect(statusDeleted).not.toBeNull();
Expand All @@ -399,8 +406,8 @@ describe("DetailViewSidebar", () => {

const tagsField = screen.queryByTestId("detailview-sidebar-tags") as HTMLInputElement;

const description = findDataNameCurrent(component as any, "description");
const title = findDataNameCurrent(component as any, "title");
const description = findDataNameCurrent(component, "description");
const title = findDataNameCurrent(component, "title");

expect(tagsField?.classList).toContain("form-control");
expect(tagsField?.classList).toContain("disabled");
Expand All @@ -423,15 +430,15 @@ describe("DetailViewSidebar", () => {
></DetailViewSidebar>
</DetailViewContext.Provider>
);
const component = render(<DeletedTestComponent />);
const component = render(<DeletedTestComponent />) as RenderResult;

const statusReadOnly = component.queryByTestId("detailview-exifstatus-status-read-only");
expect(statusReadOnly).not.toBeNull();

// Tags and other input fields are disabled
const tags = screen.queryByTestId("detailview-sidebar-tags") as HTMLInputElement;
const description = findDataNameCurrent(component as any, "description");
const title = findDataNameCurrent(component as any, "title");
const description = findDataNameCurrent(component, "description");
const title = findDataNameCurrent(component, "title");

await waitFor(() => expect(tags?.classList).toContain("form-control"));

Expand All @@ -455,7 +462,7 @@ describe("DetailViewSidebar", () => {
status: IExifStatus.Default,
pageType: PageType.DetailView,
colorClassActiveList: []
} as any;
} as unknown as IDetailView;

it("Press v to paste return false", () => {
let vPasteIsCalled = false;
Expand Down Expand Up @@ -600,7 +607,7 @@ describe("DetailViewSidebar", () => {
status: IExifStatus.Default,
pageType: PageType.DetailView,
colorClassActiveList: []
} as any
} as unknown as IDetailView
};

const isInFormSpy = jest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MemoryRouter } from "react-router-dom";
import { DetailViewContext } from "../../../contexts/detailview-context";
import { IRelativeObjects, PageType } from "../../../interfaces/IDetailView";
import { IDetailView, IRelativeObjects, PageType } from "../../../interfaces/IDetailView";
import { IExifStatus } from "../../../interfaces/IExifStatus";
import { IFileIndexItem } from "../../../interfaces/IFileIndexItem";
import DetailViewSidebar from "./detail-view-sidebar";
Expand Down Expand Up @@ -35,7 +35,7 @@ export const Default = () => {
status: IExifStatus.Default,
pageType: PageType.DetailView,
colorClassActiveList: []
} as any
} as unknown as IDetailView
};
return (
<MemoryRouter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IUseLocation } from "../../../hooks/use-location/interfaces/IUseLocation";
import { newIArchive } from "../../../interfaces/IArchive";
import { IConnectionDefault } from "../../../interfaces/IConnectionDefault";
import { IDetailView } from "../../../interfaces/IDetailView";
import { IFileIndexItem } from "../../../interfaces/IFileIndexItem";
import * as FetchPost from "../../../shared/fetch/fetch-post";
import { FileListCache } from "../../../shared/filelist-cache";
Expand All @@ -12,7 +14,13 @@ describe("Update Change", () => {
return Promise.resolve({} as IConnectionDefault);
});

new UpdateChange({} as any, jest.fn(), jest.fn(), {} as any, {} as any).Update([]);
new UpdateChange(
{} as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{} as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([]);

expect(fetchPostSpy).toHaveBeenCalledTimes(0);
});
Expand All @@ -22,9 +30,13 @@ describe("Update Change", () => {
return Promise.resolve({} as IConnectionDefault);
});

new UpdateChange({} as any, jest.fn(), jest.fn(), {} as any, {} as any).Update([
["", "test"]
]);
new UpdateChange(
{} as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{} as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["", "test"]]);

expect(fetchPostSpy).toHaveBeenCalledTimes(0);
});
Expand All @@ -34,9 +46,13 @@ describe("Update Change", () => {
return Promise.resolve({} as IConnectionDefault);
});

new UpdateChange({ tag: "" } as any, jest.fn(), jest.fn(), {} as any, {} as any).Update([
["tag", "test"]
]);
new UpdateChange(
{ tag: "" } as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{} as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["tag", "test"]]);

expect(fetchPostSpy).toHaveBeenCalledTimes(1);
});
Expand All @@ -49,9 +65,13 @@ describe("Update Change", () => {
return Promise.resolve({} as IConnectionDefault);
});

new UpdateChange({ tag: "test" } as any, jest.fn(), jest.fn(), {} as any, {} as any).Update([
["tag", "test"]
]);
new UpdateChange(
{ tag: "test" } as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{} as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["tag", "test"]]);

expect(fetchPostSpy).toHaveBeenCalledTimes(0);
});
Expand All @@ -71,11 +91,11 @@ describe("Update Change", () => {
});

const result = await new UpdateChange(
{ tag: "test1" } as any,
{ tag: "test1" } as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{} as any,
{} as any
{} as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["tag", "test"]]);

expect(result).toBe("wrong status code or missing data");
Expand All @@ -100,11 +120,11 @@ describe("Update Change", () => {
});

const result = await new UpdateChange(
{ tag: "test1" } as any,
{ tag: "test1" } as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{ location: { search: "" } } as any,
{} as any
{ location: { search: "" } } as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["tag", "test"]]);

expect(result).toBe("item not in result");
Expand All @@ -129,11 +149,11 @@ describe("Update Change", () => {
});

const result = await new UpdateChange(
{ tag: "test1", filePath: "/test.jpg" } as any,
{ tag: "test1", filePath: "/test.jpg" } as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{ location: { search: "/test.jpg" } } as any,
{} as any
{ location: { search: "/test.jpg" } } as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["tag", "test"]]);

expect(result).toBe(true);
Expand All @@ -150,9 +170,13 @@ describe("Update Change", () => {
return Promise.resolve({} as IConnectionDefault);
});

await new UpdateChange({} as any, jest.fn(), jest.fn(), {} as any, {} as any).Update([
["tags", "test"]
]);
await new UpdateChange(
{} as unknown as IFileIndexItem,
jest.fn(),
jest.fn(),
{} as unknown as IUseLocation,
{} as unknown as IDetailView
).Update([["tags", "test"]]);

expect(fetchPostSpy).toHaveBeenCalledTimes(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class UpdateChange {
* @param items - tuple with "value: string, name: string"
*/
public Update(items: [string, string][]): Promise<string | boolean> {
const updateObject: any = { f: this.fileIndexItem.filePath };
const updateObject: Record<string, string> = { f: this.fileIndexItem.filePath };

for (const [name, value] of items) {
if (!name) continue;
Expand All @@ -48,7 +48,10 @@ export class UpdateChange {
if (!replacedValue) replacedValue = AsciiNull();

// compare
const fileIndexObject: any = this.fileIndexItem;
const fileIndexObject: Record<string, string> = this.fileIndexItem as unknown as Record<
string,
string
>;

if (fileIndexObject[name] === undefined) {
console.error("missing name", name);
Expand Down
Loading

0 comments on commit 75395bd

Please sign in to comment.