mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Expose a way to control tray item visibility through Extension API
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
6c7c0244a1
commit
5253df0647
78
src/behaviours/tray/extension-adding-tray-items.test.tsx
Normal file
78
src/behaviours/tray/extension-adding-tray-items.test.tsx
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { computed, runInAction, observable } from "mobx";
|
||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getExtensionFakeFor } from "../../renderer/components/test-utils/get-extension-fake";
|
||||
|
||||
describe("preferences: extension adding tray items", () => {
|
||||
describe("when extension with tray items is enabled", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
let someObservable: IObservableValue<boolean>;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
await builder.render();
|
||||
|
||||
builder.preferences.navigate();
|
||||
|
||||
const getExtensionFake = getExtensionFakeFor(builder);
|
||||
|
||||
someObservable = observable.box(false);
|
||||
|
||||
const testExtension = getExtensionFake({
|
||||
id: "some-extension-id",
|
||||
name: "some-extension",
|
||||
|
||||
mainOptions: {
|
||||
trayMenus: [
|
||||
{
|
||||
label: "some-controlled-visibility",
|
||||
click: () => {},
|
||||
visible: computed(() => someObservable.get()),
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-uncontrolled-visibility",
|
||||
click: () => {},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
builder.extensions.enable(testExtension);
|
||||
});
|
||||
|
||||
it("shows item which doesn't control the visibility", () => {
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-uncontrolled-visibility-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("does not show hidden item", () => {
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-controlled-visibility-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("when item becomes visible, shows the item", () => {
|
||||
runInAction(() => {
|
||||
someObservable.set(true);
|
||||
});
|
||||
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-controlled-visibility-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -71,7 +71,14 @@ const toItemInjectablesFor = (extension: LensMainExtension, withErrorLoggingFor:
|
||||
},
|
||||
|
||||
enabled: computed(() => registration.enabled ?? true),
|
||||
visible: computed(() => true),
|
||||
|
||||
visible: computed(() => {
|
||||
if (!registration.visible) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return registration.visible.get();
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: trayMenuItemInjectionToken,
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
export interface TrayMenuRegistration {
|
||||
label?: string;
|
||||
click?: (menuItem: TrayMenuRegistration) => void;
|
||||
@ -11,4 +13,5 @@ export interface TrayMenuRegistration {
|
||||
toolTip?: string;
|
||||
enabled?: boolean;
|
||||
submenu?: TrayMenuRegistration[];
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user