mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
62b381e33b
commit
0e1911cc9d
10 files changed
+88
-28
No files matched your search
@@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import { catalogEntity } from "../../main/catalog-sources/general";
|
|
||||||
import { ClusterStore } from "../cluster-store";
|
import { ClusterStore } from "../cluster-store";
|
||||||
import { HotbarStore } from "../hotbar-store";
|
import { HotbarStore } from "../hotbar-store";
|
||||||
|
|
||||||
@@ -41,7 +40,13 @@ jest.mock("../../main/catalog/catalog-entity-registry", () => ({
|
|||||||
source: "remote"
|
source: "remote"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
catalogEntity,
|
{
|
||||||
|
metadata: {
|
||||||
|
uid: "catalog-entity",
|
||||||
|
name: "Catalog",
|
||||||
|
source: "app"
|
||||||
|
},
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
+18
-18
@@ -72,24 +72,6 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
|||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
fileNameMigration();
|
fileNameMigration();
|
||||||
this.load();
|
this.load();
|
||||||
|
|
||||||
if (app) {
|
|
||||||
// track telemetry availability
|
|
||||||
reaction(() => this.allowTelemetry, allowed => {
|
|
||||||
appEventBus.emit({ name: "telemetry", action: allowed ? "enabled" : "disabled" });
|
|
||||||
});
|
|
||||||
|
|
||||||
// open at system start-up
|
|
||||||
reaction(() => this.openAtLogin, openAtLogin => {
|
|
||||||
app.setLoginItemSettings({
|
|
||||||
openAtLogin,
|
|
||||||
openAsHidden: true,
|
|
||||||
args: ["--hidden"]
|
|
||||||
});
|
|
||||||
}, {
|
|
||||||
fireImmediately: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable lastSeenAppVersion = "0.0.0";
|
@observable lastSeenAppVersion = "0.0.0";
|
||||||
@@ -130,6 +112,24 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
|||||||
return this.shell || process.env.SHELL || process.env.PTYSHELL;
|
return this.shell || process.env.SHELL || process.env.PTYSHELL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startMainReactions() {
|
||||||
|
// track telemetry availability
|
||||||
|
reaction(() => this.allowTelemetry, allowed => {
|
||||||
|
appEventBus.emit({ name: "telemetry", action: allowed ? "enabled" : "disabled" });
|
||||||
|
});
|
||||||
|
|
||||||
|
// open at system start-up
|
||||||
|
reaction(() => this.openAtLogin, openAtLogin => {
|
||||||
|
app.setLoginItemSettings({
|
||||||
|
openAtLogin,
|
||||||
|
openAsHidden: true,
|
||||||
|
args: ["--hidden"]
|
||||||
|
});
|
||||||
|
}, {
|
||||||
|
fireImmediately: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a column (by ID) for a table (by ID) is configured to be hidden
|
* Checks if a column (by ID) for a table (by ID) is configured to be hidden
|
||||||
* @param tableId The ID of the table to be checked against
|
* @param tableId The ID of the table to be checked against
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ jest.mock("../extension-installer", () => ({
|
|||||||
installPackage: jest.fn()
|
installPackage: jest.fn()
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
jest.mock("electron", () => ({
|
||||||
|
app: {
|
||||||
|
getPath: () => "tmp",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
console = new Console(process.stdout, process.stderr); // fix mockFS
|
console = new Console(process.stdout, process.stderr); // fix mockFS
|
||||||
const mockedWatch = watch as jest.MockedFunction<typeof watch>;
|
const mockedWatch = watch as jest.MockedFunction<typeof watch>;
|
||||||
|
|||||||
@@ -22,6 +22,14 @@
|
|||||||
import { UserStore } from "../../common/user-store";
|
import { UserStore } from "../../common/user-store";
|
||||||
import { ContextHandler } from "../context-handler";
|
import { ContextHandler } from "../context-handler";
|
||||||
import { PrometheusProvider, PrometheusProviderRegistry, PrometheusService } from "../prometheus";
|
import { PrometheusProvider, PrometheusProviderRegistry, PrometheusService } from "../prometheus";
|
||||||
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
|
jest.mock("electron", () => ({
|
||||||
|
app: {
|
||||||
|
getPath: () => "tmp",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
enum ServiceResult {
|
enum ServiceResult {
|
||||||
Success,
|
Success,
|
||||||
@@ -70,6 +78,10 @@ function getHandler() {
|
|||||||
|
|
||||||
describe("ContextHandler", () => {
|
describe("ContextHandler", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockFs({
|
||||||
|
"tmp": {}
|
||||||
|
});
|
||||||
|
|
||||||
PrometheusProviderRegistry.createInstance();
|
PrometheusProviderRegistry.createInstance();
|
||||||
UserStore.createInstance();
|
UserStore.createInstance();
|
||||||
});
|
});
|
||||||
@@ -77,6 +89,7 @@ describe("ContextHandler", () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
PrometheusProviderRegistry.resetInstance();
|
PrometheusProviderRegistry.resetInstance();
|
||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
|
mockFs.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getPrometheusService", () => {
|
describe("getPrometheusService", () => {
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ jest.mock("winston", () => ({
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getPath: () => "/foo",
|
getPath: () => "tmp",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -77,8 +78,6 @@ const mockWaitUntilUsed = waitUntilUsed as jest.MockedFunction<typeof waitUntilU
|
|||||||
describe("kube auth proxy tests", () => {
|
describe("kube auth proxy tests", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
UserStore.resetInstance();
|
|
||||||
UserStore.createInstance();
|
|
||||||
|
|
||||||
const mockMinikubeConfig = {
|
const mockMinikubeConfig = {
|
||||||
"minikube-config.yml": JSON.stringify({
|
"minikube-config.yml": JSON.stringify({
|
||||||
@@ -102,13 +101,16 @@ describe("kube auth proxy tests", () => {
|
|||||||
}],
|
}],
|
||||||
kind: "Config",
|
kind: "Config",
|
||||||
preferences: {},
|
preferences: {},
|
||||||
})
|
}),
|
||||||
|
"tmp": {},
|
||||||
};
|
};
|
||||||
|
|
||||||
mockFs(mockMinikubeConfig);
|
mockFs(mockMinikubeConfig);
|
||||||
|
UserStore.createInstance();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
UserStore.resetInstance();
|
||||||
mockFs.restore();
|
mockFs.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -138,7 +138,7 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
logger.info("💾 Loading stores");
|
logger.info("💾 Loading stores");
|
||||||
|
|
||||||
UserStore.createInstance();
|
UserStore.createInstance().startMainReactions();
|
||||||
ClusterStore.createInstance().provideInitialFromMain();
|
ClusterStore.createInstance().provideInitialFromMain();
|
||||||
HotbarStore.createInstance();
|
HotbarStore.createInstance();
|
||||||
ExtensionsStore.createInstance();
|
ExtensionsStore.createInstance();
|
||||||
|
|||||||
@@ -28,9 +28,17 @@ import { LensExtension } from "../../../extensions/main-api";
|
|||||||
import { ExtensionLoader } from "../../../extensions/extension-loader";
|
import { ExtensionLoader } from "../../../extensions/extension-loader";
|
||||||
import { ExtensionsStore } from "../../../extensions/extensions-store";
|
import { ExtensionsStore } from "../../../extensions/extensions-store";
|
||||||
import { LensProtocolRouterMain } from "../router";
|
import { LensProtocolRouterMain } from "../router";
|
||||||
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
jest.mock("../../../common/ipc");
|
jest.mock("../../../common/ipc");
|
||||||
|
|
||||||
|
jest.mock("electron", () => ({
|
||||||
|
app: {
|
||||||
|
getPath: () => "tmp",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
function throwIfDefined(val: any): void {
|
function throwIfDefined(val: any): void {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
throw val;
|
throw val;
|
||||||
@@ -39,6 +47,9 @@ function throwIfDefined(val: any): void {
|
|||||||
|
|
||||||
describe("protocol router tests", () => {
|
describe("protocol router tests", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockFs({
|
||||||
|
"tmp": {}
|
||||||
|
});
|
||||||
ExtensionsStore.createInstance();
|
ExtensionsStore.createInstance();
|
||||||
ExtensionLoader.createInstance();
|
ExtensionLoader.createInstance();
|
||||||
|
|
||||||
@@ -53,6 +64,7 @@ describe("protocol router tests", () => {
|
|||||||
ExtensionsStore.resetInstance();
|
ExtensionsStore.resetInstance();
|
||||||
ExtensionLoader.resetInstance();
|
ExtensionLoader.resetInstance();
|
||||||
LensProtocolRouterMain.resetInstance();
|
LensProtocolRouterMain.resetInstance();
|
||||||
|
mockFs.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw on non-lens URLS", () => {
|
it("should throw on non-lens URLS", () => {
|
||||||
|
|||||||
@@ -22,8 +22,14 @@
|
|||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { app, remote } from "electron";
|
import { app, remote } from "electron";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { isTestEnv } from "../../common/vars";
|
||||||
|
|
||||||
export function fileNameMigration() {
|
export function fileNameMigration() {
|
||||||
|
if (isTestEnv) {
|
||||||
|
// hack: to make unit testing easier just ignore the following code
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const userDataPath = (app || remote.app).getPath("userData");
|
const userDataPath = (app || remote.app).getPath("userData");
|
||||||
const configJsonPath = path.join(userDataPath, "config.json");
|
const configJsonPath = path.join(userDataPath, "config.json");
|
||||||
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ import type { LogTabData } from "../log-tab.store";
|
|||||||
import { dockerPod, deploymentPod1 } from "./pod.mock";
|
import { dockerPod, deploymentPod1 } from "./pod.mock";
|
||||||
import { ThemeStore } from "../../../theme.store";
|
import { ThemeStore } from "../../../theme.store";
|
||||||
import { UserStore } from "../../../../common/user-store";
|
import { UserStore } from "../../../../common/user-store";
|
||||||
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getPath: () => "/foo",
|
getPath: () => "tmp",
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -71,6 +72,9 @@ const getFewPodsTabData = (): LogTabData => {
|
|||||||
|
|
||||||
describe("<LogResourceSelector />", () => {
|
describe("<LogResourceSelector />", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockFs({
|
||||||
|
"tmp": {}
|
||||||
|
});
|
||||||
UserStore.createInstance();
|
UserStore.createInstance();
|
||||||
ThemeStore.createInstance();
|
ThemeStore.createInstance();
|
||||||
});
|
});
|
||||||
@@ -78,6 +82,7 @@ describe("<LogResourceSelector />", () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
ThemeStore.resetInstance();
|
ThemeStore.resetInstance();
|
||||||
|
mockFs.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders w/o errors", () => {
|
it("renders w/o errors", () => {
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ import React from "react";
|
|||||||
import { ThemeStore } from "../../../theme.store";
|
import { ThemeStore } from "../../../theme.store";
|
||||||
import { UserStore } from "../../../../common/user-store";
|
import { UserStore } from "../../../../common/user-store";
|
||||||
import { Notifications } from "../../notifications";
|
import { Notifications } from "../../notifications";
|
||||||
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
|
jest.mock("electron", () => ({
|
||||||
|
app: {
|
||||||
|
getPath: () => "tmp",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
const mockHotbars: {[id: string]: any} = {
|
const mockHotbars: {[id: string]: any} = {
|
||||||
"1": {
|
"1": {
|
||||||
@@ -48,6 +56,9 @@ jest.mock("../../../../common/hotbar-store", () => ({
|
|||||||
|
|
||||||
describe("<HotbarRemoveCommand />", () => {
|
describe("<HotbarRemoveCommand />", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockFs({
|
||||||
|
"tmp": {}
|
||||||
|
});
|
||||||
UserStore.createInstance();
|
UserStore.createInstance();
|
||||||
ThemeStore.createInstance();
|
ThemeStore.createInstance();
|
||||||
});
|
});
|
||||||
@@ -55,11 +66,12 @@ describe("<HotbarRemoveCommand />", () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
ThemeStore.resetInstance();
|
ThemeStore.resetInstance();
|
||||||
|
mockFs.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders w/o errors", () => {
|
it("renders w/o errors", () => {
|
||||||
const { container } = render(<HotbarRemoveCommand/>);
|
const { container } = render(<HotbarRemoveCommand/>);
|
||||||
|
|
||||||
expect(container).toBeInstanceOf(HTMLElement);
|
expect(container).toBeInstanceOf(HTMLElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,4 +85,3 @@ describe("<HotbarRemoveCommand />", () => {
|
|||||||
spy.mockRestore();
|
spy.mockRestore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Reference in new issue
Block a user