Simplify campaign detail UI and progress states
This commit is contained in:
@@ -1,8 +1,32 @@
|
||||
import { afterEach, expect, it, vi } from 'vitest';
|
||||
import { fetchCampaigns } from '../../src/lib/ui/campaigns.js';
|
||||
import { campaignServerStatus, fetchCampaigns } from '../../src/lib/ui/campaigns.js';
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it('distinguishes queued work, file application, and health verification without treating stage messages as failures', () => {
|
||||
const server = { restart_state: 'pending', restarted_at: null, error: 'Queued to restart; waiting for another server to recover' };
|
||||
expect(campaignServerStatus(server, [{ apply_state: 'pending' }])).toEqual({ group: 'queued', label: 'Queued', tone: 'neutral' });
|
||||
expect(campaignServerStatus(server, [{ apply_state: 'applying' }])).toMatchObject({ group: 'processing', label: 'Applying files' });
|
||||
expect(campaignServerStatus({ ...server, restarted_at: '2026-10-06T20:08:29Z', error: 'Checking container state with host agent' }, [{ apply_state: 'applied' }]))
|
||||
.toEqual({ group: 'processing', label: 'Verifying health', tone: 'info' });
|
||||
});
|
||||
|
||||
it.each(['failed', 'held', 'manual'])('keeps %s servers needing intervention ahead of ordinary progress', restart_state => {
|
||||
expect(campaignServerStatus({ restart_state, restarted_at: '2026-10-06T20:08:29Z' }, [{ apply_state: 'applying' }]))
|
||||
.toMatchObject({ group: 'attention', tone: restart_state === 'failed' ? 'danger' : 'warning' });
|
||||
});
|
||||
|
||||
it('preserves completed and inactive outcomes without asking users to intervene on deleted servers', () => {
|
||||
const server = { restart_state: 'done', restarted_at: '2026-10-06T20:08:29Z' };
|
||||
expect(campaignServerStatus(server)).toMatchObject({ group: 'complete', label: 'Complete' });
|
||||
for (const restart_state of ['skipped', 'cancelled']) {
|
||||
expect(campaignServerStatus({ ...server, restart_state })).toMatchObject({ group: 'inactive', tone: 'neutral' });
|
||||
}
|
||||
const deleted = { ...server, server_deleted_at: '2026-10-06T21:00:00Z' };
|
||||
expect(campaignServerStatus(deleted)).toMatchObject({ group: 'complete' });
|
||||
expect(campaignServerStatus({ ...deleted, restart_state: 'failed' })).toEqual({ group: 'inactive', label: 'Deleted before activation', tone: 'neutral' });
|
||||
});
|
||||
|
||||
it('loads history beyond the API page limit without truncating or fetching unwanted older rows', async () => {
|
||||
const requests: URL[] = [];
|
||||
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
||||
|
||||
Reference in New Issue
Block a user