import { describe, expect, test } from 'vitest'; import { publishStepDependencyName, publishStepDisplayName } from './displayNames.js'; import type { PublishStepKind, PublishStepStatus } from './index.js'; /** A step kind exactly as it arrives over the wire, including one this build has never heard of. */ function wireKind(value: string): PublishStepKind { return JSON.parse(JSON.stringify(value)); } describe('publishStepDisplayName', () => { test('names a step that has not started with its plain, not-yet-running name', () => { expect(publishStepDisplayName('build', 'pending')).toBe('Build application'); expect(publishStepDisplayName('database_provisioning', 'pending')).toBe('Provision database(s)'); expect(publishStepDisplayName('database_migration', 'pending')).toBe('Apply schema migrations to database(s)'); // A publish that has not started must not read as if it is already happening. expect(publishStepDisplayName('publish', 'pending')).toBe('Publish'); }); test('switches to the past tense once a step has finished', () => { expect(publishStepDisplayName('build', 'passed')).toBe('Built application'); expect(publishStepDisplayName('database_provisioning', 'passed')).toBe('Provisioned database(s)'); expect(publishStepDisplayName('database_migration', 'passed')).toBe('Applied schema migrations to database(s)'); expect(publishStepDisplayName('publish', 'passed')).toBe('Published'); }); test('marks a running step with the active phrasing and an ellipsis, and a failed step as failed', () => { expect(publishStepDisplayName('build', 'in_progress')).toBe('Building application…'); expect(publishStepDisplayName('build', 'failed')).toBe('Build application failed'); expect(publishStepDisplayName('database_provisioning', 'in_progress')).toBe('Provisioning database(s)…'); expect(publishStepDisplayName('database_provisioning', 'failed')).toBe('Provision database(s) failed'); expect(publishStepDisplayName('database_migration', 'in_progress')).toBe('Applying schema migrations to database(s)…'); expect(publishStepDisplayName('database_migration', 'failed')).toBe('Apply schema migrations to database(s) failed'); expect(publishStepDisplayName('publish', 'in_progress')).toBe('Publishing…'); expect(publishStepDisplayName('publish', 'failed')).toBe('Publish failed'); }); test('keeps a note with the phrase, ahead of the running or failed marker', () => { expect(publishStepDisplayName('database_provisioning', 'pending', '2 tags')).toBe('Provision database(s) (2 tags)'); expect(publishStepDisplayName('database_provisioning', 'in_progress', '2 tags')).toBe('Provisioning database(s) (2 tags)…'); expect(publishStepDisplayName('database_provisioning', 'failed', '2 tags')).toBe('Provision database(s) (2 tags) failed'); expect(publishStepDisplayName('database_provisioning', 'passed', '2 tags')).toBe('Provisioned database(s) (2 tags)'); }); test('treats a step that cleared with advisories as finished', () => { expect(publishStepDisplayName('build', 'advisory')).toBe('Built application'); }); test('keeps the neutral, not-yet-running name for a step that is waiting or otherwise not running', () => { for (const status of ['action_required', 'blocked', 'skipped', 'stale'] satisfies PublishStepStatus[]) { expect(publishStepDisplayName('build', status)).toBe('Build application'); } }); test('gives the policy step an active phrasing while it runs, and its plain name otherwise', () => { expect(publishStepDisplayName('policy_gates', 'pending')).toBe('Pre-Publish Policies'); expect(publishStepDisplayName('policy_gates', 'in_progress')).toBe('Running Pre-Publish Policies…'); expect(publishStepDisplayName('policy_gates', 'passed')).toBe('Pre-Publish Policies'); expect(publishStepDisplayName('policy_gates', 'failed')).toBe('Pre-Publish Policies failed'); }); test('has a label for every kind so a new step cannot render an empty row', () => { const kinds: PublishStepKind[] = ['build', 'database_migration', 'database_provisioning', 'policy_gates', 'publish']; for (const kind of kinds) { expect(publishStepDisplayName(kind, 'pending')).not.toBe(''); } }); test('shows the raw kind when a newer server sends a step this build does not know', () => { expect(publishStepDisplayName(wireKind('quantum_deploy'), 'pending')).toBe('quantum_deploy'); expect(publishStepDisplayName(wireKind('quantum_deploy'), 'in_progress')).toBe('quantum_deploy…'); expect(publishStepDisplayName(wireKind('quantum_deploy'), 'passed')).toBe('quantum_deploy'); }); }); describe('publishStepDependencyName', () => { test('names a step as a thing to wait for rather than an action in progress', () => { expect(publishStepDependencyName('build')).toBe('the application build'); expect(publishStepDependencyName('database_migration')).toBe('schema migrations'); expect(publishStepDependencyName('database_provisioning')).toBe('database provisioning'); expect(publishStepDependencyName('policy_gates')).toBe('Pre-Publish Policies'); expect(publishStepDependencyName('publish')).toBe('publishing'); }); test('shows the raw kind when a newer server sends a step this build does not know', () => { expect(publishStepDependencyName(wireKind('quantum_deploy'))).toBe('quantum_deploy'); }); });