diff --git a/src/main/ask-boolean/__snapshots__/ask-boolean.test.ts.snap b/src/main/ask-boolean/__snapshots__/ask-boolean.test.ts.snap deleted file mode 100644 index 33b2ec4033..0000000000 --- a/src/main/ask-boolean/__snapshots__/ask-boolean.test.ts.snap +++ /dev/null @@ -1,666 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ask-boolean given started when asking multiple questions renders 1`] = ` - -
-
-
- - - home - - - - - arrow_back - - - - - arrow_forward - - -
-
-
-
-
-
-
-
-
-
- - - info_outline - - -
-
-
- - some-title - -

- Some question -

-
- - -
-
-
-
- - - close - - -
-
-
-
- - - info_outline - - -
-
-
- - some-other-title - -

- Some other question -

-
- - -
-
-
-
- - - close - - -
-
-
-
- -`; - -exports[`ask-boolean given started when asking multiple questions when answering to first question renders 1`] = ` - -
-
-
- - - home - - - - - arrow_back - - - - - arrow_forward - - -
-
-
-
-
-
-
-
-
-
- - - info_outline - - -
-
-
- - some-other-title - -

- Some other question -

-
- - -
-
-
-
- - - close - - -
-
-
-
- -`; - -exports[`ask-boolean given started when asking question renders 1`] = ` - -
-
-
- - - home - - - - - arrow_back - - - - - arrow_forward - - -
-
-
-
-
-
-
-
-
-
- - - info_outline - - -
-
-
- - some-title - -

- Some question -

