From 1af76e1ccf9ffdd4148accee21c73c8dc43df8a8 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 5 Dec 2022 11:11:40 +0300 Subject: [PATCH] Check if .wrap class applied properly Signed-off-by: Alex Andreev --- .../__snapshots__/log-list.test.tsx.snap | 111 ++++++++++++++++ .../dock/logs/__test__/log-list.test.tsx | 125 ++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 src/renderer/components/dock/logs/__test__/__snapshots__/log-list.test.tsx.snap create mode 100644 src/renderer/components/dock/logs/__test__/log-list.test.tsx diff --git a/src/renderer/components/dock/logs/__test__/__snapshots__/log-list.test.tsx.snap b/src/renderer/components/dock/logs/__test__/__snapshots__/log-list.test.tsx.snap new file mode 100644 index 0000000000..c37d126cb3 --- /dev/null +++ b/src/renderer/components/dock/logs/__test__/__snapshots__/log-list.test.tsx.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders logs 1`] = ` +
+
+
+
+
+
+
+ + hello + +
+
+
+
+
+
+
+ + world + +
+
+
+
+
+
+
+
+`; + +exports[` when user selected to wrap log lines renders logs with wrapping 1`] = ` +
+
+
+
+
+
+
+ + hello + +
+
+
+
+
+
+
+ + world + +
+
+
+
+
+
+
+
+`; diff --git a/src/renderer/components/dock/logs/__test__/log-list.test.tsx b/src/renderer/components/dock/logs/__test__/log-list.test.tsx new file mode 100644 index 0000000000..3124550a80 --- /dev/null +++ b/src/renderer/components/dock/logs/__test__/log-list.test.tsx @@ -0,0 +1,125 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import React from "react"; +import { getDiForUnitTesting } from "../../../../getDiForUnitTesting"; +import { SearchStore } from "../../../../search-store/search-store"; +import type { DiRender } from "../../../test-utils/renderFor"; +import { renderFor } from "../../../test-utils/renderFor"; +import type { TabId } from "../../dock/store"; +import { LogList } from "../log-list"; +import type { LogTabViewModelDependencies } from "../logs-view-model"; +import { LogTabViewModel } from "../logs-view-model"; +import type { LogTabData } from "../tab-store"; +import { dockerPod } from "./pod.mock"; + +Object.defineProperty(window, "IntersectionObserver", { + writable: true, + value: jest.fn().mockImplementation(() => ({ + observe: jest.fn(), + disconnect: jest.fn(), + unobserve: jest.fn(), + })), +}); + +function mockLogTabViewModel(tabId: TabId, deps: Partial): LogTabViewModel { + return new LogTabViewModel(tabId, { + getLogs: jest.fn(), + getLogsWithoutTimestamps: jest.fn(), + getVisibleLogs: jest.fn(), + getTimestampSplitLogs: jest.fn(), + getLogTabData: jest.fn(), + setLogTabData: jest.fn(), + loadLogs: jest.fn(), + reloadLogs: jest.fn(), + renameTab: jest.fn(), + stopLoadingLogs: jest.fn(), + getPodById: jest.fn(), + getPodsByOwnerId: jest.fn(), + areLogsPresent: jest.fn(), + searchStore: new SearchStore(), + downloadLogs: jest.fn(), + downloadAllLogs: jest.fn(), + ...deps, + }); +} + +const getOnePodViewModel = (tabId: TabId, deps: Partial = {}, logTabData?: Partial): LogTabViewModel => { + const selectedPod = dockerPod; + + return mockLogTabViewModel(tabId, { + getLogTabData: () => ({ + selectedPodId: selectedPod.getId(), + selectedContainer: selectedPod.getContainers()[0].name, + namespace: selectedPod.getNs(), + showPrevious: false, + showTimestamps: false, + wrap: false, + ...logTabData, + }), + getPodById: (id) => { + if (id === selectedPod.getId()) { + return selectedPod; + } + + return undefined; + }, + ...deps, + }); +}; + +describe("", () => { + let render: DiRender; + + beforeEach(() => { + const di = getDiForUnitTesting({ doGeneralOverrides: true }); + + render = renderFor(di); + }); + + it("renders empty list", () => { + const { container } = render( [], + })} />); + + expect(container.getElementsByClassName(".LogRow")).toHaveLength(0); + }); + + it("renders logs", () => { + const model = getOnePodViewModel("foobar", { + getVisibleLogs: () => [ + "hello", + "world", + ], + }); + + const list = render(); + + expect(list.container).toMatchSnapshot(); + }); + + describe("when user selected to wrap log lines", () => { + const model = getOnePodViewModel("foobar", { + getVisibleLogs: () => [ + "hello", + "world", + ] + }, { + wrap: true, + }); + + it("renders logs with wrapping", () => { + const list = render(); + + expect(list.container).toMatchSnapshot(); + }); + + it("has specific class applied for log row wrappers", () => { + const list = render(); + + expect(list.container.getElementsByClassName("rowWrapper wrap")).toHaveLength(2); + }); + }); +});