forked from Talenttrust/Talenttrust-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusBadge.test.tsx
More file actions
192 lines (164 loc) · 7.8 KB
/
Copy pathStatusBadge.test.tsx
File metadata and controls
192 lines (164 loc) · 7.8 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import React from 'react';
import { render, screen } from '@testing-library/react';
import StatusBadge, { StatusType } from '../StatusBadge';
const STATUS_ICONS: Record<StatusType, string> = {
Active: '▶',
Completed: '✓',
Disputed: '⚠',
Pending: '⏳',
Paid: '✔',
};
describe('StatusBadge', () => {
describe('rendering', () => {
it('renders the status text', () => {
render(<StatusBadge status="Completed" />);
expect(screen.getByText('Completed')).toBeInTheDocument();
});
it('renders all status types correctly', () => {
const statuses: StatusType[] = ['Active', 'Completed', 'Disputed', 'Pending', 'Paid'];
statuses.forEach((status) => {
const { unmount } = render(<StatusBadge status={status} />);
expect(screen.getByText(status)).toBeInTheDocument();
unmount();
});
});
it('renders an icon for each status', () => {
const statuses: StatusType[] = ['Active', 'Completed', 'Disputed', 'Pending', 'Paid'];
statuses.forEach((status) => {
const { container, unmount } = render(<StatusBadge status={status} />);
const iconSpan = container.querySelector('span[aria-hidden="true"]');
expect(iconSpan).toBeInTheDocument();
expect(iconSpan?.textContent).toBe(STATUS_ICONS[status]);
unmount();
});
});
it('icon span has aria-hidden="true"', () => {
const { container } = render(<StatusBadge status="Active" />);
const iconSpan = container.querySelector('span[aria-hidden="true"]');
expect(iconSpan).toHaveAttribute('aria-hidden', 'true');
});
});
describe('styling', () => {
// a11y/theming-27: these assertions previously checked for fixed
// Tailwind pastel classes (e.g. 'bg-emerald-100'), which is exactly
// what broke dark-mode contrast -- the same literal classes were
// reused unchanged regardless of [data-theme]. StatusBadge now uses
// the --status-* CSS variables defined in globals.css, which carry
// an audited light/dark pair. See docs/components/Accessibility.md.
it('applies correct themed classes for Active status', () => {
const { container } = render(<StatusBadge status="Active" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-success-bg)]');
expect(span?.className).toContain('text-[var(--status-success-foreground)]');
});
it('applies correct themed classes for Completed status', () => {
const { container } = render(<StatusBadge status="Completed" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-info-bg)]');
expect(span?.className).toContain('text-[var(--status-info-foreground)]');
});
it('applies correct themed classes for Disputed status', () => {
const { container } = render(<StatusBadge status="Disputed" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-error-bg)]');
expect(span?.className).toContain('text-[var(--status-error-foreground)]');
});
it('applies correct themed classes for Pending status', () => {
const { container } = render(<StatusBadge status="Pending" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-warning-bg)]');
expect(span?.className).toContain('text-[var(--status-warning-foreground)]');
});
it('applies correct themed classes for Paid status', () => {
const { container } = render(<StatusBadge status="Paid" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-success-bg)]');
expect(span?.className).toContain('text-[var(--status-success-foreground)]');
});
it('applies base badge styles consistently', () => {
const { container } = render(<StatusBadge status="Active" />);
const span = container.querySelector('span');
expect(span?.className).toContain('inline-flex');
expect(span?.className).toContain('items-center');
expect(span?.className).toContain('rounded-full');
expect(span?.className).toContain('px-3');
expect(span?.className).toContain('py-1');
expect(span?.className).toContain('text-sm');
expect(span?.className).toContain('font-semibold');
});
it('no longer uses fixed Tailwind pastel color classes (regression guard)', () => {
const statuses: StatusType[] = ['Active', 'Completed', 'Disputed', 'Pending', 'Paid'];
statuses.forEach((status) => {
const { container, unmount } = render(<StatusBadge status={status} />);
const span = container.querySelector('span');
expect(span?.className).not.toMatch(/bg-(emerald|sky|rose|amber)-100/);
expect(span?.className).not.toMatch(/text-(emerald|sky|rose|amber)-800/);
unmount();
});
});
});
describe('additional className prop', () => {
it('applies additional className when provided', () => {
const { container } = render(<StatusBadge status="Completed" className="ml-2 custom-class" />);
const span = container.querySelector('span');
expect(span?.className).toContain('ml-2');
expect(span?.className).toContain('custom-class');
});
it('works with empty className prop', () => {
const { container } = render(<StatusBadge status="Completed" className="" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-info-bg)]');
});
it('defaults to empty string when className is not provided', () => {
const { container } = render(<StatusBadge status="Completed" />);
const span = container.querySelector('span');
expect(span?.className).toContain('bg-[var(--status-info-bg)]');
});
});
describe('accessibility', () => {
it('has role="status" for screen readers', () => {
render(<StatusBadge status="Completed" />);
const badge = screen.getByRole('status');
expect(badge).toBeInTheDocument();
});
it('has appropriate aria-label for each status', () => {
const statuses: StatusType[] = ['Active', 'Completed', 'Disputed', 'Pending', 'Paid'];
statuses.forEach((status) => {
const { unmount } = render(<StatusBadge status={status} />);
expect(screen.getByLabelText(`Status: ${status}`)).toBeInTheDocument();
unmount();
});
});
it('is semantically correct with role and label', () => {
render(<StatusBadge status="Active" />);
const badge = screen.getByRole('status', { name: 'Status: Active' });
expect(badge).toHaveTextContent('Active');
});
});
describe('snapshot tests', () => {
it('matches snapshot for Active status', () => {
const { container } = render(<StatusBadge status="Active" />);
expect(container.firstChild).toMatchSnapshot();
});
it('matches snapshot for Completed status', () => {
const { container } = render(<StatusBadge status="Completed" />);
expect(container.firstChild).toMatchSnapshot();
});
it('matches snapshot for Disputed status', () => {
const { container } = render(<StatusBadge status="Disputed" />);
expect(container.firstChild).toMatchSnapshot();
});
it('matches snapshot for Pending status', () => {
const { container } = render(<StatusBadge status="Pending" />);
expect(container.firstChild).toMatchSnapshot();
});
it('matches snapshot for Paid status', () => {
const { container } = render(<StatusBadge status="Paid" />);
expect(container.firstChild).toMatchSnapshot();
});
it('matches snapshot with additional className', () => {
const { container } = render(<StatusBadge status="Active" className="ml-2" />);
expect(container.firstChild).toMatchSnapshot();
});
});
});