feat: clean frontend test logs (#1894)

This commit is contained in:
Chaim Lev-Ari
2026-02-22 07:42:49 +00:00
committed by GitHub
parent caf6b2aa0c
commit 2bbcae39b6
13 changed files with 141 additions and 30 deletions
@@ -7,6 +7,7 @@ import { ComponentProps } from 'react';
import { server } from '@/setup-tests/server';
import { withTestQueryProvider } from '@/react/test-utils/withTestQuery';
import { withUserProvider } from '@/react/test-utils/withUserProvider';
import { suppressConsoleLogs } from '@/setup-tests/suppress-console';
import { createMockUsers, createMockStack } from '@/react-tools/test-mocks';
import { EnvironmentType } from '@/react/portainer/environments/types';
import { Role } from '@/portainer/users/types';
@@ -69,6 +70,7 @@ beforeEach(() => {
describe('initial loading', () => {
it('should be empty when environment data is not loaded', async () => {
const restoreConsole = suppressConsoleLogs();
setupMswHandlers({ shouldReturnEnv: false });
const { container } = renderComponent();
@@ -77,6 +79,8 @@ describe('initial loading', () => {
await waitFor(() => {
expect(container.innerHTML).toBe('<div></div>');
});
restoreConsole();
});
it('should be empty when schema data is not loaded', async () => {
@@ -141,6 +145,8 @@ describe('initial loading', () => {
describe('form submission', () => {
it('should show confirmation dialog before submitting', async () => {
const restoreConsole = suppressConsoleLogs();
const mockConfirm = vi.mocked(confirmStackUpdate);
renderComponent();
const user = userEvent.setup();
@@ -162,9 +168,13 @@ describe('form submission', () => {
false // stackType is DockerCompose
);
});
restoreConsole();
});
it('should call mutation API with correct payload', async () => {
const restoreConsole = suppressConsoleLogs();
let capturedRequestBody: unknown;
server.use(
@@ -203,6 +213,8 @@ describe('form submission', () => {
},
{ timeout: 3000 }
);
restoreConsole();
});
it('should not submit if confirmation is cancelled', async () => {
@@ -244,6 +256,8 @@ describe('form submission', () => {
});
it('should call onSubmitSuccess callback and show success notification after mutation completes', async () => {
const restoreConsole = suppressConsoleLogs();
const onSubmitSuccess = vi.fn();
renderComponent({ onSubmitSuccess });
const user = userEvent.setup();
@@ -266,9 +280,13 @@ describe('form submission', () => {
);
expect(onSubmitSuccess).toHaveBeenCalled();
});
restoreConsole();
});
it('should handle API errors during submission', async () => {
const restoreConsole = suppressConsoleLogs();
server.use(
http.put('/api/stacks/:id', () =>
HttpResponse.json({ message: 'Stack update failed' }, { status: 500 })
@@ -295,6 +313,7 @@ describe('form submission', () => {
});
expect(deployButton).toBeEnabled();
restoreConsole();
});
});
@@ -12,6 +12,7 @@ import { withUserProvider } from '@/react/test-utils/withUserProvider';
import { withTestRouter } from '@/react/test-utils/withRouter';
import { createMockStack, createMockUsers } from '@/react-tools/test-mocks';
import { Role } from '@/portainer/users/types';
import { suppressConsoleLogs } from '@/setup-tests/suppress-console';
import { StackEditorTab } from './StackEditorTab';
@@ -103,6 +104,8 @@ describe('StackEditorTab - Webhook ID Handling', () => {
describe('Form submission', () => {
it('should send webhook ID in API request when stack has webhook', async () => {
const restoreConsole = suppressConsoleLogs();
const user = userEvent.setup();
let capturedRequestBody: DefaultBodyType;
@@ -142,9 +145,12 @@ describe('StackEditorTab - Webhook ID Handling', () => {
assert(capturedRequestBody && typeof capturedRequestBody === 'object');
expect(capturedRequestBody?.webhook).toBe('existing-webhook-123');
restoreConsole();
});
it('should not send webhook ID in API request when stack has no webhook', async () => {
const restoreConsole = suppressConsoleLogs();
const user = userEvent.setup();
let capturedRequestBody: DefaultBodyType;
@@ -183,6 +189,7 @@ describe('StackEditorTab - Webhook ID Handling', () => {
);
expect(capturedRequestBody).not.toHaveProperty('webhook');
restoreConsole();
});
});
});
@@ -5,6 +5,7 @@ import { vi } from 'vitest';
import { server } from '@/setup-tests/server';
import { withTestQueryProvider } from '@/react/test-utils/withTestQuery';
import { suppressConsoleLogs } from '@/setup-tests/suppress-console';
import { useVersionedStackFile } from './useVersionedStackFile';
@@ -305,6 +306,9 @@ describe('useVersionedStackFile', () => {
});
describe('error handling', () => {
const restoreConsole = suppressConsoleLogs();
afterAll(restoreConsole);
it('should handle API errors gracefully', async () => {
server.use(
http.get('/api/stacks/:id/file', () =>
@@ -420,6 +424,7 @@ describe('useVersionedStackFile', () => {
});
it('should clear loading state after failed fetch', async () => {
const restoreConsole = suppressConsoleLogs();
server.use(
http.get('/api/stacks/:id/file', () =>
HttpResponse.json({ message: 'Error' }, { status: 500 })
@@ -435,6 +440,8 @@ describe('useVersionedStackFile', () => {
await waitFor(() => {
expect(result.current.isLoading).toBe(false);
});
restoreConsole();
});
});