forked from Creditra/Creditra-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessibleTooltip.test.tsx
More file actions
47 lines (37 loc) · 1.88 KB
/
Copy pathAccessibleTooltip.test.tsx
File metadata and controls
47 lines (37 loc) · 1.88 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
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 { AccessibleTooltip } from './AccessibleTooltip';
describe('AccessibleTooltip', () => {
it('connects the focusable help trigger to tooltip content', () => {
render(<AccessibleTooltip label="Explain this field." />);
const trigger = screen.getByLabelText('More information');
const tooltip = screen.getByRole('tooltip');
expect(trigger).toHaveAttribute('aria-describedby', tooltip.id);
expect(trigger).toHaveAttribute('tabindex', '0');
expect(tooltip).toHaveTextContent('Explain this field.');
});
it('supports inline child content and exposes the gloss via aria-describedby', async () => {
const user = userEvent.setup();
render(
<AccessibleTooltip label="Utilization is the percentage of your available credit that is currently being used.">
<span>utilization</span>
</AccessibleTooltip>,
);
const trigger = screen.getByText('utilization').closest('.accessible-tooltip__trigger');
const tooltip = screen.getByRole('tooltip');
expect(trigger).not.toBeNull();
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('keeps the 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.');
});
});