Frontend tests improvements (#13115)

Fix warnings and lower coverage by 0.1%
This commit is contained in:
Félix Malfait
2025-07-09 09:23:26 +02:00
committed by GitHub
parent 6057bdd389
commit 6ba6860e1c
29 changed files with 435 additions and 237 deletions
@@ -1,5 +1,5 @@
import { MockedProvider } from '@apollo/client/testing';
import { renderHook } from '@testing-library/react';
import { act, renderHook } from '@testing-library/react';
import { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { RecoilRoot } from 'recoil';
@@ -99,7 +99,9 @@ describe('useWebhookForm', () => {
secret: 'test-secret',
};
await result.current.handleSave(formData);
await act(async () => {
await result.current.handleSave(formData);
});
expect(mockCreateOneRecord).toHaveBeenCalledWith({
id: expect.any(String),
@@ -132,7 +134,9 @@ describe('useWebhookForm', () => {
secret: 'test-secret',
};
await result.current.handleSave(formData);
await act(async () => {
await result.current.handleSave(formData);
});
expect(mockEnqueueErrorSnackBar).toHaveBeenCalledWith({
apolloError: error,
@@ -159,7 +163,9 @@ describe('useWebhookForm', () => {
secret: 'test-secret',
};
await result.current.handleSave(formData);
await act(async () => {
await result.current.handleSave(formData);
});
expect(mockCreateOneRecord).toHaveBeenCalledWith({
id: expect.any(String),
@@ -206,7 +212,9 @@ describe('useWebhookForm', () => {
secret: 'updated-secret',
};
await result.current.handleSave(formData);
await act(async () => {
await result.current.handleSave(formData);
});
expect(mockUpdateOneRecord).toHaveBeenCalledWith({
idToUpdate: webhookId,
@@ -241,7 +249,9 @@ describe('useWebhookForm', () => {
secret: 'test-secret',
};
await result.current.handleSave(formData);
await act(async () => {
await result.current.handleSave(formData);
});
expect(mockEnqueueErrorSnackBar).toHaveBeenCalledWith({
apolloError: error,
@@ -256,7 +266,9 @@ describe('useWebhookForm', () => {
{ wrapper: Wrapper },
);
result.current.updateOperation(0, 'object', 'person');
act(() => {
result.current.updateOperation(0, 'object', 'person');
});
const operations = result.current.formConfig.getValues('operations');
expect(operations[0].object).toBe('person');
@@ -268,16 +280,20 @@ describe('useWebhookForm', () => {
{ wrapper: Wrapper },
);
result.current.formConfig.setValue('operations', [
{ object: 'person', action: 'created' },
{ object: 'company', action: 'updated' },
]);
act(() => {
result.current.formConfig.setValue('operations', [
{ object: 'person', action: 'created' },
{ object: 'company', action: 'updated' },
]);
});
const initialOperations =
result.current.formConfig.getValues('operations');
const initialCount = initialOperations.length;
result.current.removeOperation(0);
act(() => {
result.current.removeOperation(0);
});
const updatedOperations =
result.current.formConfig.getValues('operations');
@@ -300,7 +316,9 @@ describe('useWebhookForm', () => {
{ wrapper: Wrapper },
);
await result.current.deleteWebhook();
await act(async () => {
await result.current.deleteWebhook();
});
expect(mockDeleteOneRecord).toHaveBeenCalledWith(webhookId);
expect(mockEnqueueSuccessSnackBar).toHaveBeenCalledWith({
@@ -314,7 +332,9 @@ describe('useWebhookForm', () => {
{ wrapper: Wrapper },
);
await result.current.deleteWebhook();
await act(async () => {
await result.current.deleteWebhook();
});
expect(mockEnqueueErrorSnackBar).toHaveBeenCalledWith({
message: 'Webhook ID is required for deletion',
@@ -336,7 +356,9 @@ describe('useWebhookForm', () => {
{ wrapper: Wrapper },
);
await result.current.deleteWebhook();
await act(async () => {
await result.current.deleteWebhook();
});
expect(mockEnqueueErrorSnackBar).toHaveBeenCalledWith({
apolloError: error,