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:
parent
ff20645bbc
commit
21e05d935b
@ -392,7 +392,7 @@ exports[`installing update using tray when started when user checks for updates
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex column gaps"
|
class="flex column gaps"
|
||||||
data-testid="ask-boolean-install-update"
|
data-testid="ask-boolean-some-irrelevant-random-id"
|
||||||
>
|
>
|
||||||
<b>
|
<b>
|
||||||
Update Available
|
Update Available
|
||||||
@ -407,14 +407,14 @@ Lens should restart automatically, if it doesn't please restart manually. Instal
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="Button light"
|
class="Button light"
|
||||||
data-testid="ask-boolean-install-update-button-yes"
|
data-testid="ask-boolean-some-irrelevant-random-id-button-yes"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="Button active outlined"
|
class="Button active outlined"
|
||||||
data-testid="ask-boolean-install-update-button-no"
|
data-testid="ask-boolean-some-irrelevant-random-id-button-no"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
No
|
No
|
||||||
@ -427,7 +427,7 @@ Lens should restart automatically, if it doesn't please restart manually. Instal
|
|||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
class="Icon close material interactive focusable"
|
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"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@ -184,7 +184,6 @@ describe("installing update", () => {
|
|||||||
|
|
||||||
it("asks user to install update immediately", () => {
|
it("asks user to install update immediately", () => {
|
||||||
expect(askBooleanMock).toHaveBeenCalledWith({
|
expect(askBooleanMock).toHaveBeenCalledWith({
|
||||||
id: "install-update",
|
|
||||||
title: "Update Available",
|
title: "Update Available",
|
||||||
question:
|
question:
|
||||||
"Version some-version of Lens IDE is available and ready to be installed. Would you like to update now?\n\n" +
|
"Version some-version of Lens IDE is available and ready to be installed. Would you like to update now?\n\n" +
|
||||||
|
|||||||
@ -77,7 +77,6 @@ const processCheckingForUpdatesInjectable = getInjectable({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userWantsToInstallUpdate = await askBoolean({
|
const userWantsToInstallUpdate = await askBoolean({
|
||||||
id: "install-update",
|
|
||||||
title: "Update Available",
|
title: "Update Available",
|
||||||
|
|
||||||
question: `Version ${version} of Lens IDE is available and ready to be installed. Would you like to update now?\n\n` +
|
question: `Version ${version} of Lens IDE is available and ready to be installed. Would you like to update now?\n\n` +
|
||||||
|
|||||||
@ -29,7 +29,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex column gaps"
|
class="flex column gaps"
|
||||||
data-testid="ask-boolean-some-question-id"
|
data-testid="ask-boolean-some-random-id-1"
|
||||||
>
|
>
|
||||||
<b>
|
<b>
|
||||||
some-title
|
some-title
|
||||||
@ -42,14 +42,14 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="Button light"
|
class="Button light"
|
||||||
data-testid="ask-boolean-some-question-id-button-yes"
|
data-testid="ask-boolean-some-random-id-1-button-yes"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="Button active outlined"
|
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"
|
type="button"
|
||||||
>
|
>
|
||||||
No
|
No
|
||||||
@ -62,7 +62,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
|
|||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
class="Icon close material interactive focusable"
|
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"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
@ -97,7 +97,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex column gaps"
|
class="flex column gaps"
|
||||||
data-testid="ask-boolean-some-other-question-id"
|
data-testid="ask-boolean-some-random-id-2"
|
||||||
>
|
>
|
||||||
<b>
|
<b>
|
||||||
some-other-title
|
some-other-title
|
||||||
@ -110,14 +110,14 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="Button light"
|
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"
|
type="button"
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="Button active outlined"
|
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"
|
type="button"
|
||||||
>
|
>
|
||||||
No
|
No
|
||||||
@ -130,7 +130,7 @@ exports[`ask-boolean given started when asking multiple questions renders 1`] =
|
|||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
class="Icon close material interactive focusable"
|
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"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
@ -176,7 +176,7 @@ exports[`ask-boolean given started when asking multiple questions when answering
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex column gaps"
|
class="flex column gaps"
|
||||||
data-testid="ask-boolean-some-other-question-id"
|
data-testid="ask-boolean-some-random-id-2"
|
||||||
>
|
>
|
||||||
<b>
|
<b>
|
||||||
some-other-title
|
some-other-title
|
||||||
@ -189,14 +189,14 @@ exports[`ask-boolean given started when asking multiple questions when answering
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="Button light"
|
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"
|
type="button"
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="Button active outlined"
|
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"
|
type="button"
|
||||||
>
|
>
|
||||||
No
|
No
|
||||||
@ -209,7 +209,7 @@ exports[`ask-boolean given started when asking multiple questions when answering
|
|||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
class="Icon close material interactive focusable"
|
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"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
@ -255,7 +255,7 @@ exports[`ask-boolean given started when asking question renders 1`] = `
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex column gaps"
|
class="flex column gaps"
|
||||||
data-testid="ask-boolean-some-question-id"
|
data-testid="ask-boolean-some-random-id-1"
|
||||||
>
|
>
|
||||||
<b>
|
<b>
|
||||||
some-title
|
some-title
|
||||||
@ -268,14 +268,14 @@ exports[`ask-boolean given started when asking question renders 1`] = `
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="Button light"
|
class="Button light"
|
||||||
data-testid="ask-boolean-some-question-id-button-yes"
|
data-testid="ask-boolean-some-random-id-1-button-yes"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="Button active outlined"
|
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"
|
type="button"
|
||||||
>
|
>
|
||||||
No
|
No
|
||||||
@ -288,7 +288,7 @@ exports[`ask-boolean given started when asking question renders 1`] = `
|
|||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
class="Icon close material interactive focusable"
|
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"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@ -6,13 +6,12 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import { sendToChannelInjectionToken } from "../../common/channel/send-to-channel-injection-token";
|
import { sendToChannelInjectionToken } from "../../common/channel/send-to-channel-injection-token";
|
||||||
import askBooleanQuestionChannelInjectable from "../../common/ask-boolean/ask-boolean-question-channel.injectable";
|
import askBooleanQuestionChannelInjectable from "../../common/ask-boolean/ask-boolean-question-channel.injectable";
|
||||||
import askBooleanPromiseInjectable from "./ask-boolean-promise.injectable";
|
import askBooleanPromiseInjectable from "./ask-boolean-promise.injectable";
|
||||||
|
import getRandomIdInjectable from "../../common/utils/get-random-id.injectable";
|
||||||
|
|
||||||
export type AskBoolean = ({
|
export type AskBoolean = ({
|
||||||
id,
|
|
||||||
title,
|
title,
|
||||||
question,
|
question,
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
|
||||||
title: string;
|
title: string;
|
||||||
question: string;
|
question: string;
|
||||||
}) => Promise<boolean>;
|
}) => Promise<boolean>;
|
||||||
@ -23,8 +22,11 @@ const askBooleanInjectable = getInjectable({
|
|||||||
instantiate: (di): AskBoolean => {
|
instantiate: (di): AskBoolean => {
|
||||||
const sendToChannel = di.inject(sendToChannelInjectionToken);
|
const sendToChannel = di.inject(sendToChannelInjectionToken);
|
||||||
const askBooleanChannel = di.inject(askBooleanQuestionChannelInjectable);
|
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);
|
const returnValuePromise = di.inject(askBooleanPromiseInjectable, id);
|
||||||
|
|
||||||
returnValuePromise.clear();
|
returnValuePromise.clear();
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import askBooleanInjectable from "./ask-boolean.injectable";
|
|||||||
import { getPromiseStatus } from "../../common/test-utils/get-promise-status";
|
import { getPromiseStatus } from "../../common/test-utils/get-promise-status";
|
||||||
import type { RenderResult } from "@testing-library/react";
|
import type { RenderResult } from "@testing-library/react";
|
||||||
import { fireEvent } from "@testing-library/react";
|
import { fireEvent } from "@testing-library/react";
|
||||||
|
import getRandomIdInjectable from "../../common/utils/get-random-id.injectable";
|
||||||
|
|
||||||
describe("ask-boolean", () => {
|
describe("ask-boolean", () => {
|
||||||
let applicationBuilder: ApplicationBuilder;
|
let applicationBuilder: ApplicationBuilder;
|
||||||
@ -17,6 +18,13 @@ describe("ask-boolean", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
applicationBuilder = getApplicationBuilder();
|
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);
|
askBoolean = applicationBuilder.dis.mainDi.inject(askBooleanInjectable);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -32,7 +40,6 @@ describe("ask-boolean", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
actualPromise = askBoolean({
|
actualPromise = askBoolean({
|
||||||
id: "some-question-id",
|
|
||||||
title: "some-title",
|
title: "some-title",
|
||||||
question: "Some question",
|
question: "Some question",
|
||||||
});
|
});
|
||||||
@ -49,14 +56,14 @@ describe("ask-boolean", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("shows notification", () => {
|
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();
|
expect(notification).not.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when user answers "yes"', () => {
|
describe('when user answers "yes"', () => {
|
||||||
beforeEach(() => {
|
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);
|
fireEvent.click(button);
|
||||||
});
|
});
|
||||||
@ -66,7 +73,7 @@ describe("ask-boolean", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not show notification anymore", () => {
|
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();
|
expect(notification).toBeNull();
|
||||||
});
|
});
|
||||||
@ -80,7 +87,7 @@ describe("ask-boolean", () => {
|
|||||||
|
|
||||||
describe('when user answers "no"', () => {
|
describe('when user answers "no"', () => {
|
||||||
beforeEach(() => {
|
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);
|
fireEvent.click(button);
|
||||||
});
|
});
|
||||||
@ -90,7 +97,7 @@ describe("ask-boolean", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not show notification anymore", () => {
|
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();
|
expect(notification).toBeNull();
|
||||||
});
|
});
|
||||||
@ -104,7 +111,7 @@ describe("ask-boolean", () => {
|
|||||||
|
|
||||||
describe("when user closes notification without answering the question", () => {
|
describe("when user closes notification without answering the question", () => {
|
||||||
beforeEach(() => {
|
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);
|
fireEvent.click(button);
|
||||||
});
|
});
|
||||||
@ -114,7 +121,7 @@ describe("ask-boolean", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not show notification anymore", () => {
|
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();
|
expect(notification).toBeNull();
|
||||||
});
|
});
|
||||||
@ -133,13 +140,11 @@ describe("ask-boolean", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
firstQuestionPromise = askBoolean({
|
firstQuestionPromise = askBoolean({
|
||||||
id: "some-question-id",
|
|
||||||
title: "some-title",
|
title: "some-title",
|
||||||
question: "Some question",
|
question: "Some question",
|
||||||
});
|
});
|
||||||
|
|
||||||
secondQuestionPromise = askBoolean({
|
secondQuestionPromise = askBoolean({
|
||||||
id: "some-other-question-id",
|
|
||||||
title: "some-other-title",
|
title: "some-other-title",
|
||||||
question: "Some other question",
|
question: "Some other question",
|
||||||
});
|
});
|
||||||
@ -150,20 +155,20 @@ describe("ask-boolean", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("shows notification for first question", () => {
|
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();
|
expect(notification).not.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows notification for second question", () => {
|
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();
|
expect(notification).not.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when answering to first question", () => {
|
describe("when answering to first question", () => {
|
||||||
beforeEach(() => {
|
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);
|
fireEvent.click(button);
|
||||||
});
|
});
|
||||||
@ -173,13 +178,13 @@ describe("ask-boolean", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not show notification for first question anymore", () => {
|
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();
|
expect(notification).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("still shows notification for second question", () => {
|
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();
|
expect(notification).not.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user