-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgroupedBooleanLabel.test.tsx
More file actions
65 lines (58 loc) · 2.17 KB
/
Copy pathgroupedBooleanLabel.test.tsx
File metadata and controls
65 lines (58 loc) · 2.17 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
/**
* Grouped boolean headers fall back to readable Yes/No.
*
* Regression coverage for the group header rendering the raw i18n key
* (`grid.booleanTrue`) instead of a label: the formatter asked for keys that
* exist in neither the grid's default bundle nor the locale files, and passed
* the English fallback as a bare second argument — which the no-provider
* translator reads as an options object, so the fallback never applied.
*
* These grids render with no `I18nProvider`, which is exactly the path the
* defaults map exists to serve (standalone usage / tests).
*/
import { describe, it, expect } from 'vitest';
import { render, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import React from 'react';
import { ObjectGrid } from '../ObjectGrid';
import { registerAllFields } from '@object-ui/fields';
import { ActionProvider } from '@object-ui/react';
registerAllFields();
const rows = [
{ id: '1', name: 'Row 1', active: true },
{ id: '2', name: 'Row 2', active: false },
{ id: '3', name: 'Row 3', active: true },
];
function renderBooleanGroupedGrid() {
const schema: any = {
type: 'object-grid' as const,
objectName: 'test_object',
columns: [
{ field: 'name', label: 'Name' },
{ field: 'active', label: 'Active', type: 'boolean' },
],
data: { provider: 'value', items: rows },
grouping: { fields: [{ field: 'active' }] },
};
return render(
<ActionProvider>
<ObjectGrid schema={schema} />
</ActionProvider>
);
}
const groupLabels = () =>
Array.from(document.querySelectorAll('.group-label')).map((el) => el.textContent);
describe('Grouped boolean group headers', () => {
it('labels the groups Yes / No', async () => {
renderBooleanGroupedGrid();
await waitFor(() => expect(groupLabels().length).toBeGreaterThan(0));
expect(groupLabels()).toEqual(expect.arrayContaining(['Yes', 'No']));
});
it('never leaks a raw `grid.*` translation key into a group header', async () => {
renderBooleanGroupedGrid();
await waitFor(() => expect(groupLabels().length).toBeGreaterThan(0));
for (const label of groupLabels()) {
expect(label).not.toMatch(/^grid\./);
}
});
});