forked from Creditra/Creditra-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewSection.test.tsx
More file actions
64 lines (53 loc) · 2.42 KB
/
Copy pathPreviewSection.test.tsx
File metadata and controls
64 lines (53 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { PreviewSection } from './PreviewSection';
import { ConfirmationStep } from './ConfirmationStep';
import type { CreditLine } from '@/types/draw-credit.types';
const creditLine: CreditLine = {
id: 'line-1',
name: 'Test Line',
limit: 10000,
available: 4000,
utilization: 60,
};
describe('glossed credit terms', () => {
it('exposes the first utilization gloss in PreviewSection via keyboard and aria-describedby', async () => {
const user = userEvent.setup();
render(<PreviewSection creditLine={creditLine} amount={1000} />);
const trigger = screen.getByLabelText('More information');
const tooltip = screen.getByRole('tooltip');
expect(trigger).toHaveAttribute('aria-describedby', tooltip.id);
expect(trigger).toHaveAttribute('tabindex', '0');
await user.tab();
expect(trigger).toHaveFocus();
expect(tooltip).toHaveTextContent('Utilization is the percentage of your available credit that is currently being used.');
});
it('wraps the first utilization and term occurrences in ConfirmationStep without repeating them', async () => {
const user = userEvent.setup();
render(
<ConfirmationStep
creditLine={creditLine}
amount={1000}
onConfirm={() => undefined}
onBack={() => undefined}
onCancel={() => undefined}
/>,
);
const triggers = screen.getAllByLabelText('More information');
expect(triggers).toHaveLength(2);
const firstUtilizationTrigger = screen.getByText('Current utilization').closest('.accessible-tooltip');
expect(firstUtilizationTrigger).not.toBeNull();
await user.tab();
expect(triggers[0]).toHaveFocus();
});
it('keeps glossary copy aligned with docs/MICROCOPY.md', () => {
const microcopyPath = path.resolve(__dirname, '../../docs/MICROCOPY.md');
const microcopy = readFileSync(microcopyPath, 'utf8');
expect(microcopy).toContain('Utilization is the percentage of your available credit that is currently being used.');
expect(microcopy).toContain('A reserve is the portion of your credit line that should stay untouched for safety and flexibility.');
expect(microcopy).toContain('A term is a defined period or condition of your credit agreement.');
});
});