From af45f4778324ab78659be7d882e0650b3570e1d5 Mon Sep 17 00:00:00 2001 From: alfonsomthd Date: Tue, 2 Oct 2018 12:08:21 +0200 Subject: [PATCH] mgr/dashboard: New Landing Page: Milestone 2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Added tests for InfoCard & InfoGroup components. Fixes: https://tracker.ceph.com/issues/27050 Signed-off-by: Alfonso Martínez --- .../info-card/info-card.component.spec.ts | 42 ++++++++++++++++++- .../info-card/info-card.component.ts | 2 - .../info-group/info-group.component.spec.ts | 10 ++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.spec.ts index 70a98416d0c..f5492508d1d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.spec.ts @@ -17,10 +17,50 @@ describe('InfoCardComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(InfoCardComponent); component = fixture.componentInstance; - fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + + it('Setting cardTitle makes title visible', () => { + const cardTitle = 'Card Title'; + component.cardTitle = cardTitle; + fixture.detectChanges(); + const titleDiv = fixture.debugElement.nativeElement.querySelector('.card-title'); + + expect(titleDiv.textContent).toContain(cardTitle); + }); + + it('Setting link makes anchor visible', () => { + const cardTitle = 'Card Title'; + const link = '/dashboard'; + component.cardTitle = cardTitle; + component.link = link; + fixture.detectChanges(); + const anchor = fixture.debugElement.nativeElement + .querySelector('.card-title') + .querySelector('a'); + + expect(anchor.textContent).toContain(cardTitle); + expect(anchor.href).toBe(`http://localhost${link}`); + }); + + it('Setting cardClass makes class set', () => { + const cardClass = 'my-css-card-class'; + component.cardClass = cardClass; + fixture.detectChanges(); + const card = fixture.debugElement.nativeElement.querySelector(`.card.${cardClass}`); + + expect(card).toBeTruthy(); + }); + + it('Setting contentClass makes class set', () => { + const contentClass = 'my-css-content-class'; + component.contentClass = contentClass; + fixture.detectChanges(); + const card = fixture.debugElement.nativeElement.querySelector(`.card-body.${contentClass}`); + + expect(card).toBeTruthy(); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.ts index 8bb7f8ed2e2..fdcbe2ecea5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-card/info-card.component.ts @@ -13,7 +13,5 @@ export class InfoCardComponent { @Input() cardClass = ''; @Input() - imageClass: string; - @Input() contentClass: string; } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-group/info-group.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-group/info-group.component.spec.ts index 22944038a61..0bb0abb5c45 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-group/info-group.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/info-group/info-group.component.spec.ts @@ -15,10 +15,18 @@ describe('InfoGroupComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(InfoGroupComponent); component = fixture.componentInstance; - fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); + + it('Setting groupTitle makes title visible', () => { + const groupTitle = 'Group Title'; + component.groupTitle = groupTitle; + fixture.detectChanges(); + const titleDiv = fixture.debugElement.nativeElement.querySelector('.info-group-title'); + + expect(titleDiv.textContent).toContain(groupTitle); + }); }); -- 2.39.5