diff --git a/packages/angular-material/src/library/layouts/array-layout.renderer.ts b/packages/angular-material/src/library/layouts/array-layout.renderer.ts index 569b92075b..846af7277d 100644 --- a/packages/angular-material/src/library/layouts/array-layout.renderer.ts +++ b/packages/angular-material/src/library/layouts/array-layout.renderer.ts @@ -60,7 +60,7 @@ import { { + it('should succeed', () => { + expect( + ArrayLayoutRendererTester(TEST_UISCHEMA, TEST_SCHEMA, { + config: {}, + rootSchema: {}, + }) + ).toBe(4); + }); +}); +describe('Array layout', () => { + let fixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + fixture = beforeEachLayoutTest(ArrayLayoutRenderer, { + declarations: [LayoutChildrenRenderPropsPipe], + imports: [ + MatIcon, + MatBadge, + MatTooltip, + MatCard, + MatCardContent, + MatCardActions, + ], + }); + })); + + it('render with no data the error count should be 1', () => { + setupMockStore(fixture, { + data: {}, + schema: TEST_SCHEMA, + uischema: TEST_UISCHEMA, + }); + fixture.componentInstance.ngOnInit(); + fixture.detectChanges(); + expect(fixture.nativeElement.children[0].children.length).toBe(2); + + fixture.whenRenderingDone().then(() => { + fixture.detectChanges(); + + const arrayLayoutElement: HTMLElement = fixture.nativeElement; + const matBadgeElement = + arrayLayoutElement.querySelector('.mat-badge-content')!; + + const noDataElement = arrayLayoutElement.children[0].children[1]; + + expect(matBadgeElement.textContent).toBe('1'); + expect(noDataElement.textContent).toBe('No data'); + }); + }); + + it('render with data that contains empty required fields should show proper error count', () => { + setupMockStore(fixture, { + data: { test: [{}] }, + schema: TEST_SCHEMA, + uischema: TEST_UISCHEMA, + }); + fixture.componentInstance.ngOnInit(); + fixture.detectChanges(); + expect(fixture.nativeElement.children[0].children.length).toBe(2); + + fixture.whenRenderingDone().then(() => { + fixture.detectChanges(); + + const arrayLayoutElement: HTMLElement = fixture.nativeElement; + const matBadgeElement = + arrayLayoutElement.querySelector('.mat-badge-content')!; + + expect(matBadgeElement.textContent).toBe('2'); + }); + }); + + it('render with more data that contains empty required fields should show proper error count', () => { + setupMockStore(fixture, { + data: { test: [{}, {}] }, + schema: TEST_SCHEMA, + uischema: TEST_UISCHEMA, + }); + fixture.componentInstance.ngOnInit(); + fixture.detectChanges(); + expect(fixture.nativeElement.children[0].children.length).toBe(3); + + fixture.whenRenderingDone().then(() => { + fixture.detectChanges(); + + const arrayLayoutElement: HTMLElement = fixture.nativeElement; + const matBadgeElement = + arrayLayoutElement.querySelector('.mat-badge-content')!; + + expect(matBadgeElement.textContent).toBe('4'); + }); + }); +});