mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Replace factory function with transient dependency
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
b1c3a59709
commit
5567b0df30
@ -20,6 +20,7 @@ import callForLogsInjectable from "../call-for-logs.injectable";
|
|||||||
import { LogTabViewModel, LogTabViewModelDependencies } from "../logs-view-model";
|
import { LogTabViewModel, LogTabViewModelDependencies } from "../logs-view-model";
|
||||||
import type { TabId } from "../../dock/store";
|
import type { TabId } from "../../dock/store";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { SearchStore } from "../../../../search-store/search-store";
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
@ -50,7 +51,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependen
|
|||||||
stopLoadingLogs: jest.fn(),
|
stopLoadingLogs: jest.fn(),
|
||||||
getPodById: jest.fn(),
|
getPodById: jest.fn(),
|
||||||
getPodsByOwnerId: jest.fn(),
|
getPodsByOwnerId: jest.fn(),
|
||||||
createSearchStore: jest.fn(),
|
searchStore: new SearchStore(),
|
||||||
areLogsPresent: jest.fn(),
|
areLogsPresent: jest.fn(),
|
||||||
...deps,
|
...deps,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,7 +30,7 @@ function mockLogTabViewModel(tabId: TabId, deps: Partial<LogTabViewModelDependen
|
|||||||
getPodById: jest.fn(),
|
getPodById: jest.fn(),
|
||||||
getPodsByOwnerId: jest.fn(),
|
getPodsByOwnerId: jest.fn(),
|
||||||
areLogsPresent: jest.fn(),
|
areLogsPresent: jest.fn(),
|
||||||
createSearchStore: () => new SearchStore(),
|
searchStore: new SearchStore(),
|
||||||
...deps,
|
...deps,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,9 +14,9 @@ import loadLogsInjectable from "./load-logs.injectable";
|
|||||||
import setLogTabDataInjectable from "./set-log-tab-data.injectable";
|
import setLogTabDataInjectable from "./set-log-tab-data.injectable";
|
||||||
import stopLoadingLogsInjectable from "./stop-loading-logs.injectable";
|
import stopLoadingLogsInjectable from "./stop-loading-logs.injectable";
|
||||||
import { podsStore } from "../../+workloads-pods/pods.store";
|
import { podsStore } from "../../+workloads-pods/pods.store";
|
||||||
import createSearchStoreInjectable from "../../../search-store/create-search-store.injectable";
|
|
||||||
import renameTabInjectable from "../dock/rename-tab.injectable";
|
import renameTabInjectable from "../dock/rename-tab.injectable";
|
||||||
import areLogsPresentInjectable from "./are-logs-present.injectable";
|
import areLogsPresentInjectable from "./are-logs-present.injectable";
|
||||||
|
import searchStoreInjectable from "../../../search-store/search-store.injectable";
|
||||||
|
|
||||||
export interface InstantiateArgs {
|
export interface InstantiateArgs {
|
||||||
tabId: TabId;
|
tabId: TabId;
|
||||||
@ -36,7 +36,7 @@ const logsViewModelInjectable = getInjectable({
|
|||||||
areLogsPresent: di.inject(areLogsPresentInjectable),
|
areLogsPresent: di.inject(areLogsPresentInjectable),
|
||||||
getPodById: id => podsStore.getById(id),
|
getPodById: id => podsStore.getById(id),
|
||||||
getPodsByOwnerId: id => podsStore.getPodsByOwnerId(id),
|
getPodsByOwnerId: id => podsStore.getPodsByOwnerId(id),
|
||||||
createSearchStore: di.inject(createSearchStoreInjectable),
|
searchStore: di.inject(searchStoreInjectable),
|
||||||
}),
|
}),
|
||||||
lifecycle: lifecycleEnum.transient,
|
lifecycle: lifecycleEnum.transient,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,12 +21,16 @@ export interface LogTabViewModelDependencies {
|
|||||||
getPodById: (id: string) => Pod | undefined;
|
getPodById: (id: string) => Pod | undefined;
|
||||||
getPodsByOwnerId: (id: string) => Pod[];
|
getPodsByOwnerId: (id: string) => Pod[];
|
||||||
areLogsPresent: (tabId: TabId) => boolean;
|
areLogsPresent: (tabId: TabId) => boolean;
|
||||||
createSearchStore: () => SearchStore;
|
searchStore: SearchStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LogTabViewModel {
|
export class LogTabViewModel {
|
||||||
constructor(protected readonly tabId: TabId, private readonly dependencies: LogTabViewModelDependencies) {}
|
constructor(protected readonly tabId: TabId, private readonly dependencies: LogTabViewModelDependencies) {}
|
||||||
|
|
||||||
|
get searchStore() {
|
||||||
|
return this.dependencies.searchStore;
|
||||||
|
}
|
||||||
|
|
||||||
readonly isLoading = computed(() => this.dependencies.areLogsPresent(this.tabId));
|
readonly isLoading = computed(() => this.dependencies.areLogsPresent(this.tabId));
|
||||||
readonly logs = computed(() => this.dependencies.getLogs(this.tabId));
|
readonly logs = computed(() => this.dependencies.getLogs(this.tabId));
|
||||||
readonly logsWithoutTimestamps = computed(() => this.dependencies.getLogsWithoutTimestamps(this.tabId));
|
readonly logsWithoutTimestamps = computed(() => this.dependencies.getLogsWithoutTimestamps(this.tabId));
|
||||||
@ -54,7 +58,6 @@ export class LogTabViewModel {
|
|||||||
|
|
||||||
return this.dependencies.getPodById(data.selectedPodId);
|
return this.dependencies.getPodById(data.selectedPodId);
|
||||||
});
|
});
|
||||||
readonly searchStore = this.dependencies.createSearchStore();
|
|
||||||
|
|
||||||
updateLogTabData = (partialData: Partial<LogTabData>) => {
|
updateLogTabData = (partialData: Partial<LogTabData>) => {
|
||||||
this.dependencies.setLogTabData(this.tabId, { ...this.logTabData.get(), ...partialData });
|
this.dependencies.setLogTabData(this.tabId, { ...this.logTabData.get(), ...partialData });
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||||
import { SearchStore } from "./search-store";
|
import { SearchStore } from "./search-store";
|
||||||
|
|
||||||
const createSearchStoreInjectable = getInjectable({
|
const searchStoreInjectable = getInjectable({
|
||||||
instantiate: () => () => new SearchStore(),
|
instantiate: () => new SearchStore(),
|
||||||
lifecycle: lifecycleEnum.singleton,
|
lifecycle: lifecycleEnum.transient,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default createSearchStoreInjectable;
|
export default searchStoreInjectable;
|
||||||
@ -9,6 +9,7 @@ import { stdout, stderr } from "process";
|
|||||||
import { getDiForUnitTesting } from "../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../getDiForUnitTesting";
|
||||||
import directoryForUserDataInjectable
|
import directoryForUserDataInjectable
|
||||||
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
from "../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import searchStoreInjectable from "./search-store.injectable";
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
@ -34,7 +35,7 @@ describe("search store tests", () => {
|
|||||||
|
|
||||||
await di.runSetups();
|
await di.runSetups();
|
||||||
|
|
||||||
searchStore = new SearchStore();
|
searchStore = di.inject(searchStoreInjectable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does nothing with empty search query", () => {
|
it("does nothing with empty search query", () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user