fix(tests): Enhance CrowdSecConfig with new input fields and improve accessibility
- Added IDs to input fields in CrowdSecConfig for better accessibility. - Updated labels to use <label> elements for checkboxes and inputs. - Improved error handling and user feedback in the CrowdSecConfig tests. - Enhanced test coverage for console enrollment and banned IP functionalities. fix: Update SecurityHeaders to include aria-label for delete button - Added aria-label to the delete button for better screen reader support. test: Add comprehensive tests for proxyHostsHelpers and validation utilities - Implemented tests for formatting and help text functions in proxyHostsHelpers. - Added validation tests for email and IP address formats. chore: Update vitest configuration for dynamic coverage thresholds - Adjusted coverage thresholds to be dynamic based on environment variables. - Included additional coverage reporters. chore: Update frontend-test-coverage script to reflect new coverage threshold - Increased minimum coverage requirement from 85% to 87.5%. fix: Ensure tests pass with consistent data in passwd file - Updated tests/etc/passwd to ensure consistent content.
This commit is contained in:
85
frontend/src/api/__tests__/import.test.ts
Normal file
85
frontend/src/api/__tests__/import.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { uploadCaddyfile, uploadCaddyfilesMulti, getImportPreview, commitImport, cancelImport, getImportStatus } from '../import';
|
||||
import client from '../client';
|
||||
|
||||
vi.mock('../client', () => ({
|
||||
default: {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('import API', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('uploadCaddyfile posts content', async () => {
|
||||
const content = 'example.com';
|
||||
const mockResponse = { preview: { hosts: [] } };
|
||||
(client.post as any).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await uploadCaddyfile(content);
|
||||
expect(client.post).toHaveBeenCalledWith('/import/upload', { content });
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('uploadCaddyfilesMulti posts files', async () => {
|
||||
const files = [{ filename: 'Caddyfile', content: 'foo.com' }];
|
||||
const mockResponse = { preview: { hosts: [] } };
|
||||
(client.post as any).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await uploadCaddyfilesMulti(files);
|
||||
expect(client.post).toHaveBeenCalledWith('/import/upload-multi', { files });
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('getImportPreview gets preview', async () => {
|
||||
const mockResponse = { preview: { hosts: [] } };
|
||||
(client.get as any).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await getImportPreview();
|
||||
expect(client.get).toHaveBeenCalledWith('/import/preview');
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('commitImport posts commitments', async () => {
|
||||
const sessionUUID = 'uuid-123';
|
||||
const resolutions = { 'foo.com': 'keep' };
|
||||
const names = { 'foo.com': 'My Site' };
|
||||
const mockResponse = { created: 1, updated: 0, skipped: 0, errors: [] };
|
||||
|
||||
(client.post as any).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await commitImport(sessionUUID, resolutions, names);
|
||||
expect(client.post).toHaveBeenCalledWith('/import/commit', {
|
||||
session_uuid: sessionUUID,
|
||||
resolutions,
|
||||
names
|
||||
});
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('cancelImport posts cancel', async () => {
|
||||
(client.post as any).mockResolvedValue({});
|
||||
|
||||
await cancelImport();
|
||||
expect(client.post).toHaveBeenCalledWith('/import/cancel');
|
||||
});
|
||||
|
||||
it('getImportStatus gets status', async () => {
|
||||
const mockResponse = { has_pending: true };
|
||||
(client.get as any).mockResolvedValue({ data: mockResponse });
|
||||
|
||||
const result = await getImportStatus();
|
||||
expect(client.get).toHaveBeenCalledWith('/import/status');
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('getImportStatus handles error', async () => {
|
||||
(client.get as any).mockRejectedValue(new Error('Failed'));
|
||||
|
||||
const result = await getImportStatus();
|
||||
expect(result).toEqual({ has_pending: false });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user