mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Restructure to monorepo (#6907)
* wip: restructure to monorepo Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor create-release-pr to a package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * build fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * github workflow fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix typo Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add webpack-env types to core Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix github workflows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor/fix integration tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * yarn run dev Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * eslint settings for vscode Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * move templates to right package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * open-lens build fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * integration test fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix nx task dependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use bash shell for unit tests in test workflow Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix test:unit for windows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix win-ca webpack error in open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix win-ca webpack error in open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix build:app on windows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ELECTRON_BUILDER_EXTRA_ARGS Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * sync src/ from master Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove Makefile from core Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
0066ca4ea2
commit
2657df2293
3321 files changed
+28699
-11447
No files matched your search
+115
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import type { FakeExtensionOptions } from "../../renderer/components/test-utils/get-extension-fake";
|
||||
import getRandomIdInjectable from "../../common/utils/get-random-id.injectable";
|
||||
import logErrorInjectable from "../../common/log-error.injectable";
|
||||
|
||||
describe("clicking tray menu item originating from extension", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
let logErrorMock: jest.Mock;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
logErrorMock = jest.fn();
|
||||
|
||||
mainDi.override(logErrorInjectable, () => logErrorMock);
|
||||
mainDi.override(getRandomIdInjectable, () => () => "some-random-id");
|
||||
});
|
||||
|
||||
await builder.render();
|
||||
});
|
||||
|
||||
describe("when extension is enabled", () => {
|
||||
let someExtension: FakeExtensionOptions;
|
||||
let clickMock: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
clickMock = jest.fn();
|
||||
|
||||
someExtension = {
|
||||
id: "some-extension-id",
|
||||
name: "some-extension-name",
|
||||
mainOptions: {
|
||||
trayMenus: [{ label: "some-label", click: clickMock }],
|
||||
},
|
||||
};
|
||||
|
||||
builder.extensions.enable(someExtension);
|
||||
});
|
||||
|
||||
it("when item is clicked, triggers the click handler", () => {
|
||||
builder.tray.click(
|
||||
"some-random-id-tray-menu-item-for-extension-some-extension-name",
|
||||
);
|
||||
|
||||
expect(clickMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("given click handler throws synchronously, when item is clicked", () => {
|
||||
beforeEach(() => {
|
||||
clickMock.mockImplementation(() => {
|
||||
throw new Error("some-error");
|
||||
});
|
||||
|
||||
builder.tray.click(
|
||||
"some-random-id-tray-menu-item-for-extension-some-extension-name",
|
||||
);
|
||||
});
|
||||
|
||||
it("logs the error", () => {
|
||||
expect(logErrorMock).toHaveBeenCalledWith(
|
||||
'[TRAY]: Clicking of tray item "some-random-id" from extension "some-extension-name" failed.',
|
||||
expect.any(Error),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("given click handler rejects asynchronously, when item is clicked", () => {
|
||||
beforeEach(() => {
|
||||
clickMock.mockImplementation(() => Promise.reject("some-rejection"));
|
||||
|
||||
builder.tray.click(
|
||||
"some-random-id-tray-menu-item-for-extension-some-extension-name",
|
||||
);
|
||||
});
|
||||
|
||||
it("logs the error", () => {
|
||||
expect(logErrorMock).toHaveBeenCalledWith(
|
||||
'[TRAY]: Clicking of tray item "some-random-id" from extension "some-extension-name" failed.',
|
||||
"some-rejection",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when extension is disabled", () => {
|
||||
beforeEach(() => {
|
||||
builder.extensions.disable(someExtension);
|
||||
});
|
||||
|
||||
it("does not have the tray menu item from extension", () => {
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-random-id-tray-menu-item-for-extension-some-extension-name",
|
||||
),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
// Note: Motivation here is to make sure that enabling same extension does not throw
|
||||
it("when extension is re-enabled, has the tray menu item from extension", async () => {
|
||||
await builder.extensions.enable(someExtension);
|
||||
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-random-id-tray-menu-item-for-extension-some-extension-name",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,278 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { IObservableArray, IObservableValue } from "mobx";
|
||||
import { computed, runInAction, observable } from "mobx";
|
||||
import type { TrayMenuRegistration } from "../../main/tray/tray-menu-registration";
|
||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
|
||||
describe("preferences: extension adding tray items", () => {
|
||||
describe("when extension with tray items are statically defined", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
let someObservableForVisibility: IObservableValue<boolean>;
|
||||
let someObservableForEnabled: IObservableValue<boolean>;
|
||||
let someObservableLabel: IObservableValue<string>;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
await builder.render();
|
||||
|
||||
builder.preferences.navigate();
|
||||
|
||||
someObservableForVisibility = observable.box(false);
|
||||
someObservableForEnabled = observable.box(false);
|
||||
someObservableLabel = observable.box("Some label");
|
||||
|
||||
const testExtension = {
|
||||
id: "some-extension-id",
|
||||
name: "some-extension",
|
||||
|
||||
mainOptions: {
|
||||
trayMenus: [
|
||||
{
|
||||
id: "some-controlled-visibility",
|
||||
label: "some-controlled-visibility",
|
||||
click: () => {},
|
||||
visible: computed(() => someObservableForVisibility.get()),
|
||||
},
|
||||
|
||||
{
|
||||
id: "some-uncontrolled-visibility",
|
||||
label: "some-uncontrolled-visibility",
|
||||
click: () => {},
|
||||
},
|
||||
|
||||
{
|
||||
id: "some-controlled-enabled",
|
||||
label: "some-controlled-enabled",
|
||||
click: () => {},
|
||||
enabled: computed(() => someObservableForEnabled.get()),
|
||||
},
|
||||
|
||||
{
|
||||
id: "some-uncontrolled-enabled",
|
||||
label: "some-uncontrolled-enabled",
|
||||
click: () => {},
|
||||
},
|
||||
|
||||
{
|
||||
id: "some-statically-enabled",
|
||||
label: "some-statically-enabled",
|
||||
click: () => {},
|
||||
enabled: true,
|
||||
},
|
||||
|
||||
{
|
||||
id: "some-statically-disabled",
|
||||
label: "some-statically-disabled",
|
||||
click: () => {},
|
||||
enabled: false,
|
||||
},
|
||||
|
||||
{
|
||||
id: "some-item-with-controlled-label",
|
||||
label: computed(() => someObservableLabel.get()),
|
||||
click: () => {},
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
builder.extensions.enable(testExtension);
|
||||
});
|
||||
|
||||
describe("given controlled label", () => {
|
||||
it("has the label", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-item-with-controlled-label-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.label).toBe("Some label");
|
||||
});
|
||||
|
||||
it("when label changes, updates the label", () => {
|
||||
runInAction(() => {
|
||||
someObservableLabel.set("Some new label");
|
||||
});
|
||||
|
||||
const item = builder.tray.get(
|
||||
"some-item-with-controlled-label-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.label).toBe("Some new label");
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it("given item is statically disabled, item is disabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-statically-disabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(false);
|
||||
});
|
||||
|
||||
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(() => {
|
||||
someObservableForVisibility.set(true);
|
||||
});
|
||||
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-controlled-visibility-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
|
||||
it("given item does not have enabled status, item is enabled by default", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-uncontrolled-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
describe("given item has controlled enabled status and is disabled", () => {
|
||||
it("is disabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-controlled-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("when item becomes enabled, items is enabled", () => {
|
||||
runInAction(() => {
|
||||
someObservableForEnabled.set(true);
|
||||
});
|
||||
|
||||
const item = builder.tray.get(
|
||||
"some-controlled-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("given item is statically enabled, item is enabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-statically-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("given item is statically disabled, item is disabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-statically-disabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when extension with tray items are dynamically defined", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
let menuItems: IObservableArray<TrayMenuRegistration>;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
await builder.render();
|
||||
|
||||
builder.preferences.navigate();
|
||||
|
||||
menuItems = observable.array([
|
||||
{
|
||||
id: "some-visible",
|
||||
label: "some-visible",
|
||||
click: () => {},
|
||||
visible: computed(() => true),
|
||||
},
|
||||
]);
|
||||
|
||||
const computedTrayMenu = computed(() => menuItems);
|
||||
|
||||
const testExtension = {
|
||||
id: "some-extension-id",
|
||||
name: "some-extension",
|
||||
|
||||
mainOptions: {
|
||||
trayMenus: computedTrayMenu,
|
||||
},
|
||||
};
|
||||
|
||||
builder.extensions.enable(testExtension);
|
||||
});
|
||||
|
||||
it("given item exists, it's shown", () => {
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-visible-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("given item is added, it's shown", async () => {
|
||||
menuItems.push({
|
||||
id: "some-added",
|
||||
label: "some-added",
|
||||
click: () => {},
|
||||
visible: computed(() => true),
|
||||
});
|
||||
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-added-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("given item is removed, it's not shown", async () => {
|
||||
menuItems.replace([]);
|
||||
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-visible-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("given items are removed and one added, it's shown", async () => {
|
||||
menuItems.replace([]);
|
||||
menuItems.push({
|
||||
id: "some-added",
|
||||
label: "some-added",
|
||||
click: () => {},
|
||||
visible: computed(() => true),
|
||||
});
|
||||
|
||||
expect(
|
||||
builder.tray.get(
|
||||
"some-added-tray-menu-item-for-extension-some-extension",
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import getRandomIdInjectable from "../../common/utils/get-random-id.injectable";
|
||||
|
||||
describe("multiple separators originating from extension", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
mainDi.unoverride(getRandomIdInjectable);
|
||||
mainDi.permitSideEffects(getRandomIdInjectable);
|
||||
});
|
||||
|
||||
await builder.render();
|
||||
});
|
||||
|
||||
it("given extension with multiple separators, when extension is enabled, does not throw", () => {
|
||||
const someExtension = {
|
||||
id: "some-extension-id",
|
||||
name: "some-extension",
|
||||
|
||||
mainOptions: {
|
||||
trayMenus: [{ type: "separator" as const }, { type: "separator" as const } ],
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
builder.extensions.enable(someExtension);
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user