1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/features/command-pallet/keyboard-shortcuts.test.tsx
Janne Savolainen 32a08d65aa
Rename old directory for behaviours as "features" to better communicate new intent with new directory structure to organize code and tests around features instead of technicalities
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-08-16 15:07:00 +03:00

149 lines
4.0 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { RenderResult } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import platformInjectable from "../../common/vars/platform.injectable";
import { type ApplicationBuilder, getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
describe("Command Pallet: keyboard shortcut tests", () => {
let applicationBuilder: ApplicationBuilder;
let rendered: RenderResult;
beforeEach(async () => {
applicationBuilder = getApplicationBuilder();
});
describe("when on macOS", () => {
beforeEach(async () => {
applicationBuilder.dis.rendererDi.override(platformInjectable, () => "darwin");
rendered = await applicationBuilder.render();
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not show the command pallet yet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeNull();
});
describe("when pressing ESC", () => {
beforeEach(() => {
userEvent.keyboard("{Escape}");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not show the command pallet yet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeNull();
});
});
describe("when pressing SHIFT+CMD+P", () => {
beforeEach(() => {
userEvent.keyboard("{Shift>}{Meta>}P{/Meta}{/Shift}");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("shows the command pallet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeInTheDocument();
});
describe("when pressing ESC", () => {
beforeEach(() => {
userEvent.keyboard("{Escape}");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("no longer shows the command pallet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeNull();
});
});
});
});
describe("when on linux", () => {
beforeEach(async () => {
applicationBuilder.dis.rendererDi.override(platformInjectable, () => "linux");
rendered = await applicationBuilder.render();
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not show the command pallet yet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeNull();
});
describe("when pressing ESC", () => {
beforeEach(() => {
userEvent.keyboard("{Escape}");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("does not show the command pallet yet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeNull();
});
});
describe("when pressing SHIFT+CTRL+P", () => {
beforeEach(() => {
userEvent.keyboard("{Shift>}{Control>}P{/Control}{/Shift}");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("shows the command pallet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeInTheDocument();
});
describe("when pressing ESC", () => {
beforeEach(() => {
userEvent.keyboard("{Escape}");
});
it("renders", () => {
expect(rendered.baseElement).toMatchSnapshot();
});
it("no longer shows the command pallet", () => {
const actual = rendered.queryByTestId("command-container");
expect(actual).toBeNull();
});
});
});
});
});