Skip to content

Commit e2450f3

Browse files
fix: array layout renderer error count fix
1 parent f815e1c commit e2450f3

File tree

2 files changed

+149
-1
lines changed

2 files changed

+149
-1
lines changed

packages/angular-material/src/library/layouts/array-layout.renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
<mat-icon
6161
*ngIf="this.error?.length"
6262
color="warn"
63-
matBadge="{{ this.error.split('').length }}"
63+
matBadge="{{ this.error.split('\\n').length }}"
6464
matBadgeColor="warn"
6565
matTooltip="{{ this.error }}"
6666
matTooltipClass="error-message-tooltip"
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
The MIT License
3+
4+
Copyright (c) 2017-2019 EclipseSource Munich
5+
https://github.com/eclipsesource/jsonforms
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
*/
25+
import { ComponentFixture, waitForAsync } from '@angular/core/testing';
26+
import { UISchemaElement } from '@jsonforms/core';
27+
import { beforeEachLayoutTest, setupMockStore } from './common';
28+
import {
29+
ArrayLayoutRenderer,
30+
ArrayLayoutRendererTester,
31+
} from '../src/library/layouts/array-layout.renderer';
32+
import { LayoutChildrenRenderPropsPipe } from '../src/library/layouts/layout.renderer';
33+
34+
const TEST_SCHEMA = {
35+
type: 'object',
36+
properties: {
37+
test: {
38+
type: 'array',
39+
minItems: 1,
40+
items: {
41+
type: 'object',
42+
properties: {
43+
test1: {
44+
type: 'string',
45+
title: 'Test 1',
46+
},
47+
test2: {
48+
type: 'string',
49+
title: 'Test 2',
50+
$dataciteRequired: false,
51+
},
52+
},
53+
},
54+
},
55+
},
56+
required: ['test'],
57+
};
58+
59+
describe('Array layout tester', () => {
60+
it('should succeed', () => {
61+
expect(ArrayLayoutRendererTester(undefined, undefined)).toBe(1);
62+
});
63+
});
64+
describe.only('Array layout', () => {
65+
let fixture: ComponentFixture<any>;
66+
67+
beforeEach(waitForAsync(() => {
68+
fixture = beforeEachLayoutTest(ArrayLayoutRenderer, {
69+
declarations: [LayoutChildrenRenderPropsPipe],
70+
});
71+
}));
72+
73+
it('render with undefined elements', () => {
74+
const uischema: UISchemaElement = {
75+
type: 'Control',
76+
scope: '#/properties/test',
77+
};
78+
setupMockStore(fixture, {
79+
data: {},
80+
schema: TEST_SCHEMA,
81+
uischema,
82+
});
83+
fixture.componentInstance.ngOnInit();
84+
fixture.detectChanges();
85+
expect(fixture.nativeElement.children[0].children.length).toBe(0);
86+
});
87+
88+
it('render with null elements', () => {
89+
const uischema = {
90+
type: 'Control',
91+
elements: null,
92+
};
93+
setupMockStore(fixture, {
94+
data: {},
95+
schema: TEST_SCHEMA,
96+
uischema,
97+
});
98+
fixture.componentInstance.ngOnInit();
99+
fixture.detectChanges();
100+
expect(fixture.nativeElement.children[0].children.length).toBe(0);
101+
});
102+
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+
};
128+
setupMockStore(fixture, {
129+
data: {},
130+
schema: TEST_SCHEMA,
131+
uischema,
132+
});
133+
fixture.componentInstance.ngOnInit();
134+
fixture.detectChanges();
135+
expect(fixture.nativeElement.children[0].children.length).toBe(2);
136+
expect(fixture.nativeElement.children[0].hidden).toBe(false);
137+
138+
fixture.whenRenderingDone().then(() => {
139+
fixture.detectChanges();
140+
141+
const arrayLayoutElement: HTMLElement = fixture.nativeElement;
142+
const matBadgeElement =
143+
arrayLayoutElement.querySelector('.mat-badge-content')!;
144+
145+
expect(matBadgeElement.textContent).toBe('1');
146+
});
147+
});
148+
});

0 commit comments

Comments
 (0)