Skip to content

Commit

Permalink
fix tests. - 49 to go
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Aug 18, 2023
1 parent abb9558 commit a0b55d4
Show file tree
Hide file tree
Showing 45 changed files with 378 additions and 283 deletions.
1 change: 1 addition & 0 deletions starsky/starsky/clientapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}'",
"test": "jest --watch",
"test:ci": "jest --ci --coverage --silent",
"test-ci": "npm run test:ci",
"test:ci:debug": "jest --ci --coverage",
"preview": "vite preview",
"tsc": "tsc"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import {
IRelativeObjects,
newIRelativeObjects
Expand All @@ -7,7 +8,11 @@ import ArchivePagination from "./archive-pagination";

describe("ArchivePagination", () => {
it("renders new object", () => {
render(<ArchivePagination relativeObjects={newIRelativeObjects()} />);
render(
<MemoryRouter>
<ArchivePagination relativeObjects={newIRelativeObjects()} />
</MemoryRouter>
);
});

const relativeObjects = {
Expand All @@ -17,7 +22,9 @@ describe("ArchivePagination", () => {

it("next page exist", () => {
const Component = render(
<ArchivePagination relativeObjects={relativeObjects} />
<MemoryRouter>
<ArchivePagination relativeObjects={relativeObjects} />
</MemoryRouter>
);
const next = Component.queryByTestId(
"archive-pagination-next"
Expand All @@ -27,7 +34,9 @@ describe("ArchivePagination", () => {

it("prev page exist", () => {
const Component = render(
<ArchivePagination relativeObjects={relativeObjects} />
<MemoryRouter>
<ArchivePagination relativeObjects={relativeObjects} />
</MemoryRouter>
);
const next = Component.queryByTestId(
"archive-pagination-prev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ describe("ArchiveSidebarColorClass", () => {
dispatch
} as AppContext.IArchiveContext;

jest.mock("@reach/router", () => ({
navigate: jest.fn(),
globalHistory: jest.fn()
}));

// to use with: => import { act } from 'react-dom/test-utils';
Router.navigate("/?select=test.jpg");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ describe("ArchiveSidebarLabelEditAddOverwrite", () => {
}
} as AppContext.IArchiveContext;

jest.mock("@reach/router", () => ({
navigate: jest.fn(),
globalHistory: jest.fn()
}));

act(() => {
// to use with: => import { act } from 'react-dom/test-utils';
Router.navigate("/?select=test.jpg");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ describe("ArchiveSidebarLabelEditAddOverwrite", () => {
}
} as AppContext.IArchiveContext;

jest.mock("@reach/router", () => ({
navigate: jest.fn(),
globalHistory: jest.fn()
}));

act(() => {
// to use with: => import { act } from 'react-dom/test-utils';
Router.navigate("/?select=test.jpg");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
IFileIndexItem,
newIFileIndexItemArray
} from "../../../interfaces/IFileIndexItem";
import { Router } from "../../../router-app/router-app";
import { URLPath } from "../../../shared/url-path";
import ArchiveSidebarSelectionList from "./archive-sidebar-selection-list";
;

describe("archive-sidebar-selection-list", () => {
it("renders", () => {
render(
Expand All @@ -16,14 +15,9 @@ describe("archive-sidebar-selection-list", () => {

describe("with select state", () => {
beforeEach(() => {
jest.mock("@reach/router", () => ({
navigate: jest.fn(),
globalHistory: jest.fn()
}));

act(() => {
// to use with: => import { act } from 'react-dom/test-utils';
window.location.replace("/?select=test.jpg");
Router.navigate("/?select=test.jpg");
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { ArchiveContextProvider } from "../../../contexts/archive-context";
import { IArchiveProps } from "../../../interfaces/IArchiveProps";
import { newIFileIndexItemArray } from "../../../interfaces/IFileIndexItem";
import ArchiveSidebarSelectionList from "./archive-sidebar-selection-list";
;

export default {
title: "components/molecules/archive-sidebar/selection-list"
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { act, render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { Router } from "../../../router-app/router-app";
import { URLPath } from "../../../shared/url-path";
import ColorClassFilter from "./color-class-filter";
;

describe("ColorClassFilter", () => {
it("renders", () => {
render(
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1, 2]}
colorClassUsage={[1, 2]}
></ColorClassFilter>
<MemoryRouter>
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1, 2]}
colorClassUsage={[1, 2]}
></ColorClassFilter>
</MemoryRouter>
);
});

it("onClick value", () => {
const component = render(
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[1, 2]}
/>
<MemoryRouter>
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[1, 2]}
/>
</MemoryRouter>
);

const colorClass = screen.queryByTestId(
Expand Down Expand Up @@ -52,12 +56,14 @@ describe("ColorClassFilter", () => {

it("outside current scope display reset", () => {
const component = render(
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[3]}
/>
<MemoryRouter>
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[3]}
/>
</MemoryRouter>
);

expect(screen.getByTestId("color-class-filter-reset")).toBeTruthy();
Expand All @@ -67,12 +73,14 @@ describe("ColorClassFilter", () => {

it("onClick value and preloader exist", () => {
const component = render(
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[1, 2]}
/>
<MemoryRouter>
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[1, 2]}
/>
</MemoryRouter>
);

const colorClass = screen.queryByTestId(
Expand All @@ -91,15 +99,17 @@ describe("ColorClassFilter", () => {
});

it("undo selection when clicking on already selected colorclass", () => {
window.location.replace("/?colorclass=1");
Router.navigate("/?colorclass=1");

const component = render(
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[1, 2]}
/>
<MemoryRouter>
<ColorClassFilter
itemsCount={1}
subPath={"/test"}
colorClassActiveList={[1]}
colorClassUsage={[1, 2]}
/>
</MemoryRouter>
);

const colorClass = screen.queryByTestId(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fireEvent, render, screen } from "@testing-library/react";
import { act } from "react-dom/test-utils";
import { MemoryRouter } from "react-router-dom";
import {
IFileIndexItem,
newIFileIndexItemArray
Expand All @@ -26,11 +27,13 @@ describe("ItemListView", () => {

it("search with data-filepath in child element", () => {
const component = render(
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
</MemoryRouter>
);

const element = screen.queryAllByTestId(
Expand All @@ -50,23 +53,27 @@ describe("ItemListView", () => {
.spyOn(FlatListItem, "default")
.mockImplementationOnce(() => <></>);
const component = render(
<ItemListView
iconList={false}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<MemoryRouter>
<ItemListView
iconList={false}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
</MemoryRouter>
);
expect(flatListItemSpy).toBeCalled();
component.unmount();
});

it("no content", () => {
const component = render(
<ItemListView
iconList={true}
fileIndexItems={undefined as any}
colorClassUsage={[]}
/>
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={undefined as any}
colorClassUsage={[]}
/>
</MemoryRouter>
);
expect(component.container.textContent).toBe("no content");
});
Expand Down Expand Up @@ -157,11 +164,13 @@ describe("ItemListView", () => {
});

const component = render(
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
</MemoryRouter>
);

const item = screen.queryByTestId(
Expand Down Expand Up @@ -199,11 +208,13 @@ describe("ItemListView", () => {
.spyOn(ListImageChildItem, "default")
.mockImplementationOnce(() => <>t</>);
const component = render(
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
</MemoryRouter>
);
expect(listImageChildItemSpy).toBeCalled();
component.unmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
newIFileIndexItemArray
} from "../../../interfaces/IFileIndexItem";
import ItemListView from "./item-list-view";
;

const exampleData8Selected = [
{ fileName: "test.jpg", filePath: "/test.jpg", lastEdited: "1" },
{ fileName: "test2.jpg", filePath: "/test2.jpg", lastEdited: "1" },
Expand Down
Loading

0 comments on commit a0b55d4

Please sign in to comment.