Skip to content

Commit 1856c34

Browse files
fix the array layout tests
1 parent e2450f3 commit 1856c34

File tree

1 file changed

+79
-49
lines changed

1 file changed

+79
-49
lines changed

packages/angular-material/test/array-layout.spec.ts

Lines changed: 79 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@
2323
THE SOFTWARE.
2424
*/
2525
import { ComponentFixture, waitForAsync } from '@angular/core/testing';
26-
import { UISchemaElement } from '@jsonforms/core';
26+
import { MatIcon } from '@angular/material/icon';
27+
import { MatBadge } from '@angular/material/badge';
28+
import { MatTooltip } from '@angular/material/tooltip';
29+
import {
30+
MatCard,
31+
MatCardContent,
32+
MatCardActions,
33+
} from '@angular/material/card';
2734
import { beforeEachLayoutTest, setupMockStore } from './common';
2835
import {
2936
ArrayLayoutRenderer,
@@ -47,93 +54,116 @@ const TEST_SCHEMA = {
4754
test2: {
4855
type: 'string',
4956
title: 'Test 2',
50-
$dataciteRequired: false,
5157
},
5258
},
59+
required: ['test1', 'test2'],
5360
},
5461
},
5562
},
5663
required: ['test'],
5764
};
5865

66+
const TEST_UISCHEMA = {
67+
type: 'Control',
68+
scope: '#/properties/test',
69+
options: {
70+
detail: {
71+
type: 'HorizontalLayout',
72+
elements: [
73+
{
74+
type: 'Control',
75+
scope: '#/properties/test1',
76+
},
77+
{
78+
type: 'Control',
79+
scope: '#/properties/test2',
80+
},
81+
],
82+
},
83+
},
84+
};
85+
5986
describe('Array layout tester', () => {
6087
it('should succeed', () => {
61-
expect(ArrayLayoutRendererTester(undefined, undefined)).toBe(1);
88+
expect(
89+
ArrayLayoutRendererTester(TEST_UISCHEMA, TEST_SCHEMA, {
90+
config: {},
91+
rootSchema: {},
92+
})
93+
).toBe(4);
6294
});
6395
});
64-
describe.only('Array layout', () => {
96+
describe('Array layout', () => {
6597
let fixture: ComponentFixture<any>;
6698

6799
beforeEach(waitForAsync(() => {
68100
fixture = beforeEachLayoutTest(ArrayLayoutRenderer, {
69101
declarations: [LayoutChildrenRenderPropsPipe],
102+
imports: [
103+
MatIcon,
104+
MatBadge,
105+
MatTooltip,
106+
MatCard,
107+
MatCardContent,
108+
MatCardActions,
109+
],
70110
});
71111
}));
72112

73-
it('render with undefined elements', () => {
74-
const uischema: UISchemaElement = {
75-
type: 'Control',
76-
scope: '#/properties/test',
77-
};
113+
it('render with no data the error count should be 1', () => {
78114
setupMockStore(fixture, {
79115
data: {},
80116
schema: TEST_SCHEMA,
81-
uischema,
117+
uischema: TEST_UISCHEMA,
82118
});
83119
fixture.componentInstance.ngOnInit();
84120
fixture.detectChanges();
85-
expect(fixture.nativeElement.children[0].children.length).toBe(0);
121+
expect(fixture.nativeElement.children[0].children.length).toBe(2);
122+
123+
fixture.whenRenderingDone().then(() => {
124+
fixture.detectChanges();
125+
126+
const arrayLayoutElement: HTMLElement = fixture.nativeElement;
127+
const matBadgeElement =
128+
arrayLayoutElement.querySelector('.mat-badge-content')!;
129+
130+
const noDataElement = arrayLayoutElement.children[0].children[1];
131+
132+
expect(matBadgeElement.textContent).toBe('1');
133+
expect(noDataElement.textContent).toBe('No data');
134+
});
86135
});
87136

88-
it('render with null elements', () => {
89-
const uischema = {
90-
type: 'Control',
91-
elements: null,
92-
};
137+
it('render with data that contains empty required fields should show proper error count', () => {
93138
setupMockStore(fixture, {
94-
data: {},
139+
data: { test: [{}] },
95140
schema: TEST_SCHEMA,
96-
uischema,
141+
uischema: TEST_UISCHEMA,
97142
});
98143
fixture.componentInstance.ngOnInit();
99144
fixture.detectChanges();
100-
expect(fixture.nativeElement.children[0].children.length).toBe(0);
145+
expect(fixture.nativeElement.children[0].children.length).toBe(2);
146+
147+
fixture.whenRenderingDone().then(() => {
148+
fixture.detectChanges();
149+
150+
const arrayLayoutElement: HTMLElement = fixture.nativeElement;
151+
const matBadgeElement =
152+
arrayLayoutElement.querySelector('.mat-badge-content')!;
153+
154+
expect(matBadgeElement.textContent).toBe('2');
155+
});
101156
});
102157

103-
it('render with children', () => {
104-
const uischema = {
105-
type: 'VerticalLayout',
106-
elements: [
107-
{
108-
type: 'Control',
109-
scope: '#/properties/test',
110-
options: {
111-
detail: {
112-
type: 'HorizontalLayout',
113-
elements: [
114-
{
115-
type: 'Control',
116-
scope: '#/properties/test1',
117-
},
118-
{
119-
type: 'Control',
120-
scope: '#/properties/test2',
121-
},
122-
],
123-
},
124-
},
125-
},
126-
],
127-
};
158+
it('render with more data that contains empty required fields should show proper error count', () => {
128159
setupMockStore(fixture, {
129-
data: {},
160+
data: { test: [{}, {}] },
130161
schema: TEST_SCHEMA,
131-
uischema,
162+
uischema: TEST_UISCHEMA,
132163
});
133164
fixture.componentInstance.ngOnInit();
134165
fixture.detectChanges();
135-
expect(fixture.nativeElement.children[0].children.length).toBe(2);
136-
expect(fixture.nativeElement.children[0].hidden).toBe(false);
166+
expect(fixture.nativeElement.children[0].children.length).toBe(3);
137167

138168
fixture.whenRenderingDone().then(() => {
139169
fixture.detectChanges();
@@ -142,7 +172,7 @@ describe.only('Array layout', () => {
142172
const matBadgeElement =
143173
arrayLayoutElement.querySelector('.mat-badge-content')!;
144174

145-
expect(matBadgeElement.textContent).toBe('1');
175+
expect(matBadgeElement.textContent).toBe('4');
146176
});
147177
});
148178
});

0 commit comments

Comments
 (0)