mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix extensions using "application" as magic string for preference tab (#6666)
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
439881783f
commit
1e0094bd8e
File diff suppressed because it is too large
Load Diff
@ -2,12 +2,14 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import navigateToProxyPreferencesInjectable from "./common/navigate-to-proxy-preferences.injectable";
|
||||
import type { Discover } from "../../renderer/components/test-utils/discovery-of-html-elements";
|
||||
import { discoverFor } from "../../renderer/components/test-utils/discovery-of-html-elements";
|
||||
import type { FakeExtensionOptions } from "../../renderer/components/test-utils/get-extension-fake";
|
||||
|
||||
describe("preferences - navigation to application preferences", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
@ -16,6 +18,53 @@ describe("preferences - navigation to application preferences", () => {
|
||||
builder = getApplicationBuilder();
|
||||
});
|
||||
|
||||
describe("given in preferences, when rendered", () => {
|
||||
let rendered: RenderResult;
|
||||
let discover: Discover;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder.beforeWindowStart(() => {
|
||||
builder.preferences.navigate();
|
||||
});
|
||||
|
||||
rendered = await builder.render();
|
||||
|
||||
discover = discoverFor(() => rendered);
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(rendered.container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("shows application preferences", () => {
|
||||
const { discovered } = discover.querySingleElement(
|
||||
"preference-page",
|
||||
"application-page",
|
||||
);
|
||||
|
||||
expect(discovered).not.toBeNull();
|
||||
});
|
||||
|
||||
describe("when extension with application preference items gets enabled", () => {
|
||||
beforeEach(() => {
|
||||
builder.extensions.enable(
|
||||
extensionStubWithApplicationPreferenceItems,
|
||||
);
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(rendered.container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("shows preference items of the extension", () => {
|
||||
const { attributeValues } =
|
||||
discover.queryAllElements("preference-item");
|
||||
|
||||
expect(attributeValues).toContain("preference-item-for-extension-some-test-extension-name-item-some-application-preference-item-id");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("given in some child page of preferences, when rendered", () => {
|
||||
let rendered: RenderResult;
|
||||
let discover: Discover;
|
||||
@ -85,3 +134,22 @@ describe("preferences - navigation to application preferences", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const extensionStubWithApplicationPreferenceItems: FakeExtensionOptions = {
|
||||
id: "some-test-extension-id",
|
||||
name: "some-test-extension-name",
|
||||
|
||||
rendererOptions: {
|
||||
appPreferences: [
|
||||
{
|
||||
title: "Some application-preference item",
|
||||
id: "some-application-preference-item-id",
|
||||
showInPreferencesTab: "application",
|
||||
|
||||
components: {
|
||||
Hint: () => <div data-testid="some-preference-item-hint" />,
|
||||
Input: () => <div data-testid="some-preference-item-input" />,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@ -120,10 +120,10 @@ const registratorForPreferenceItemsInjectable = getInjectable({
|
||||
kind: "block" as const,
|
||||
id: itemId,
|
||||
|
||||
// Note: Legacy extensions considered telemetry as magic string, and so does this code
|
||||
// Note: Legacy extensions considered telemetry and application as magic strings, and so does this code
|
||||
parentId: registration.showInPreferencesTab
|
||||
? registration.showInPreferencesTab === "telemetry"
|
||||
? "telemetry-page"
|
||||
? ["telemetry", "application"].includes(registration.showInPreferencesTab)
|
||||
? `${registration.showInPreferencesTab}-page`
|
||||
: `${commonId}-additional-page-${registration.showInPreferencesTab}`
|
||||
: primaryPageId,
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user