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

Fixing linter

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-08-15 15:30:04 +03:00
parent be59c955be
commit 558cef5fea
6 changed files with 56 additions and 40 deletions

View File

@ -15,7 +15,8 @@ import type { ApplicationBuilder } from "../../../test-utils/get-application-bui
import { getApplicationBuilder } from "../../../test-utils/get-application-builder";
import dockStoreInjectable from "../../dock/store.injectable";
import areLogsPresentInjectable from "../are-logs-present.injectable";
import callForLogsInjectable, { CallForLogs } from "../call-for-logs.injectable";
import type { CallForLogs } from "../call-for-logs.injectable";
import callForLogsInjectable from "../call-for-logs.injectable";
import createPodLogsTabInjectable from "../create-pod-logs-tab.injectable";
import getLogTabDataInjectable from "../get-log-tab-data.injectable";
import getLogsWithoutTimestampsInjectable from "../get-logs-without-timestamps.injectable";
@ -125,23 +126,25 @@ describe("download logs options in pod logs dock tab", () => {
describe("when call for logs resolves with logs", () => {
beforeEach(() => {
callForLogsMock.mockResolvedValue("all-logs");
})
});
describe("when selected 'download visible logs'", () => {
beforeEach(() => {
const button = rendered.getByTestId("download-visible-logs");
button.click();
});
it("shows save dialog with proper attributes", () => {
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "some-logs", "text/plain")
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "some-logs", "text/plain");
});
})
});
describe("when selected 'download all logs'", () => {
beforeEach(async () => {
await act(async () => {
const button = rendered.getByTestId("download-all-logs");
button.click();
});
});
@ -149,18 +152,18 @@ describe("download logs options in pod logs dock tab", () => {
it("logs have been called with query", () => {
expect(callForLogsMock).toHaveBeenCalledWith(
{ name: "dockerExporter", namespace: "default" },
{ "previous": true, "timestamps": false }
{ "previous": true, "timestamps": false },
);
})
});
it("shows save dialog with proper attributes", async () => {
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "all-logs", "text/plain")
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "all-logs", "text/plain");
});
it("doesn't block download dropdown for interaction after click", async () => {
expect(rendered.getByTestId("download-logs-dropdown")).not.toHaveAttribute("disabled")
expect(rendered.getByTestId("download-logs-dropdown")).not.toHaveAttribute("disabled");
});
})
});
describe("blocking user interaction after menu item click", () => {
it("block download dropdown for interaction when selected 'download all logs'", async () => {
@ -169,8 +172,8 @@ describe("download logs options in pod logs dock tab", () => {
act(() => downloadMenuItem.click());
await waitFor(() => {
expect(rendered.getByTestId("download-logs-dropdown")).toHaveAttribute("disabled")
})
expect(rendered.getByTestId("download-logs-dropdown")).toHaveAttribute("disabled");
});
});
it("doesn't block dropdown for interaction when selected 'download visible logs'", () => {
@ -178,63 +181,67 @@ describe("download logs options in pod logs dock tab", () => {
act(() => downloadMenuItem.click());
expect(rendered.getByTestId("download-logs-dropdown")).not.toHaveAttribute("disabled")
})
})
})
expect(rendered.getByTestId("download-logs-dropdown")).not.toHaveAttribute("disabled");
});
});
});
describe("when call for logs resolves with no logs", () => {
beforeEach(() => {
callForLogsMock.mockResolvedValue("");
})
});
describe("when selected 'download visible logs'", () => {
beforeEach(() => {
const button = rendered.getByTestId("download-visible-logs");
button.click();
});
it("shows save dialog with proper attributes", () => {
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "some-logs", "text/plain")
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "some-logs", "text/plain");
});
})
});
describe("when selected 'download all logs'", () => {
beforeEach(async () => {
await act(async () => {
const button = rendered.getByTestId("download-all-logs");
button.click();
});
});
it("doesn't show save dialog", async () => {
expect(openSaveFileDialogMock).not.toHaveBeenCalled()
expect(openSaveFileDialogMock).not.toHaveBeenCalled();
});
})
})
});
});
describe("when call for logs rejects", () => {
beforeEach(() => {
callForLogsMock.mockRejectedValue("error");
})
});
describe("when selected 'download visible logs'", () => {
beforeEach(async () => {
await act(async () => {
const button = rendered.getByTestId("download-visible-logs");
button.click();
});
});
it("shows save dialog with proper attributes", () => {
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "some-logs", "text/plain")
expect(openSaveFileDialogMock).toHaveBeenCalledWith("dockerExporter.log", "some-logs", "text/plain");
});
})
});
describe("when selected 'download all logs'", () => {
beforeEach(async () => {
await act(async () => {
const button = rendered.getByTestId("download-all-logs");
button.click();
});
});
@ -242,15 +249,15 @@ describe("download logs options in pod logs dock tab", () => {
it("logs have been called", () => {
expect(callForLogsMock).toHaveBeenCalledWith(
{ name: "dockerExporter", namespace: "default" },
{ "previous": true, "timestamps": false }
{ "previous": true, "timestamps": false },
);
})
});
it("doesn't show save dialog", async () => {
expect(openSaveFileDialogMock).not.toHaveBeenCalled()
expect(openSaveFileDialogMock).not.toHaveBeenCalled();
});
})
})
});
});
});
});
});

View File

@ -1,3 +1,7 @@
/**
* 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 type { PodLogsQuery } from "../../../../common/k8s-api/endpoints";
import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api";
@ -10,19 +14,19 @@ const downloadAllLogsInjectable = getInjectable({
instantiate: (di) => {
const callForLogs = di.inject(callForLogsInjectable);
const openSaveFileDialog = di.inject(openSaveFileDialogInjectable)
const openSaveFileDialog = di.inject(openSaveFileDialogInjectable);
const logger = di.inject(loggerInjectable);
return async (params: ResourceDescriptor, query: PodLogsQuery) => {
const logs = await callForLogs(params, query).catch(error => {
logger.error("Can't download logs: ", error);
})
});
if (logs) {
openSaveFileDialog(`${params.name}.log`, logs, "text/plain");
}
}
};
},
});
export default downloadAllLogsInjectable;
export default downloadAllLogsInjectable;

View File

@ -26,7 +26,7 @@ export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs }: D
} finally {
setWaiting(false);
}
}
};
return (
<Dropdown

View File

@ -1,3 +1,7 @@
/**
* 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 openSaveFileDialogInjectable from "../../../utils/save-file.injectable";
@ -5,12 +9,12 @@ const downloadLogsInjectable = getInjectable({
id: "download-logs",
instantiate: (di) => {
const openSaveFileDialog = di.inject(openSaveFileDialogInjectable)
const openSaveFileDialog = di.inject(openSaveFileDialogInjectable);
return (filename: string, logs: string[]) => {
openSaveFileDialog(filename, logs.join("\n"), "text/plain");
}
};
},
});
export default downloadLogsInjectable;
export default downloadLogsInjectable;

View File

@ -101,11 +101,11 @@ export class LogTabViewModel {
if (pod && tabData) {
const params = { name: pod.getName(), namespace: pod.getNs() };
const query = { timestamps: tabData.showTimestamps, previous: tabData.showPrevious }
const query = { timestamps: tabData.showTimestamps, previous: tabData.showPrevious };
return this.dependencies.downloadAllLogs(params, query);
}
return;
}
};
}

View File

@ -3,7 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import React, { HTMLAttributes, useState } from "react";
import type { HTMLAttributes } from "react";
import React, { useState } from "react";
import { Menu } from "../menu";
interface DropdownProps extends HTMLAttributes<HTMLDivElement> {