Merge branch 'master' into feature/ingress_class_api_view

This commit is contained in:
Roman committed 2022-12-29 12:38:16 +02:00
commit 87c932f2e5
7 files changed
+191 -40

No files matched your search

@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { withInjectables } from "@ogre-tools/injectable-react";
import { action, computed, makeObservable, observable, reaction } from "mobx";
import { computed, makeObservable, observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import React from "react";
import { Notice } from "../../../../../../renderer/components/+extensions/notice";
@@ -59,11 +59,7 @@ class NonInjectedKubeconfigSync extends React.Component<Dependencies> {
reaction(
() => Array.from(this.syncs.entries(), ([filePath, kind]) => tuple.from(filePath, kind)),
syncs => {
action(() => {
for (const [path] of syncs) {
this.props.userStore.syncKubeconfigEntries.set(path, {});
}
});
this.props.userStore.syncKubeconfigEntries.replace(syncs);
},
),
]);
@@ -6,16 +6,22 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { SendMessageToChannel } from "../../../common/utils/channel/message-to-channel-injection-token";
import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
import getVisibleWindowsInjectable from "../../start-main-application/lens-window/get-visible-windows.injectable";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
const messageToChannelInjectable = getInjectable({
id: "message-to-channel",
instantiate: (di) => {
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
const clusterFrames = di.inject(clusterFramesInjectable);
return ((channel, data) => {
for (const window of getVisibleWindows()) {
window.send({ channel: channel.id, data });
clusterFrames.forEach(frameInfo => {
window.send({ channel: channel.id, data, frameInfo });
});
}
}) as SendMessageToChannel;
},
@@ -0,0 +1,115 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getDiForUnitTesting } from "../../getDiForUnitTesting";
import getVisibleWindowsInjectable from "../../start-main-application/lens-window/get-visible-windows.injectable";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token";
import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
import type { DiContainer } from "@ogre-tools/injectable";
import type { ClusterFrameInfo } from "../../../common/cluster-frames";
describe("message-to-channel", () => {
let di: DiContainer;
let sendToWindowMock: jest.Mock;
beforeEach(() => {
di = getDiForUnitTesting({ doGeneralOverrides: true });
sendToWindowMock = jest.fn();
di.override(getVisibleWindowsInjectable, () => () => [
{
id: "some-window",
send: sendToWindowMock,
show: () => {},
reload: () => {},
isStarting: false,
start: async () => {},
close: () => {},
isVisible: true,
},
{
id: "some-other-window",
send: sendToWindowMock,
show: () => {},
reload: () => {},
isStarting: false,
start: async () => {},
close: () => {},
isVisible: true,
},
]);
di.override(
clusterFramesInjectable,
() =>
new Map<string, ClusterFrameInfo>([
[
"some-cluster-id",
{ frameId: 42, processId: 84 },
],
[
"some-other-cluster-id",
{ frameId: 126, processId: 168 },
],
]),
);
});
describe("when sending message", () => {
beforeEach(() => {
const sendMessageToChannel = di.inject(
sendMessageToChannelInjectionToken,
);
sendMessageToChannel(someChannel, 42);
});
it("sends to each window and cluster frames", () => {
expect(sendToWindowMock.mock.calls).toEqual([
[{ channel: "some-channel-id", data: 42 }],
[
{
channel: "some-channel-id",
data: 42,
frameInfo: { frameId: 42, processId: 84 },
},
],
[
{
channel: "some-channel-id",
data: 42,
frameInfo: { frameId: 126, processId: 168 },
},
],
[{ channel: "some-channel-id", data: 42 }],
[
{
channel: "some-channel-id",
data: 42,
frameInfo: { frameId: 42, processId: 84 },
},
],
[
{
channel: "some-channel-id",
data: 42,
frameInfo: { frameId: 126, processId: 168 },
},
],
]);
});
});
});
const someChannel: MessageChannel<number> = {
id: "some-channel-id",
};