Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 22, 2024
1 parent e24c49e commit 3bc8c9f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { IEnvFeatures } from "../../../interfaces/IEnvFeatures";
import * as FetchPost from "../../../shared/fetch/fetch-post";
import { UrlQuery } from "../../../shared/url-query";
import * as Notification from "../../atoms/notification/notification";
import MenuOptionDesktopEditorOpenSingle from "./menu-option-desktop-editor-open-single";
import MenuOptionDesktopEditorOpenSingle, {
OpenDesktopSingle
} from "./menu-option-desktop-editor-open-single";

describe("MenuOptionDesktopEditorOpenSingle", () => {
it("should render without errors", () => {
Expand Down Expand Up @@ -62,6 +64,41 @@ describe("MenuOptionDesktopEditorOpenSingle", () => {
container.unmount();
});

it("calls StartMenuOptionDesktopEditorOpenSelection on hotkey trigger", async () => {
const mockIConnectionDefaultResolve: Promise<IConnectionDefault> = Promise.resolve({
data: true,
statusCode: 200
} as IConnectionDefault);

const fetchPostSpy = jest
.spyOn(FetchPost, "default")
.mockReset()
.mockImplementationOnce(() => mockIConnectionDefaultResolve)
.mockImplementationOnce(() => mockIConnectionDefaultResolve);

const container = render(
<MenuOptionDesktopEditorOpenSingle
subPath={"/test.jpg"}
collections={false}
isReadOnly={false}
/>
);

fireEvent.keyDown(document.body, { key: "e", ctrlKey: true });

await waitFor(() => {
expect(fetchPostSpy).toHaveBeenCalled();
expect(fetchPostSpy).toHaveBeenCalledTimes(1);

expect(fetchPostSpy).toHaveBeenNthCalledWith(
1,
new UrlQuery().UrlApiDesktopEditorOpen(),
"f=%2Ftest.jpg&collections=false"
);
container.unmount();
});
});

it("feature toggle disabled", () => {
const mockGetIConnectionDefaultFeatureToggle = {
statusCode: 200,
Expand Down Expand Up @@ -148,4 +185,9 @@ describe("MenuOptionDesktopEditorOpenSingle", () => {
});
container.unmount();
});

it("OpenDesktopSingle readonly should skip", async () => {
const result = await OpenDesktopSingle("/", false, jest.fn(), "error", true);
expect(result).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export async function OpenDesktopSingle(
setIsError: React.Dispatch<React.SetStateAction<string>>,
messageDesktopEditorUnableToOpen: string,
isReadOnly: boolean
) {
): Promise<boolean> {
if (isReadOnly) {
return;
return false;
}
const urlOpen = new UrlQuery().UrlApiDesktopEditorOpen();

Expand All @@ -37,6 +37,7 @@ export async function OpenDesktopSingle(
if (openDesktopResult.statusCode >= 300) {
setIsError(messageDesktopEditorUnableToOpen);
}
return true;
}

const MenuOptionDesktopEditorOpenSingle: React.FunctionComponent<IMenuOptionDesktopEditorOpenSingleProps> =
Expand Down

0 comments on commit 3bc8c9f

Please sign in to comment.