mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix test
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ab60f62f01
commit
b9effeb740
@ -25,9 +25,11 @@ import { Pod } from "../../../../common/k8s-api/endpoints";
|
|||||||
import { ThemeStore } from "../../../theme.store";
|
import { ThemeStore } from "../../../theme.store";
|
||||||
import { dockStore } from "../dock.store";
|
import { dockStore } from "../dock.store";
|
||||||
import { logTabStore } from "../log-tab.store";
|
import { logTabStore } from "../log-tab.store";
|
||||||
import { TerminalStore } from "../terminal.store";
|
|
||||||
import { deploymentPod1, deploymentPod2, deploymentPod3, dockerPod } from "./pod.mock";
|
import { deploymentPod1, deploymentPod2, deploymentPod3, dockerPod } from "./pod.mock";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
|
import { mockWindow } from "../../../../../__mocks__/windowMock";
|
||||||
|
|
||||||
|
mockWindow();
|
||||||
|
|
||||||
jest.mock("react-monaco-editor", () => null);
|
jest.mock("react-monaco-editor", () => null);
|
||||||
|
|
||||||
@ -45,7 +47,6 @@ describe("log tab store", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
UserStore.createInstance();
|
UserStore.createInstance();
|
||||||
ThemeStore.createInstance();
|
ThemeStore.createInstance();
|
||||||
TerminalStore.createInstance();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -53,7 +54,6 @@ describe("log tab store", () => {
|
|||||||
dockStore.reset();
|
dockStore.reset();
|
||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
ThemeStore.resetInstance();
|
ThemeStore.resetInstance();
|
||||||
TerminalStore.resetInstance();
|
|
||||||
fse.remove("tmp");
|
fse.remove("tmp");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -135,18 +135,19 @@ describe("log tab store", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: this is failed when it's not .only == depends on something above
|
// FIXME: this is failed when it's not .only == depends on something above
|
||||||
it.only("closes tab if no pods left in store", () => {
|
it.only("closes tab if no pods left in store", async () => {
|
||||||
const selectedPod = new Pod(deploymentPod1);
|
const selectedPod = new Pod(deploymentPod1);
|
||||||
const selectedContainer = selectedPod.getInitContainers()[0];
|
const selectedContainer = selectedPod.getInitContainers()[0];
|
||||||
|
|
||||||
logTabStore.createPodTab({
|
const id = logTabStore.createPodTab({
|
||||||
selectedPod,
|
selectedPod,
|
||||||
selectedContainer
|
selectedContainer
|
||||||
});
|
});
|
||||||
|
|
||||||
podsStore.items.clear();
|
podsStore.items.clear();
|
||||||
|
|
||||||
expect(logTabStore.getData(dockStore.selectedTabId)).toBeUndefined();
|
expect(logTabStore.getData(dockStore.selectedTabId)).toBeUndefined();
|
||||||
expect(dockStore.getTabById(dockStore.selectedTabId)).toBeUndefined();
|
expect(logTabStore.getData(id)).toBeUndefined();
|
||||||
|
expect(dockStore.getTabById(id)).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
import { action, computed, IReactionOptions, makeObservable, observable, reaction } from "mobx";
|
import { action, computed, IReactionOptions, makeObservable, observable, reaction } from "mobx";
|
||||||
import { autoBind, createStorage } from "../../utils";
|
import { autoBind, createStorage, toJS } from "../../utils";
|
||||||
import throttle from "lodash/throttle";
|
import throttle from "lodash/throttle";
|
||||||
import {monacoModelsManager} from "./monaco-model-manager";
|
import {monacoModelsManager} from "./monaco-model-manager";
|
||||||
|
|
||||||
@ -311,6 +311,8 @@ export class DockStore implements DockStorageState {
|
|||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(tabId, toJS(this.tabs));
|
||||||
}
|
}
|
||||||
|
|
||||||
closeTabs(tabs: DockTab[]) {
|
closeTabs(tabs: DockTab[]) {
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import uniqueId from "lodash/uniqueId";
|
import uniqueId from "lodash/uniqueId";
|
||||||
import { action, reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
|
|
||||||
import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints";
|
import { IPodContainer, Pod } from "../../../common/k8s-api/endpoints";
|
||||||
@ -55,12 +55,12 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
|||||||
reaction(() => podsStore.items.length, () => this.updateTabsData());
|
reaction(() => podsStore.items.length, () => this.updateTabsData());
|
||||||
}
|
}
|
||||||
|
|
||||||
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): void {
|
createPodTab({ selectedPod, selectedContainer }: PodLogsTabData): string {
|
||||||
const podOwner = selectedPod.getOwnerRefs()[0];
|
const podOwner = selectedPod.getOwnerRefs()[0];
|
||||||
const pods = podsStore.getPodsByOwnerId(podOwner?.uid);
|
const pods = podsStore.getPodsByOwnerId(podOwner?.uid);
|
||||||
const title = `Pod ${selectedPod.getName()}`;
|
const title = `Pod ${selectedPod.getName()}`;
|
||||||
|
|
||||||
this.createLogsTab(title, {
|
return this.createLogsTab(title, {
|
||||||
pods: pods.length ? pods : [selectedPod],
|
pods: pods.length ? pods : [selectedPod],
|
||||||
selectedPod,
|
selectedPod,
|
||||||
selectedContainer
|
selectedContainer
|
||||||
@ -94,9 +94,9 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
|||||||
...tabParams,
|
...tabParams,
|
||||||
kind: TabKind.POD_LOGS,
|
kind: TabKind.POD_LOGS,
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private createLogsTab(title: string, data: LogTabData) {
|
private createLogsTab(title: string, data: LogTabData): string {
|
||||||
const id = uniqueId("log-tab-");
|
const id = uniqueId("log-tab-");
|
||||||
|
|
||||||
this.createDockTab({ id, title });
|
this.createDockTab({ id, title });
|
||||||
@ -105,9 +105,10 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
|||||||
showTimestamps: false,
|
showTimestamps: false,
|
||||||
previous: false
|
previous: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
private updateTabsData() {
|
private updateTabsData() {
|
||||||
for (const [tabId, tabData] of this.data) {
|
for (const [tabId, tabData] of this.data) {
|
||||||
try {
|
try {
|
||||||
@ -134,7 +135,7 @@ export class LogTabStore extends DockTabStore<LogTabData> {
|
|||||||
this.closeTab(tabId);
|
this.closeTab(tabId);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`[LOG-TAB-STORE]: failed to set data for tabId=${tabId} deleting`, error, tabData);
|
logger.error(`[LOG-TAB-STORE]: failed to set data for tabId=${tabId} deleting`, error,);
|
||||||
this.data.delete(tabId);
|
this.data.delete(tabId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user