-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathViewRefWidget.test.tsx
More file actions
61 lines (54 loc) · 1.9 KB
/
Copy pathViewRefWidget.test.tsx
File metadata and controls
61 lines (54 loc) · 1.9 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
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect, afterEach } from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import { WIDGETS } from './widgets';
afterEach(cleanup);
const ViewRef = WIDGETS['view-ref'];
/**
* ADR-0047 `view-ref` widget — picks `interfaceConfig.sourceView` from the
* source object's views (context.objectViews) instead of a free-text name the
* author could mistype. Radix Select portals its option list on open (flaky in
* jsdom), so these tests cover the parts that render eagerly: the registry
* wiring, the closed trigger, and graceful degradation with no views.
*/
describe('view-ref widget', () => {
it('is registered in the WIDGETS map', () => {
expect(ViewRef).toBeTypeOf('function');
});
it('renders a combobox trigger when views are available', () => {
render(
<ViewRef
value="default"
onChange={() => {}}
schema={{ type: 'string' }}
context={{ objectViews: [
{ name: 'default', label: 'All records' },
{ name: 'mine', label: 'My records' },
] }}
/>,
);
expect(screen.getByRole('combobox')).toBeInTheDocument();
});
it('renders (does not crash) when no source object / views are bound', () => {
render(
<ViewRef
value={undefined}
onChange={() => {}}
schema={{ type: 'string' }}
context={{ objectViews: [] }}
/>,
);
expect(screen.getByRole('combobox')).toBeInTheDocument();
});
it('renders with an out-of-catalog value without throwing (stale value survives)', () => {
render(
<ViewRef
value="renamed_view"
onChange={() => {}}
schema={{ type: 'string' }}
context={{ objectViews: [{ name: 'default', label: 'All records' }] }}
/>,
);
expect(screen.getByRole('combobox')).toBeInTheDocument();
});
});