Skip to content

Commit

Permalink
rename to internal folder instead of shared
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 4, 2024
1 parent c0b0a4d commit c2b51f6
Show file tree
Hide file tree
Showing 63 changed files with 130 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { GetFilterUrlColorClass } from "./shared/get-filter-url-color-class.ts";
import { CleanColorClass } from "./shared/clean-color-class.ts";
import { ClassNameContainer } from "./shared/class-name-container.ts";
import localization from "../../../localization/localization.json";
import { IArchiveProps } from "../../../interfaces/IArchiveProps.ts";

// <ColorClassFilter itemsCount={this.props.collectionsCount} subPath={this.props.subPath}
// colorClassActiveList={this.props.colorClassActiveList} colorClassUsage={this.props.colorClassUsage}></ColorClassFilter>
Expand All @@ -21,6 +22,19 @@ export interface IColorClassProp {
sticky?: boolean;
}

function stateFallback(state: IArchiveProps, props: IColorClassProp) {
// props is used as default, state only for update
if (!state) {
state = {
...newIArchive(),
colorClassUsage: props.colorClassUsage,
colorClassActiveList: props.colorClassActiveList,
collectionsCount: props.itemsCount ? props.itemsCount : 0
};
}
return state;
}

const ColorClassFilter: React.FunctionComponent<IColorClassProp> = memo((props) => {
// content
const settings = useGlobalSettings();
Expand All @@ -43,15 +57,8 @@ const ColorClassFilter: React.FunctionComponent<IColorClassProp> = memo((props)
const history = useLocation();

let { state } = React.useContext(ArchiveContext);
// props is used as default, state only for update
if (!state) {
state = {
...newIArchive(),
colorClassUsage: props.colorClassUsage,
colorClassActiveList: props.colorClassActiveList,
collectionsCount: props.itemsCount ? props.itemsCount : 0
};
}
state = stateFallback(state, props);

const [colorClassUsage, setColorClassUsage] = useState(props.colorClassUsage);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { act } from "react-dom/test-utils";
import { MemoryRouter } from "react-router-dom";
import { IUseLocation } from "../../../hooks/use-location/interfaces/IUseLocation";
import * as useLocation from "../../../hooks/use-location/use-location";
import {
IFileIndexItem,
newIFileIndexItemArray
} from "../../../interfaces/IFileIndexItem";
import { IFileIndexItem, newIFileIndexItemArray } from "../../../interfaces/IFileIndexItem";
import { Router } from "../../../router-app/router-app";
import * as FlatListItem from "../../atoms/flat-list-item/flat-list-item";
import * as ListImageChildItem from "../../atoms/list-image-child-item/list-image-child-item";
import ItemListView from "./item-list-view";
import * as ShiftSelectionHelper from "./shared/shift-selection-helper";
import * as ShiftSelectionHelper from "./internal/shift-selection-helper";

describe("ItemListView", () => {
it("renders (without state component)", () => {
Expand All @@ -32,17 +29,11 @@ describe("ItemListView", () => {
it("search with data-filepath in child element", () => {
const component = render(
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<ItemListView iconList={true} fileIndexItems={exampleData} colorClassUsage={[]} />
</MemoryRouter>
);

const element = screen.queryAllByTestId(
"list-image-view-select-container"
)[0];
const element = screen.queryAllByTestId("list-image-view-select-container")[0];

expect(element).toBeTruthy();

Expand All @@ -58,11 +49,7 @@ describe("ItemListView", () => {
.mockImplementationOnce(() => <></>);
const component = render(
<MemoryRouter>
<ItemListView
iconList={false}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<ItemListView iconList={false} fileIndexItems={exampleData} colorClassUsage={[]} />
</MemoryRouter>
);
expect(flatListItemSpy).toBeCalled();
Expand All @@ -72,24 +59,15 @@ describe("ItemListView", () => {
it("no content", () => {
const component = render(
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={undefined as any}
colorClassUsage={[]}
/>
<ItemListView iconList={true} fileIndexItems={undefined as any} colorClassUsage={[]} />
</MemoryRouter>
);
expect(component.container.textContent).toBe("no content");
});

it("text should be: New? Set your drive location in the settings. There are no photos in this folder", () => {
const component = render(
<ItemListView
iconList={true}
fileIndexItems={[]}
subPath="/"
colorClassUsage={[]}
/>
<ItemListView iconList={true} fileIndexItems={[]} subPath="/" colorClassUsage={[]} />
);
expect(component.container.textContent).toBe(
"New? Set your drive location in the settings. There are no photos in this folder"
Expand All @@ -98,25 +76,14 @@ describe("ItemListView", () => {

it("text should be: There are no photos in this folder", () => {
const component = render(
<ItemListView
iconList={true}
fileIndexItems={[]}
subPath="/test"
colorClassUsage={[]}
/>
);
expect(component.container.textContent).toBe(
"There are no photos in this folder"
<ItemListView iconList={true} fileIndexItems={[]} subPath="/test" colorClassUsage={[]} />
);
expect(component.container.textContent).toBe("There are no photos in this folder");
});

it("you did select a different colorclass but there a no items with this colorclass", () => {
const component = render(
<ItemListView
iconList={true}
fileIndexItems={[]}
colorClassUsage={[2]}
/>
<ItemListView iconList={true} fileIndexItems={[]} colorClassUsage={[2]} />
);
expect(component.container.textContent).toBe(
"There are more items, but these are outside of your filters. To see everything click on 'Reset Filter'"
Expand All @@ -143,9 +110,7 @@ describe("ItemListView", () => {
navigate: jest.fn()
} as unknown as IUseLocation;

jest
.spyOn(useLocation, "default")
.mockImplementationOnce(() => useLocationMock);
jest.spyOn(useLocation, "default").mockImplementationOnce(() => useLocationMock);

jest.useFakeTimers();

Expand Down Expand Up @@ -179,17 +144,11 @@ describe("ItemListView", () => {

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

const item = screen.queryByTestId(
"list-image-view-select-container"
) as HTMLButtonElement;
const item = screen.queryByTestId("list-image-view-select-container") as HTMLButtonElement;

console.log(component.container.innerHTML);
expect(item).toBeTruthy();
Expand Down Expand Up @@ -223,11 +182,7 @@ describe("ItemListView", () => {
.mockImplementationOnce(() => <>t</>);
const component = render(
<MemoryRouter>
<ItemListView
iconList={true}
fileIndexItems={exampleData}
colorClassUsage={[]}
/>
<ItemListView iconList={true} fileIndexItems={exampleData} colorClassUsage={[]} />
</MemoryRouter>
);
expect(listImageChildItemSpy).toBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { URLPath } from "../../../shared/url-path";
import FlatListItem from "../../atoms/flat-list-item/flat-list-item";
import ListImageChildItem from "../../atoms/list-image-child-item/list-image-child-item";
import ListImageViewSelectContainer from "../list-image-view-select-container/list-image-view-select-container";
import { ShiftSelectionHelper } from "./shared/shift-selection-helper";
import { WarningBoxNoPhotosFilter } from "./shared/warning-box-no-photos-filter";
import { ShiftSelectionHelper } from "./internal/shift-selection-helper";
import { WarningBoxNoPhotosFilter } from "./internal/warning-box-no-photos-filter";

interface ItemListProps {
fileIndexItems: Array<IFileIndexItem>;
Expand All @@ -17,6 +17,7 @@ interface ItemListProps {
iconList?: boolean;
subPath?: string;
}

/**
* A list with links to the items
*/
Expand Down Expand Up @@ -75,11 +76,7 @@ const ItemListView: React.FunctionComponent<ItemListProps> = memo((props) => {
key={item.fileName + item.lastEdited + item.colorClass}
onSelectionCallback={onSelectionCallback}
>
{props.iconList ? (
<ListImageChildItem {...item} />
) : (
<FlatListItem item={item} />
)}
{props.iconList ? <ListImageChildItem {...item} /> : <FlatListItem item={item} />}
</ListImageViewSelectContainer>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import {
act,
fireEvent,
render,
screen,
waitFor
} from "@testing-library/react";
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
import React from "react";
import { MemoryRouter } from "react-router-dom";
import * as useFetch from "../../../hooks/use-fetch";
import {
IConnectionDefault,
newIConnectionDefault
} from "../../../interfaces/IConnectionDefault";
import { IConnectionDefault, newIConnectionDefault } from "../../../interfaces/IConnectionDefault";
import { IEnvFeatures } from "../../../interfaces/IEnvFeatures";
import MenuInlineSearch from "./menu-inline-search";
import * as ArrowKeyDown from "./shared/arrow-key-down";
import * as InlineSearchSuggest from "./shared/inline-search-suggest";
import * as ArrowKeyDown from "./internal/arrow-key-down";
import * as InlineSearchSuggest from "./internal/inline-search-suggest";

describe("menu-inline-search", () => {
it("renders", () => {
Expand All @@ -40,13 +31,9 @@ describe("menu-inline-search", () => {
const menuBar = render(<MenuInlineSearch />);

// default
expect(menuBar.container.querySelector("label")?.classList).toContain(
"icon-addon--search"
);
expect(menuBar.container.querySelector("label")?.classList).toContain("icon-addon--search");

const input = menuBar.queryByTestId(
"menu-inline-search"
) as HTMLInputElement;
const input = menuBar.queryByTestId("menu-inline-search") as HTMLInputElement;

expect(input).not.toBeNull();

Expand Down Expand Up @@ -81,9 +68,7 @@ describe("menu-inline-search", () => {
menuBar = render(<MenuInlineSearch />);
});

const input = screen.queryByTestId(
"menu-inline-search"
) as HTMLInputElement;
const input = screen.queryByTestId("menu-inline-search") as HTMLInputElement;

expect(input).not.toBeNull();

Expand All @@ -100,13 +85,9 @@ describe("menu-inline-search", () => {
input.blur();
});

expect(menuBar.container.querySelector("label")?.classList).toContain(
"icon-addon--search"
);
expect(menuBar.container.querySelector("label")?.classList).toContain("icon-addon--search");

expect(
menuBar.findByTestId("menu-inline-search-search-icon")
).toBeTruthy();
expect(menuBar.findByTestId("menu-inline-search-search-icon")).toBeTruthy();

menuBar.unmount();
});
Expand Down Expand Up @@ -139,9 +120,7 @@ describe("menu-inline-search", () => {
.mockImplementationOnce(() => newIConnectionDefault());

const callback = jest.fn();
const menuBar = render(
<MenuInlineSearch defaultText={"tes"} callback={callback} />
);
const menuBar = render(<MenuInlineSearch defaultText={"tes"} callback={callback} />);

expect(screen.getByTestId("default-menu-item-trash")).toBeTruthy();
expect(screen.getByTestId("default-menu-item-logout")).toBeTruthy();
Expand All @@ -164,10 +143,7 @@ describe("menu-inline-search", () => {
<>
{props.suggest?.map((query, index) =>
index <= 8 ? (
<li
key={query}
data-test={"menu-inline-search-suggest-" + query}
></li>
<li key={query} data-test={"menu-inline-search-suggest-" + query}></li>
) : null
)}
</>
Expand All @@ -181,8 +157,8 @@ describe("menu-inline-search", () => {
</MemoryRouter>
);

expect(inlineSearchSuggestSpy).toBeCalledTimes(1);
expect(inlineSearchSuggestSpy).toBeCalledWith(
expect(inlineSearchSuggestSpy).toHaveBeenCalledTimes(1);
expect(inlineSearchSuggestSpy).toHaveBeenCalledWith(
{
callback: callback,
defaultText: "tes",
Expand Down Expand Up @@ -211,13 +187,9 @@ describe("menu-inline-search", () => {
.mockImplementationOnce(() => newIConnectionDefault());

const callback = jest.fn();
const menuBar = render(
<MenuInlineSearch defaultText={"tes"} callback={callback} />
);
const menuBar = render(<MenuInlineSearch defaultText={"tes"} callback={callback} />);

const input = screen.queryByTestId(
"menu-inline-search"
) as HTMLInputElement;
const input = screen.queryByTestId("menu-inline-search") as HTMLInputElement;

expect(input).not.toBeNull();

Expand All @@ -229,7 +201,7 @@ describe("menu-inline-search", () => {

expect(results).toBeTruthy();

expect(callback).toBeCalledTimes(0);
expect(callback).toHaveBeenCalledTimes(0);
menuBar.unmount();
});

Expand All @@ -248,23 +220,17 @@ describe("menu-inline-search", () => {
.mockImplementationOnce(() => newIConnectionDefault());

const callback = jest.fn();
const menuBar = render(
<MenuInlineSearch defaultText={"tes"} callback={callback} />
);
const menuBar = render(<MenuInlineSearch defaultText={"tes"} callback={callback} />);

const arrowKeyDownSpy = jest
.spyOn(ArrowKeyDown, "default")
.mockImplementationOnce(() => {});
const arrowKeyDownSpy = jest.spyOn(ArrowKeyDown, "default").mockImplementationOnce(() => {});

const input = screen.queryByTestId(
"menu-inline-search"
) as HTMLInputElement;
const input = screen.queryByTestId("menu-inline-search") as HTMLInputElement;

expect(input).not.toBeNull();

fireEvent.keyDown(input, { target: { value: "test" } });

expect(arrowKeyDownSpy).toBeCalled();
expect(arrowKeyDownSpy).toHaveBeenCalled();

menuBar.unmount();
});
Expand Down
Loading

0 comments on commit c2b51f6

Please sign in to comment.