1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make asking of boolean value from user not require explicit ID for question

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-05-23 14:56:57 +03:00
parent ff20645bbc
commit 21e05d935b
6 changed files with 45 additions and 40 deletions

View File

@ -392,7 +392,7 @@ exports[`installing update using tray when started when user checks for updates
>
<div
class="flex column gaps"
data-testid="ask-boolean-install-update"
data-testid="ask-boolean-some-irrelevant-random-id"
>
<b>
Update Available
@ -407,14 +407,14 @@ Lens should restart automatically, if it doesn't please restart manually. Instal
>
<button
class="Button light"
data-testid="ask-boolean-install-update-button-yes"
data-testid="ask-boolean-some-irrelevant-random-id-button-yes"
type="button"
>
Yes
</button>
<button
class="Button active outlined"
data-testid="ask-boolean-install-update-button-no"
data-testid="ask-boolean-some-irrelevant-random-id-button-no"
type="button"
>
No
@ -427,7 +427,7 @@ Lens should restart automatically, if it doesn't please restart manually. Instal
>
<i
class="Icon close material interactive focusable"
data-testid="close-notification-for-ask-boolean-for-install-update"
data-testid="close-notification-for-ask-boolean-for-some-irrelevant-random-id"
tabindex="0"
>
<span

View File

@ -184,7 +184,6 @@ describe("installing update", () => {
it("asks user to install update immediately", () => {
expect(askBooleanMock).toHaveBeenCalledWith({
id: "install-update",
title: "Update Available",
question:
"Version some-version of Lens IDE is available and ready to be installed. Would you like to update now?\n\n" +

View File

@ -77,7 +77,6 @@ const processCheckingForUpdatesInjectable = getInjectable({
}
const userWantsToInstallUpdate = await askBoolean({
id: "install-update",
title: "Update Available",
question: `Version ${version} of Lens IDE is available and ready to be installed. Would you like to update now?\n\n` +

View File

@ -29,7 +29,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
>
<div
class="flex column gaps"
data-testid="ask-boolean-some-question-id"
data-testid="ask-boolean-some-random-id-1"
>
<b>
some-title
@ -42,14 +42,14 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
>
<button
class="Button light"
data-testid="ask-boolean-some-question-id-button-yes"
data-testid="ask-boolean-some-random-id-1-button-yes"
type="button"
>
Yes
</button>
<button
class="Button active outlined"
data-testid="ask-boolean-some-question-id-button-no"
data-testid="ask-boolean-some-random-id-1-button-no"
type="button"
>
No
@ -62,7 +62,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
>
<i
class="Icon close material interactive focusable"
data-testid="close-notification-for-ask-boolean-for-some-question-id"
data-testid="close-notification-for-ask-boolean-for-some-random-id-1"
tabindex="0"
>
<span
@ -97,7 +97,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
>
<div
class="flex column gaps"
data-testid="ask-boolean-some-other-question-id"
data-testid="ask-boolean-some-random-id-2"
>
<b>
some-other-title
@ -110,14 +110,14 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
>
<button
class="Button light"
data-testid="ask-boolean-some-other-question-id-button-yes"
data-testid="ask-boolean-some-random-id-2-button-yes"
type="button"
>
Yes
</button>
<button
class="Button active outlined"
data-testid="ask-boolean-some-other-question-id-button-no"
data-testid="ask-boolean-some-random-id-2-button-no"
type="button"
>
No
@ -130,7 +130,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
>
<i
class="Icon close material interactive focusable"
data-testid="close-notification-for-ask-boolean-for-some-other-question-id"
data-testid="close-notification-for-ask-boolean-for-some-random-id-2"
tabindex="0"
>
<span
@ -176,7 +176,7 @@ exports[`ask-boolean given started when asking multiple questions when answering
>
<div
class="flex column gaps"
data-testid="ask-boolean-some-other-question-id"
data-testid="ask-boolean-some-random-id-2"
>
<b>
some-other-title
@ -189,14 +189,14 @@ exports[`ask-boolean given started when asking multiple questions when answering
>
<button
class="Button light"
data-testid="ask-boolean-some-other-question-id-button-yes"
data-testid="ask-boolean-some-random-id-2-button-yes"
type="button"
>
Yes
</button>
<button
class="Button active outlined"
data-testid="ask-boolean-some-other-question-id-button-no"
data-testid="ask-boolean-some-random-id-2-button-no"
type="button"
>
No
@ -209,7 +209,7 @@ exports[`ask-boolean given started when asking multiple questions when answering
>
<i
class="Icon close material interactive focusable"
data-testid="close-notification-for-ask-boolean-for-some-other-question-id"
data-testid="close-notification-for-ask-boolean-for-some-random-id-2"
tabindex="0"
>
<span
@ -255,7 +255,7 @@ exports[`ask-boolean given started when asking question renders 1`] = `
>
<div
class="flex column gaps"
data-testid="ask-boolean-some-question-id"
data-testid="ask-boolean-some-random-id-1"
>
<b>
some-title
@ -268,14 +268,14 @@ exports[`ask-boolean given started when asking question renders 1`] = `
>
<button
class="Button light"
data-testid="ask-boolean-some-question-id-button-yes"
data-testid="ask-boolean-some-random-id-1-button-yes"
type="button"
>
Yes
</button>
<button
class="Button active outlined"
data-testid="ask-boolean-some-question-id-button-no"
data-testid="ask-boolean-some-random-id-1-button-no"
type="button"
>
No
@ -288,7 +288,7 @@ exports[`ask-boolean given started when asking question renders 1`] = `
>
<i
class="Icon close material interactive focusable"
data-testid="close-notification-for-ask-boolean-for-some-question-id"
data-testid="close-notification-for-ask-boolean-for-some-random-id-1"
tabindex="0"
>
<span

View File

@ -6,13 +6,12 @@ import { getInjectable } from "@ogre-tools/injectable";
import { sendToChannelInjectionToken } from "../../common/channel/send-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 = ({
id,
title,
question,
}: {
id: string;
title: string;
question: string;
}) => Promise<boolean>;
@ -23,8 +22,11 @@ const askBooleanInjectable = getInjectable({
instantiate: (di): AskBoolean => {
const sendToChannel = di.inject(sendToChannelInjectionToken);
const askBooleanChannel = di.inject(askBooleanQuestionChannelInjectable);
const getRandomId = di.inject(getRandomIdInjectable);
return async ({ title, question }) => {
const id = getRandomId();
return async ({ id, title, question }) => {
const returnValuePromise = di.inject(askBooleanPromiseInjectable, id);
returnValuePromise.clear();

View File

@ -9,6 +9,7 @@ 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;
@ -17,6 +18,13 @@ describe("ask-boolean", () => {
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);
});
@ -32,7 +40,6 @@ describe("ask-boolean", () => {
beforeEach(() => {
actualPromise = askBoolean({
id: "some-question-id",
title: "some-title",
question: "Some question",
});
@ -49,14 +56,14 @@ describe("ask-boolean", () => {
});
it("shows notification", () => {
const notification = rendered.getByTestId("ask-boolean-some-question-id");
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-question-id-button-yes");
const button = rendered.getByTestId("ask-boolean-some-random-id-1-button-yes");
fireEvent.click(button);
});
@ -66,7 +73,7 @@ describe("ask-boolean", () => {
});
it("does not show notification anymore", () => {
const notification = rendered.queryByTestId("ask-boolean-some-question-id");
const notification = rendered.queryByTestId("ask-boolean-some-random-id-1");
expect(notification).toBeNull();
});
@ -80,7 +87,7 @@ describe("ask-boolean", () => {
describe('when user answers "no"', () => {
beforeEach(() => {
const button = rendered.getByTestId("ask-boolean-some-question-id-button-no");
const button = rendered.getByTestId("ask-boolean-some-random-id-1-button-no");
fireEvent.click(button);
});
@ -90,7 +97,7 @@ describe("ask-boolean", () => {
});
it("does not show notification anymore", () => {
const notification = rendered.queryByTestId("ask-boolean-some-question-id");
const notification = rendered.queryByTestId("ask-boolean-some-random-id-1");
expect(notification).toBeNull();
});
@ -104,7 +111,7 @@ describe("ask-boolean", () => {
describe("when user closes notification without answering the question", () => {
beforeEach(() => {
const button = rendered.getByTestId("close-notification-for-ask-boolean-for-some-question-id");
const button = rendered.getByTestId("close-notification-for-ask-boolean-for-some-random-id-1");
fireEvent.click(button);
});
@ -114,7 +121,7 @@ describe("ask-boolean", () => {
});
it("does not show notification anymore", () => {
const notification = rendered.queryByTestId("ask-boolean-some-question-id");
const notification = rendered.queryByTestId("ask-boolean-some-random-id-1");
expect(notification).toBeNull();
});
@ -133,13 +140,11 @@ describe("ask-boolean", () => {
beforeEach(() => {
firstQuestionPromise = askBoolean({
id: "some-question-id",
title: "some-title",
question: "Some question",
});
secondQuestionPromise = askBoolean({
id: "some-other-question-id",
title: "some-other-title",
question: "Some other question",
});
@ -150,20 +155,20 @@ describe("ask-boolean", () => {
});
it("shows notification for first question", () => {
const notification = rendered.getByTestId("ask-boolean-some-question-id");
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-other-question-id");
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-question-id-button-no");
const button = rendered.getByTestId("ask-boolean-some-random-id-1-button-no");
fireEvent.click(button);
});
@ -173,13 +178,13 @@ describe("ask-boolean", () => {
});
it("does not show notification for first question anymore", () => {
const notification = rendered.queryByTestId("ask-boolean-some-question-id");
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-other-question-id");
const notification = rendered.getByTestId("ask-boolean-some-random-id-2");
expect(notification).not.toBeUndefined();
});