7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
134 lines
4.6 KiB
JavaScript
134 lines
4.6 KiB
JavaScript
/**
|
|
* Tests for components/fallback/formatting.js
|
|
*
|
|
* Tests the fallback formatting utilities that provide basic
|
|
* implementations when the main formatting module is unavailable.
|
|
*/
|
|
|
|
// Ensure main formatting is NOT loaded (so fallback activates)
|
|
// We need ResearchStates for formatStatus
|
|
window.RESEARCH_STATUS = {
|
|
IN_PROGRESS: 'in_progress',
|
|
COMPLETED: 'completed',
|
|
FAILED: 'failed',
|
|
SUSPENDED: 'suspended',
|
|
CANCELLED: 'cancelled',
|
|
QUEUED: 'queued',
|
|
PENDING: 'pending',
|
|
ERROR: 'error',
|
|
};
|
|
window.RESEARCH_TERMINAL_STATES = new Set([
|
|
'completed', 'suspended', 'failed', 'error', 'cancelled',
|
|
]);
|
|
|
|
let fallbackFormatting;
|
|
|
|
beforeAll(async () => {
|
|
// Load ResearchStates
|
|
await import('@js/config/constants.js');
|
|
|
|
// Delete any existing formatting to force fallback to activate
|
|
delete window.formatting;
|
|
|
|
// Load fallback
|
|
await import('@js/components/fallback/formatting.js');
|
|
fallbackFormatting = window.formatting;
|
|
});
|
|
|
|
describe('fallback formatting', () => {
|
|
describe('formatDate', () => {
|
|
it('returns N/A for falsy input', () => {
|
|
expect(fallbackFormatting.formatDate(null)).toBe('N/A');
|
|
expect(fallbackFormatting.formatDate('')).toBe('N/A');
|
|
expect(fallbackFormatting.formatDate(undefined)).toBe('N/A');
|
|
});
|
|
|
|
it('formats a valid ISO date', () => {
|
|
const result = fallbackFormatting.formatDate('2025-06-15T10:30:00Z');
|
|
expect(result).toContain('2025');
|
|
expect(result).toContain('15');
|
|
});
|
|
|
|
it('returns original string for invalid date', () => {
|
|
const result = fallbackFormatting.formatDate('not-a-date');
|
|
// The function returns the original string on error
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('formatMode', () => {
|
|
it('maps known modes', () => {
|
|
expect(fallbackFormatting.formatMode('quick')).toBe('Quick Summary');
|
|
expect(fallbackFormatting.formatMode('detailed')).toBe('Detailed Report');
|
|
expect(fallbackFormatting.formatMode('standard')).toBe('Standard Research');
|
|
expect(fallbackFormatting.formatMode('advanced')).toBe('Advanced Research');
|
|
});
|
|
|
|
it('returns Unknown for falsy input', () => {
|
|
expect(fallbackFormatting.formatMode(null)).toBe('Unknown');
|
|
expect(fallbackFormatting.formatMode('')).toBe('Unknown');
|
|
});
|
|
|
|
it('returns raw value for unknown modes', () => {
|
|
expect(fallbackFormatting.formatMode('custom')).toBe('custom');
|
|
});
|
|
});
|
|
|
|
describe('formatDuration', () => {
|
|
it('returns N/A for falsy input (except 0)', () => {
|
|
expect(fallbackFormatting.formatDuration(null)).toBe('N/A');
|
|
expect(fallbackFormatting.formatDuration(undefined)).toBe('N/A');
|
|
});
|
|
|
|
it('formats seconds only when < 60', () => {
|
|
expect(fallbackFormatting.formatDuration(45)).toBe('45s');
|
|
});
|
|
|
|
it('formats minutes and seconds', () => {
|
|
expect(fallbackFormatting.formatDuration(125)).toBe('2m 5s');
|
|
});
|
|
|
|
it('handles zero seconds', () => {
|
|
expect(fallbackFormatting.formatDuration(0)).toBe('0s');
|
|
});
|
|
});
|
|
|
|
describe('formatFileSize', () => {
|
|
it('returns N/A for falsy input (except 0)', () => {
|
|
expect(fallbackFormatting.formatFileSize(null)).toBe('N/A');
|
|
expect(fallbackFormatting.formatFileSize(undefined)).toBe('N/A');
|
|
});
|
|
|
|
it('formats bytes', () => {
|
|
expect(fallbackFormatting.formatFileSize(500)).toBe('500.0 B');
|
|
});
|
|
|
|
it('formats kilobytes', () => {
|
|
expect(fallbackFormatting.formatFileSize(1024)).toBe('1.0 KB');
|
|
});
|
|
|
|
it('formats megabytes', () => {
|
|
expect(fallbackFormatting.formatFileSize(1048576)).toBe('1.0 MB');
|
|
});
|
|
|
|
it('formats gigabytes', () => {
|
|
expect(fallbackFormatting.formatFileSize(1073741824)).toBe('1.0 GB');
|
|
});
|
|
|
|
it('handles zero bytes', () => {
|
|
expect(fallbackFormatting.formatFileSize(0)).toBe('0.0 B');
|
|
});
|
|
|
|
it('formats with decimal precision', () => {
|
|
expect(fallbackFormatting.formatFileSize(1536)).toBe('1.5 KB');
|
|
});
|
|
});
|
|
|
|
describe('formatStatus', () => {
|
|
it('delegates to ResearchStates.formatStatus', () => {
|
|
expect(fallbackFormatting.formatStatus('completed')).toBe('Completed');
|
|
expect(fallbackFormatting.formatStatus('in_progress')).toBe('In Progress');
|
|
});
|
|
});
|
|
});
|