PSA/packages/scheduling/tests/timeEntryChangeRequestFeedback.test.ts
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

129 lines
4.7 KiB
TypeScript

// @vitest-environment jsdom
import * as React from 'react';
import { createRoot, Root } from 'react-dom/client';
import { flushSync } from 'react-dom';
import { beforeEach, describe, expect, it, vi } from 'vitest';
// useFormatters requires an I18nProvider; these tests render the panel
// standalone, so substitute locale-stable formatters.
vi.mock('@alga-psa/ui/lib/i18n/client', async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return {
...actual,
useFormatters: () => ({
formatDate: (date: Date | string, options?: Intl.DateTimeFormatOptions) =>
new Intl.DateTimeFormat('en-US', options).format(typeof date === 'string' ? new Date(date) : date),
formatNumber: (value: number, options?: Intl.NumberFormatOptions) =>
new Intl.NumberFormat('en-US', options).format(value),
formatCurrency: (value: number, currency: string, options?: Intl.NumberFormatOptions) =>
new Intl.NumberFormat('en-US', { style: 'currency', currency, ...options }).format(value),
formatRelativeTime: (date: Date | string) => String(date),
}),
};
});
import { TimeEntryChangeRequestPanel } from '../src/components/time-management/time-entry/time-sheet/TimeEntryChangeRequestFeedback';
describe('TimeEntryChangeRequestPanel', () => {
let container: HTMLDivElement;
let root: Root;
beforeEach(() => {
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
});
it('T008: shows the latest feedback banner when an entry has approver feedback', () => {
flushSync(() => {
root.render(
React.createElement(TimeEntryChangeRequestPanel, {
changeRequests: [
{
change_request_id: 'older',
time_entry_id: 'entry-1',
time_sheet_id: 'sheet-1',
comment: 'Older feedback',
created_at: '2026-03-10T09:00:00.000Z',
created_by: 'manager-1',
created_by_name: 'Grace Hopper',
tenant: 'tenant-1',
},
{
change_request_id: 'latest',
time_entry_id: 'entry-1',
time_sheet_id: 'sheet-1',
comment: 'Please split the travel and onsite work.',
created_at: '2026-03-11T09:00:00.000Z',
created_by: 'manager-1',
created_by_name: 'Grace Hopper',
tenant: 'tenant-1',
},
],
}),
);
});
expect(container.textContent).toContain('Approver feedback');
expect(container.textContent).toContain('Please split the travel and onsite work.');
expect(container.textContent).toContain('View feedback history');
});
it('T009: hides the feedback banner when an entry has no feedback', () => {
flushSync(() => {
root.render(React.createElement(TimeEntryChangeRequestPanel, { changeRequests: [] }));
});
expect(container.textContent?.trim()).toBe('');
});
it('T010/T011: renders expandable history for multiple records in chronological order', () => {
flushSync(() => {
root.render(
React.createElement(TimeEntryChangeRequestPanel, {
changeRequests: [
{
change_request_id: 'first',
time_entry_id: 'entry-1',
time_sheet_id: 'sheet-1',
comment: 'First note',
created_at: '2026-03-10T09:00:00.000Z',
created_by: 'manager-1',
created_by_name: 'Grace Hopper',
handled_at: '2026-03-10T12:00:00.000Z',
handled_by: 'user-1',
tenant: 'tenant-1',
},
{
change_request_id: 'second',
time_entry_id: 'entry-1',
time_sheet_id: 'sheet-1',
comment: 'Second note',
created_at: '2026-03-11T09:00:00.000Z',
created_by: 'manager-1',
created_by_name: 'Grace Hopper',
tenant: 'tenant-1',
},
],
}),
);
});
const details = container.querySelector('details');
if (!details) {
throw new Error('Expected feedback history details element');
}
details.open = true;
const panelText = container.textContent ?? '';
expect(panelText).toContain('View feedback history');
const historyBodies = Array.from(details.querySelectorAll('p'))
.map((node) => node.textContent ?? '')
.filter((text) => text === 'First note' || text === 'Second note');
expect(historyBodies).toEqual(['First note', 'Second note']);
expect(container.querySelector('[data-feedback-state="handled"]')).not.toBeNull();
expect(container.querySelector('[data-feedback-state="unresolved"]')).not.toBeNull();
});
});