1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Merge branch 'master' into show-extension-preferences-in-separate-page

This commit is contained in:
Alex Andreev 2022-06-17 14:51:39 +03:00
commit 83de4fc7f8
3 changed files with 55 additions and 14 deletions

View File

@ -12,7 +12,6 @@ import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { ElectronWindow, LensWindowConfiguration } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import { flushPromises } from "../../common/test-utils/flush-promises";
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
describe("opening application window using tray", () => {
@ -24,17 +23,28 @@ describe("opening application window using tray", () => {
let callForApplicationWindowHtmlMock: AsyncFnMock<() => void>;
beforeEach(async () => {
callForSplashWindowHtmlMock = asyncFn();
callForApplicationWindowHtmlMock = asyncFn();
applicationBuilder = getApplicationBuilder().beforeApplicationStart(
({ mainDi }) => {
mainDi.override(lensResourcesDirInjectable, () => "some-lens-resources-directory");
const loadFileMock = jest
.fn(callForSplashWindowHtmlMock)
.mockImplementationOnce(() => Promise.resolve());
const loadUrlMock = jest
.fn(callForApplicationWindowHtmlMock)
.mockImplementationOnce(() => Promise.resolve());
createElectronWindowMock = jest.fn((configuration: LensWindowConfiguration) =>
({
splash: {
send: () => {},
close: () => {},
show: () => {},
loadFile: callForSplashWindowHtmlMock,
loadFile: loadFileMock,
loadUrl: () => { throw new Error("Should never come here"); },
},
@ -43,7 +53,7 @@ describe("opening application window using tray", () => {
close: () => {},
show: () => {},
loadFile: () => { throw new Error("Should never come here"); },
loadUrl: callForApplicationWindowHtmlMock,
loadUrl: loadUrlMock,
},
}[configuration.id] as ElectronWindow));
@ -54,20 +64,10 @@ describe("opening application window using tray", () => {
);
expectWindowsToBeOpen = expectWindowsToBeOpenFor(mainDi);
callForSplashWindowHtmlMock = asyncFn();
callForApplicationWindowHtmlMock = asyncFn();
},
);
const renderPromise = applicationBuilder.render();
await flushPromises();
await callForSplashWindowHtmlMock.resolve();
await callForApplicationWindowHtmlMock.resolve();
await renderPromise;
await applicationBuilder.render();
});
it("only an application window is open", () => {

View File

@ -0,0 +1,37 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed, onBecomeObserved, onBecomeUnobserved } from "mobx";
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
import secretStoreInjectable from "../+config-secrets/store.injectable";
const releaseSecretsInjectable = getInjectable({
id: "release-secrets",
instantiate: (di) => {
const subscribeStores = di.inject(subscribeStoresInjectable);
const secretStore = di.inject(secretStoreInjectable);
const releaseSecrets = computed(() =>
secretStore.contextItems.filter((secret) =>
secret.type.startsWith("helm.sh/release"),
),
);
let unsubscribe: () => void;
onBecomeObserved(releaseSecrets, () => {
unsubscribe = subscribeStores([secretStore]);
});
onBecomeUnobserved(releaseSecrets, () => {
unsubscribe?.();
});
return releaseSecrets;
},
});
export default releaseSecretsInjectable;

View File

@ -7,6 +7,7 @@ import { asyncComputed } from "@ogre-tools/injectable-react";
import namespaceStoreInjectable from "../+namespaces/store.injectable";
import { listReleases } from "../../../common/k8s-api/endpoints/helm-releases.api";
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
import releaseSecretsInjectable from "./release-secrets.injectable";
const releasesInjectable = getInjectable({
id: "releases",
@ -14,10 +15,13 @@ const releasesInjectable = getInjectable({
instantiate: (di) => {
const clusterContext = di.inject(clusterFrameContextInjectable);
const namespaceStore = di.inject(namespaceStoreInjectable);
const releaseSecrets = di.inject(releaseSecretsInjectable);
return asyncComputed(async () => {
const contextNamespaces = namespaceStore.contextNamespaces || [];
void releaseSecrets.get();
const isLoadingAll =
clusterContext.allNamespaces?.length > 1 &&
clusterContext.cluster?.accessibleNamespaces.length === 0 &&