-
Notifications
You must be signed in to change notification settings - Fork 390
/
Copy pathOneOfRenderer.spec.ts
80 lines (72 loc) · 2.29 KB
/
OneOfRenderer.spec.ts
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
import { describe, it, expect, beforeEach } from 'vitest';
import { seedIds, type Translator } from '@jsonforms/core';
import OneOfControlRenderer from '../../../src/complex/OneOfRenderer.vue';
import { entry as oneOfControlRendererEntry } from '../../../src/complex/OneOfRenderer.entry';
import { mountJsonForms } from '../util';
describe('OneOfRenderer.vue', () => {
const renderers = [oneOfControlRendererEntry];
const data: unknown[] = [[{ name: 'foo', done: false }]];
const schema = {
oneOf: [
{
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string' },
done: { type: 'boolean' },
},
},
},
{
type: 'object',
properties: {
name: { type: 'string' },
done: { type: 'boolean' },
},
},
],
};
const uischema = {
type: 'Control',
scope: '#',
};
let wrapper: ReturnType<typeof mountJsonForms>;
beforeEach(() => {
// clear all ids to guarantee that the snapshots will always be generated with the same ids
seedIds();
wrapper = mountJsonForms(data, schema, renderers, uischema, undefined, {
translate: ((id, defaultMessage) => {
if (id.endsWith('clearDialogAccept')) {
return 'Do the clear!';
}
return defaultMessage;
}) as Translator,
});
});
it('check if child OneOfControl exists', () => {
expect(wrapper.getComponent(OneOfControlRenderer));
});
it('respects translations', async () => {
// trigger the selection change
wrapper.getComponent(OneOfControlRenderer).vm.handleSelectChange();
// wait until the dialog is rendered
await wrapper.vm.$nextTick();
// dialog is rendered in document outside of the wrapper
expect(document.querySelector('[role="dialog"]')).not.toBeNull();
// search for text in children of the add buton
let found = false;
document
.querySelector('[data-testid="clear-dialog-accept"]')
?.querySelectorAll('*')
.forEach((el) => {
if (el.textContent?.includes('Do the clear!')) {
found = true;
}
});
expect(found).toBeTruthy();
});
it('should render component and match snapshot', () => {
expect(wrapper.html()).toMatchSnapshot();
});
});