mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-10 05:08:53 +00:00
e37403edf1
Frontend design remediation, Phase 1 (Foundation Primitives + Toast).
Builds the six reusable UI primitives every later phase consumes;
migrates the audit-enumerated destructive-action callsites; humanises
the StatusBadge wire keys; and wraps the bulk-action bar in a
Transition with a post-action toast affordance.
Six new primitives + their .test.tsx siblings
=============================================
web/src/components/Toaster.tsx — Sonner wrapper, mounted
once at the root next to
QueryClientProvider. Pages
import { toast } from
"sonner" directly.
web/src/components/ConfirmDialog.tsx — Headless UI Dialog primitive
with optional typed-
confirmation friction for
the most-irreversible actions
(archive-certificate uses
typedConfirmation="archive").
web/src/components/Tooltip.tsx — Floating-UI tooltip with
hover + focus triggers,
aria-describedby wiring,
ESC-to-dismiss. Migrations
of the 103 native title=
sites stay in subsequent
per-page PRs per the audit
prompt's explicit "DO NOT"
on one-mega-PR sweeps.
web/src/components/EmptyState.tsx — Empty-state primitive with
optional icon / title /
description / primary +
secondary CTAs. DataTable
adds a new emptyState slot
(legacy emptyMessage string
prop preserved for backward
compat).
web/src/components/Combobox.tsx — Headless UI typeahead-
select primitive. Migrations
of the 53 native <select>
sites stay in subsequent
per-page PRs.
web/src/components/Banner.tsx — Severity-variant alert
banner with role="alert" on
error/warning, role="status"
on success/info. Migrating
the ~102 inline
bg-(red|amber|yellow)-50
sites stays as page-touch
rolling work.
Each primitive ships with a sibling .test.tsx asserting the
behavioural contract — render at rest, fire callbacks, ARIA wiring,
keyboard nav, variant styling. Total new test count: 109 assertions
across 7 files (6 primitives + extended StatusBadge).
UX-H5 closure — StatusBadge display strings
============================================
web/src/components/StatusBadge.tsx gets a statusDisplay map paired
with the existing statusStyles map. Wire keys stay byte-identical
to the Go enums per the D-1 closure comment block — only the
rendered text changes. PascalCase + snake_case + lowercase enums
now render as spaced sentence-case:
"RenewalInProgress" → "Renewal in progress"
"AwaitingCSR" → "Awaiting CSR"
"cert_mismatch" → "Certificate mismatch"
"dead" → "Dead-lettered"
Unmapped keys flow through a titleCase() helper that humanises
PascalCase / snake_case to lower-bound readability.
StatusBadge.test.tsx extends to 75 assertions: 38 D-1 + 5 dead-key
+ 31 UX-H5 display-string + 5 titleCase + 1 parity. All wire-keys
pinned byte-exact.
UX-H2 closure — window.confirm sites migrated to ConfirmDialog
==============================================================
Audit said 8 destructive-action sites. Live count was 24 across
17 files — the audit missed 11 files (auth/SessionsPage,
auth/UsersPage, auth/GroupMappingsPage, auth/OIDCProvidersPage,
auth/OIDCProviderDetailPage, auth/RolesPage, TeamsPage,
PoliciesPage, IssuersPage, ProfilesPage, RenewalPoliciesPage).
Phase 1 migrates the 7 audit-enumerated destructive sites in the
6 priority files:
- CertificateDetailPage archive (typedConfirmation="archive" —
most-irreversible action gets the
strongest friction)
- OwnersPage delete owner
- TargetsPage delete target
- AgentGroupsPage delete agent group
- auth/KeysPage revoke role grant
- auth/RoleDetailPage delete role
The remaining 11 confirm sites in audit-missed files stay open
and ship as a Phase 1 follow-up (mechanical pattern repeat — same
Edit shape × ~11 files).
UX-H3 closure — alert() → toast.error, top mutations wired
===========================================================
All 5 alert() sites migrated to toast.error:
- OwnersPage / CertificateDetailPage × 2 / TeamsPage /
RenewalPoliciesPage
Eight high-traffic mutations now fire toast.success on resolve +
toast.error on failure: deleteOwner, deleteTarget, deleteAgentGroup,
deleteTeam, deleteRenewalPolicy, archiveCertificate,
authRevokeKeyRole, authDeleteRole. The bulk-renew flow on
CertificatesPage gets a toast with a "View N jobs" action button
that deep-links to /jobs?certificate_ids=… (paired UX-L5 work).
Toaster mounted at web/src/main.tsx next to QueryClientProvider —
single import discipline. Sonner asserts at runtime if multiple
toasters are mounted; centralising the position + duration config
in Toaster.tsx avoids the mistake.
UX-M3 closure — DataTable empty-state slot
==========================================
web/src/components/DataTable.tsx gains an optional emptyState
ReactNode prop. The existing emptyMessage string prop is
preserved for backward compat — every ~18 list-page call site
that passes emptyMessage="…" keeps working unchanged. New CTAs:
pages pass <EmptyState ... /> for first-run experiences. Wiring
EmptyState on the top-5 list pages (Certificates, Issuers,
Targets, Owners, Agents) is per-page rolling work — primitive
+ slot ship in Phase 1; CTAs follow.
UX-L5 closure — Bulk-action bar transition + post-action toast
==============================================================
web/src/pages/CertificatesPage.tsx wraps the bulk-action bar
conditional render in Headless UI <Transition>. Slide-in/out
(200ms enter, 150ms leave, -translate-y-2 → 0). The
prefers-reduced-motion respect comes for free from the global
@media block landed in Phase 0.
Post-renewal toast.success fires with an action button "View N
jobs" that navigate()s to /jobs filtered to the certificate_ids
we just renewed. Closes the audit's "what just happened" gap.
Audit-accuracy callouts
=======================
* UX-H2 undercount — live 24 sites vs audit's 8. Phase 1 closes
the 7 audit-enumerated destructive confirms across 6 priority
files. The remaining 11 sites in audit-missed files stay open
for follow-up.
* UX-M2 title= count — live 103 (matches audit). Tooltip
primitive built; per-page migrations explicitly deferred per
the prompt's "DO NOT" sweep rule.
* UX-M4 native <select> sites — Combobox primitive built;
callsite migrations deferred to per-page rolling PRs.
* FE-M4 inline bg-(red|amber|yellow)-50 — Banner primitive
built; callsite migrations deferred to page-touch work.
Verification
============
$ npx tsc --noEmit
(exit 0, no type errors)
$ npx vitest run src/components/{Toaster,ConfirmDialog,EmptyState,Banner,Tooltip,Combobox}.test.tsx src/components/StatusBadge.test.tsx
Test Files 7 passed (7)
Tests 109 passed (109)
$ npx vitest run src/pages/{OwnersPage,AgentGroupsPage,TargetsPage,CertificatesPage,CertificateDetailPage,TeamsPage,RenewalPoliciesPage}.test.tsx src/pages/auth/{KeysPage,RoleDetailPage}.test.tsx
Test Files 9 passed (9)
Tests 52 passed (52)
(TargetsPage.test.tsx updated — the existing Delete confirm
test stubbed window.confirm; new test clicks the dialog's
destructive Delete button.)
$ npx vite build
✓ built in 2.89s
dist/assets/index-DZ1ZcRdP.js 1,110.61 kB (was 1,028.66 kB)
+82 KB / +26 KB gzipped from sonner + @headlessui + @floating-ui.
Bundle code-splitting is a separate phase (FE-M5).
Residual risks + follow-ups
============================
* 11 remaining window.confirm sites in audit-missed files. Phase 1
follow-up commit will sweep them with the same ConfirmDialog
pattern — mechanical work.
* The discard-unsaved-changes confirm in EditRoleModal (and 2
sibling modal sub-components) stays as window.confirm; treated
as a UX safety guardrail rather than a destructive-action
confirmation. Migrating to ConfirmDialog is fine but not
audit-priority.
* Tooltip + Combobox + Banner callsite migrations are explicit
per-page rolling work for subsequent phases — primitives
landed; per the audit prompt's "DO NOT" rule the migrations
don't sweep here.
* Optimistic-update wiring on the 5 priority mutations
(mark-notification-read, dismiss-discovery, archive-cert,
claim-discovered-cert, role-assignment) is staged for Phase 2
TQ-M3 per the prompt's explicit "DO NOT add new mutations to
the optimistic-update list beyond the 5 priority ones".
130 lines
4.4 KiB
TypeScript
130 lines
4.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { render, screen, waitFor, fireEvent, cleanup } from '@testing-library/react';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
import type { ReactNode } from 'react';
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// T-1 closure (cat-s2-c24a548076c6): TargetsPage Vitest coverage.
|
|
//
|
|
// Pins:
|
|
// 1. Targets list renders when getTargets resolves.
|
|
// 2. Status column derives from `enabled` (D-2 phantom-field trim).
|
|
// 3. Connection column reads test_status (D-2 contract).
|
|
// 4. Delete confirm flow calls deleteTarget(id).
|
|
// -----------------------------------------------------------------------------
|
|
|
|
vi.mock('../api/client', () => ({
|
|
getTargets: vi.fn(),
|
|
createTarget: vi.fn(),
|
|
deleteTarget: vi.fn(),
|
|
getAgents: vi.fn(),
|
|
}));
|
|
|
|
import TargetsPage from './TargetsPage';
|
|
import * as client from '../api/client';
|
|
|
|
function renderWithQuery(ui: ReactNode) {
|
|
const qc = new QueryClient({
|
|
defaultOptions: { queries: { retry: false, gcTime: 0, staleTime: 0 } },
|
|
});
|
|
return render(
|
|
<QueryClientProvider client={qc}>
|
|
<MemoryRouter>{ui}</MemoryRouter>
|
|
</QueryClientProvider>,
|
|
);
|
|
}
|
|
|
|
const targetEnabled = {
|
|
id: 'tgt-iis-prod',
|
|
name: 'IIS Web01',
|
|
type: 'iis',
|
|
agent_id: 'agent-iis01',
|
|
enabled: true,
|
|
test_status: 'success',
|
|
config: {},
|
|
created_at: new Date().toISOString(),
|
|
updated_at: new Date().toISOString(),
|
|
};
|
|
|
|
const targetUntested = {
|
|
id: 'tgt-untested',
|
|
name: 'New Target',
|
|
type: 'kubernetes',
|
|
agent_id: '',
|
|
enabled: false,
|
|
test_status: 'untested',
|
|
config: {},
|
|
created_at: new Date().toISOString(),
|
|
updated_at: new Date().toISOString(),
|
|
};
|
|
|
|
describe('TargetsPage — T-1 page coverage', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
cleanup();
|
|
vi.mocked(client.getTargets).mockResolvedValue({
|
|
data: [targetEnabled, targetUntested],
|
|
total: 2,
|
|
page: 1,
|
|
per_page: 50,
|
|
});
|
|
vi.mocked(client.getAgents).mockResolvedValue({ data: [], total: 0, page: 1, per_page: 50 });
|
|
vi.mocked(client.deleteTarget).mockResolvedValue({ message: 'deleted' });
|
|
});
|
|
|
|
it('renders the targets list when getTargets resolves', async () => {
|
|
renderWithQuery(<TargetsPage />);
|
|
await waitFor(() => {
|
|
expect(screen.getByText('IIS Web01')).toBeInTheDocument();
|
|
});
|
|
expect(screen.getByText('New Target')).toBeInTheDocument();
|
|
});
|
|
|
|
it('derives the Status column from enabled (D-2 phantom-field trim)', async () => {
|
|
renderWithQuery(<TargetsPage />);
|
|
await waitFor(() => {
|
|
expect(screen.getByText('IIS Web01')).toBeInTheDocument();
|
|
});
|
|
// Pre-D-2 the column read a phantom `status` field; post-D-2 it derives
|
|
// 'Enabled' / 'Disabled' purely from the boolean.
|
|
expect(screen.getAllByText(/Enabled/).length).toBeGreaterThan(0);
|
|
expect(screen.getAllByText(/Disabled/).length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('Delete confirm flow calls deleteTarget(id)', async () => {
|
|
// Phase 1 UX-H2 closure: Delete now opens a ConfirmDialog primitive
|
|
// (Headless UI) rather than firing window.confirm(). The new flow:
|
|
// 1. operator clicks the row's "Delete" button → sets state
|
|
// that opens the dialog
|
|
// 2. ConfirmDialog mounts with title "Delete deployment target"
|
|
// 3. operator clicks the dialog's destructive "Delete" button
|
|
// 4. deleteTarget(id) fires
|
|
renderWithQuery(<TargetsPage />);
|
|
await waitFor(() => {
|
|
expect(screen.getByText('IIS Web01')).toBeInTheDocument();
|
|
});
|
|
|
|
const rowDeleteButtons = await screen.findAllByRole('button', { name: 'Delete' });
|
|
fireEvent.click(rowDeleteButtons[0]!);
|
|
|
|
// Wait for the dialog title to mount (Headless UI Transition).
|
|
await waitFor(() => {
|
|
expect(screen.getByText('Delete deployment target')).toBeInTheDocument();
|
|
});
|
|
|
|
// Click the dialog's destructive-styled confirm button (.btn-danger).
|
|
const allDeleteButtons = await screen.findAllByRole('button', { name: 'Delete' });
|
|
const dialogDeleteBtn = allDeleteButtons.find((b) =>
|
|
b.className.includes('btn-danger'),
|
|
);
|
|
expect(dialogDeleteBtn).toBeDefined();
|
|
fireEvent.click(dialogDeleteBtn!);
|
|
|
|
await waitFor(() => {
|
|
expect(client.deleteTarget).toHaveBeenCalled();
|
|
});
|
|
expect(vi.mocked(client.deleteTarget).mock.calls[0]?.[0]).toBe('tgt-iis-prod');
|
|
});
|
|
});
|