-
- - -
-
-
-
- - - close - - -
-
-
-
- -`; - -exports[`ask-boolean given started when asking question when user answers "no" renders 1`] = ` - -
-
-
- - - home - - - - - arrow_back - - - - - arrow_forward - - -
-
-
-
-
-
-
-
-
- -`; - -exports[`ask-boolean given started when asking question when user answers "yes" renders 1`] = ` - -
-
-
- - - home - - - - - arrow_back - - - - - arrow_forward - - -
-
-
-
-
-
-
-
-
- -`; - -exports[`ask-boolean given started when asking question when user closes notification without answering the question renders 1`] = ` - -
-
-
- - - home - - - - - arrow_back - - - - - arrow_forward - - -
-
-
-
-
-
-
-
-
- -`; diff --git a/src/main/ask-boolean/ask-boolean-answer-channel-listener.injectable.ts b/src/main/ask-boolean/ask-boolean-answer-channel-listener.injectable.ts deleted file mode 100644 index 06bc3972eb..0000000000 --- a/src/main/ask-boolean/ask-boolean-answer-channel-listener.injectable.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { getInjectable } from "@ogre-tools/injectable"; -import type { AskBooleanAnswerChannel } from "../../common/ask-boolean/ask-boolean-answer-channel.injectable"; -import askBooleanAnswerChannelInjectable from "../../common/ask-boolean/ask-boolean-answer-channel.injectable"; -import askBooleanPromiseInjectable from "./ask-boolean-promise.injectable"; -import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token"; -import { messageChannelListenerInjectionToken } from "../../common/utils/channel/message-channel-listener-injection-token"; - - -const askBooleanAnswerChannelListenerInjectable = getInjectable({ - id: "ask-boolean-answer-channel-listener", - - instantiate: (di): MessageChannelListener => ({ - channel: di.inject(askBooleanAnswerChannelInjectable), - - handler: ({ id, value }) => { - const answerPromise = di.inject(askBooleanPromiseInjectable, id); - - answerPromise.resolve(value); - }, - }), - - injectionToken: messageChannelListenerInjectionToken, -}); - -export default askBooleanAnswerChannelListenerInjectable; diff --git a/src/main/ask-boolean/ask-boolean-promise.injectable.ts b/src/main/ask-boolean/ask-boolean-promise.injectable.ts deleted file mode 100644 index 827714084f..0000000000 --- a/src/main/ask-boolean/ask-boolean-promise.injectable.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; - -const askBooleanPromiseInjectable = getInjectable({ - id: "ask-boolean-promise", - - instantiate: (di, questionId: string) => { - void questionId; - - let resolve: (value: boolean) => void; - - const promise = new Promise(_resolve => { - resolve = _resolve; - }); - - return ({ - promise, - - resolve: (value: boolean) => { - resolve(value); - }, - }); - }, - - lifecycle: lifecycleEnum.keyedSingleton({ - getInstanceKey: (di, questionId: string) => questionId, - }), -}); - -export default askBooleanPromiseInjectable; diff --git a/src/main/ask-boolean/ask-boolean.injectable.ts b/src/main/ask-boolean/ask-boolean.injectable.ts deleted file mode 100644 index 1fa54629b2..0000000000 --- a/src/main/ask-boolean/ask-boolean.injectable.ts +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { getInjectable } from "@ogre-tools/injectable"; -import { messageToChannelInjectionToken } from "../../common/utils/channel/message-to-channel-injection-token"; -import askBooleanQuestionChannelInjectable from "../../common/ask-boolean/ask-boolean-question-channel.injectable"; -import askBooleanPromiseInjectable from "./ask-boolean-promise.injectable"; -import getRandomIdInjectable from "../../common/utils/get-random-id.injectable"; - -export type AskBoolean = ({ - title, - question, -}: { - title: string; - question: string; -}) => Promise; - -const askBooleanInjectable = getInjectable({ - id: "ask-boolean", - - instantiate: (di): AskBoolean => { - const messageToChannel = di.inject(messageToChannelInjectionToken); - const askBooleanChannel = di.inject(askBooleanQuestionChannelInjectable); - const getRandomId = di.inject(getRandomIdInjectable); - - return async ({ title, question }) => { - const id = getRandomId(); - - const returnValuePromise = di.inject(askBooleanPromiseInjectable, id); - - await messageToChannel(askBooleanChannel, { id, title, question }); - - return await returnValuePromise.promise; - }; - }, -}); - -export default askBooleanInjectable; diff --git a/src/main/ask-boolean/ask-boolean.test.ts b/src/main/ask-boolean/ask-boolean.test.ts deleted file mode 100644 index 79fecdceca..0000000000 --- a/src/main/ask-boolean/ask-boolean.test.ts +++ /dev/null @@ -1,206 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; -import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; -import type { AskBoolean } from "./ask-boolean.injectable"; -import askBooleanInjectable from "./ask-boolean.injectable"; -import { getPromiseStatus } from "../../common/test-utils/get-promise-status"; -import type { RenderResult } from "@testing-library/react"; -import { fireEvent } from "@testing-library/react"; -import getRandomIdInjectable from "../../common/utils/get-random-id.injectable"; - -describe("ask-boolean", () => { - let applicationBuilder: ApplicationBuilder; - let askBoolean: AskBoolean; - - beforeEach(() => { - applicationBuilder = getApplicationBuilder(); - - const getRandomIdFake = jest - .fn() - .mockReturnValueOnce("some-random-id-1") - .mockReturnValueOnce("some-random-id-2"); - - applicationBuilder.dis.mainDi.override(getRandomIdInjectable, () => getRandomIdFake); - - askBoolean = applicationBuilder.dis.mainDi.inject(askBooleanInjectable); - }); - - describe("given started", () => { - let rendered: RenderResult; - - beforeEach(async () => { - rendered = await applicationBuilder.render(); - }); - - describe("when asking question", () => { - let actualPromise: Promise; - - beforeEach(() => { - actualPromise = askBoolean({ - title: "some-title", - question: "Some question", - }); - }); - - it("does not resolve yet", async () => { - const promiseStatus = await getPromiseStatus(actualPromise); - - expect(promiseStatus.fulfilled).toBe(false); - }); - - it("renders", () => { - expect(rendered.baseElement).toMatchSnapshot(); - }); - - it("shows notification", () => { - const notification = rendered.getByTestId("ask-boolean-some-random-id-1"); - - expect(notification).not.toBeUndefined(); - }); - - describe('when user answers "yes"', () => { - beforeEach(() => { - const button = rendered.getByTestId("ask-boolean-some-random-id-1-button-yes"); - - fireEvent.click(button); - }); - - it("renders", () => { - expect(rendered.baseElement).toMatchSnapshot(); - }); - - it("does not show notification anymore", () => { - const notification = rendered.queryByTestId("ask-boolean-some-random-id-1"); - - expect(notification).toBeNull(); - }); - - it("resolves", async () => { - const actual = await actualPromise; - - expect(actual).toBe(true); - }); - }); - - describe('when user answers "no"', () => { - beforeEach(() => { - const button = rendered.getByTestId("ask-boolean-some-random-id-1-button-no"); - - fireEvent.click(button); - }); - - it("renders", () => { - expect(rendered.baseElement).toMatchSnapshot(); - }); - - it("does not show notification anymore", () => { - const notification = rendered.queryByTestId("ask-boolean-some-random-id-1"); - - expect(notification).toBeNull(); - }); - - it("resolves", async () => { - const actual = await actualPromise; - - expect(actual).toBe(false); - }); - }); - - describe("when user closes notification without answering the question", () => { - beforeEach(() => { - const button = rendered.getByTestId("close-notification-for-ask-boolean-for-some-random-id-1"); - - fireEvent.click(button); - }); - - it("renders", () => { - expect(rendered.baseElement).toMatchSnapshot(); - }); - - it("does not show notification anymore", () => { - const notification = rendered.queryByTestId("ask-boolean-some-random-id-1"); - - expect(notification).toBeNull(); - }); - - it("resolves", async () => { - const actual = await actualPromise; - - expect(actual).toBe(false); - }); - }); - }); - - describe("when asking multiple questions", () => { - let firstQuestionPromise: Promise; - let secondQuestionPromise: Promise; - - beforeEach(() => { - firstQuestionPromise = askBoolean({ - title: "some-title", - question: "Some question", - }); - - secondQuestionPromise = askBoolean({ - title: "some-other-title", - question: "Some other question", - }); - }); - - it("renders", () => { - expect(rendered.baseElement).toMatchSnapshot(); - }); - - it("shows notification for first question", () => { - const notification = rendered.getByTestId("ask-boolean-some-random-id-1"); - - expect(notification).not.toBeUndefined(); - }); - - it("shows notification for second question", () => { - const notification = rendered.getByTestId("ask-boolean-some-random-id-2"); - - expect(notification).not.toBeUndefined(); - }); - - describe("when answering to first question", () => { - beforeEach(() => { - const button = rendered.getByTestId("ask-boolean-some-random-id-1-button-no"); - - fireEvent.click(button); - }); - - it("renders", () => { - expect(rendered.baseElement).toMatchSnapshot(); - }); - - it("does not show notification for first question anymore", () => { - const notification = rendered.queryByTestId("ask-boolean-some-random-id-1"); - - expect(notification).toBeNull(); - }); - - it("still shows notification for second question", () => { - const notification = rendered.getByTestId("ask-boolean-some-random-id-2"); - - expect(notification).not.toBeUndefined(); - }); - - it("resolves first question", async () => { - const actual = await firstQuestionPromise; - - expect(actual).toBe(false); - }); - - it("does not resolve second question yet", async () => { - const promiseStatus = await getPromiseStatus(secondQuestionPromise); - - expect(promiseStatus.fulfilled).toBe(false); - }); - }); - }); - }); -});