Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ export const AppLogsFilter = ({ appId, expandAll, refetchLogs, isLoading, noResu
const refreshLogs = () => {
refetchLogs();
};

const onExportConfirm = (url: string) => {
window.open(url, '_blank', 'noopener noreferrer');
};

const openExportModal = () => {
setModal(<ExportLogsModal onClose={() => setModal(null)} filterValues={getValues()} />);
setModal(<ExportLogsModal onClose={() => setModal(null)} filterValues={getValues()} onConfirm={onExportConfirm} />);
};

const compactMode = useCompactMode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { composeStories } from '@storybook/react';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { axe } from 'jest-axe';

import * as stories from './ExportLogsModal.stories';

const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]);
const onConfirm = jest.fn();
const { Default } = composeStories(stories);

test.each(testCases)(`renders without crashing`, async (_storyname, Story) => {
const view = render(<Story />, {
Expand All @@ -21,3 +24,14 @@ test.each(testCases)('Should have no a11y violations', async (_storyname, Story)

expect(results).toHaveNoViolations();
});

it('should send the correct payload to the endpoint', async () => {
render(<Default onConfirm={onConfirm} />, {
wrapper: mockAppRoot().build(),
});

expect(screen.getByRole('button', { name: 'Download' })).toBeInTheDocument();
await userEvent.click(screen.getByRole('button', { name: 'Download' }));
expect(onConfirm).toHaveBeenCalledTimes(1);
expect(onConfirm).toHaveBeenCalledWith('/api/apps/undefined/export-logs?count=2000&type=json');
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
startDate: '',
endDate: '',
},
onConfirm: () => action('onConfirm'),
},
decorators: [
mockAppRoot().buildStoryDecorator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { AppLogsFilterFormData } from '../useAppLogsFilterForm';
type ExportLogsModalProps = {
onClose: () => void;
filterValues: AppLogsFilterFormData;
onConfirm: (url: string) => void;
};

type FormDataType = {
Expand All @@ -32,7 +33,7 @@ type FormDataType = {
customExportAmount: number;
};

export const ExportLogsModal = ({ onClose, filterValues }: ExportLogsModalProps) => {
export const ExportLogsModal = ({ onClose, filterValues, onConfirm }: ExportLogsModalProps) => {
const { t } = useTranslation();

const appId = useRouteParameter('id');
Expand Down Expand Up @@ -67,7 +68,7 @@ export const ExportLogsModal = ({ onClose, filterValues }: ExportLogsModalProps)
if (severity && severity !== 'all') {
baseUrl += `logLevel=${severity}&`;
}
if (event) {
if (event && event !== 'all') {
baseUrl += `method=${event}&`;
}
if (startDate) {
Expand All @@ -85,7 +86,7 @@ export const ExportLogsModal = ({ onClose, filterValues }: ExportLogsModalProps)

const handleConfirm = (): void => {
const url = getFileUrl({ ...filterValues, type, count: count === 'max' ? 2000 : getValues('customExportAmount') });
window.open(url, '_blank', 'noopener noreferrer');
onConfirm(url);
onClose();
};

Expand Down
Loading