mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactoring dock tab download logs tests (#6149)
* Separate 'download visible' and 'download all' tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Add disabled prop to DownloadLogsDropdown Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Test for dropdown if no logs available in the tab Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix linter Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Remove unused code statement Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Update snapshots Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
1 parent
032e6d968c
commit
0fe3242030
5 files changed
+1016
-172
No files matched your search
@@ -63,6 +63,7 @@ export const LogControls = observer(({ model }: LogControlsProps) => {
|
||||
/>
|
||||
|
||||
<DownloadLogsDropdown
|
||||
disabled={logs.length === 0}
|
||||
downloadVisibleLogs={model.downloadLogs}
|
||||
downloadAllLogs={model.downloadAllLogs}
|
||||
/>
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { PodLogsQuery } from "../../../../common/k8s-api/endpoints";
|
||||
import type { ResourceDescriptor } from "../../../../common/k8s-api/kube-api";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import openSaveFileDialogInjectable from "../../../utils/save-file.injectable";
|
||||
import showErrorNotificationInjectable from "../../notifications/show-error-notification.injectable";
|
||||
import callForLogsInjectable from "./call-for-logs.injectable";
|
||||
|
||||
const downloadAllLogsInjectable = getInjectable({
|
||||
@@ -16,7 +17,8 @@ const downloadAllLogsInjectable = getInjectable({
|
||||
const callForLogs = di.inject(callForLogsInjectable);
|
||||
const openSaveFileDialog = di.inject(openSaveFileDialogInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
|
||||
return async (params: ResourceDescriptor, query: PodLogsQuery) => {
|
||||
const logs = await callForLogs(params, query).catch(error => {
|
||||
logger.error("Can't download logs: ", error);
|
||||
@@ -24,6 +26,8 @@ const downloadAllLogsInjectable = getInjectable({
|
||||
|
||||
if (logs) {
|
||||
openSaveFileDialog(`${params.name}.log`, logs, "text/plain");
|
||||
} else {
|
||||
showErrorNotification("No logs to download");
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
@@ -13,9 +13,10 @@ import { Dropdown } from "../../dropdown/dropdown";
|
||||
interface DownloadLogsDropdownProps {
|
||||
downloadVisibleLogs: () => void;
|
||||
downloadAllLogs: () => Promise<void> | undefined;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs }: DownloadLogsDropdownProps) {
|
||||
export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs, disabled }: DownloadLogsDropdownProps) {
|
||||
const [waiting, setWaiting] = useState(false);
|
||||
|
||||
const downloadAll = async () => {
|
||||
@@ -35,7 +36,7 @@ export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs }: D
|
||||
<button
|
||||
data-testid="download-logs-dropdown"
|
||||
className={styles.dropdown}
|
||||
disabled={waiting}
|
||||
disabled={waiting || disabled}
|
||||
>
|
||||
Download
|
||||
<Icon material="arrow_drop_down" smallest/>
|
||||
|
||||
Reference in new issue
Block a user