From 47b7b8c4e0a22453dd55b27e5e4007233cf6d6e4 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Fri, 10 Jul 2020 11:34:08 +0200 Subject: [PATCH] mgr/dashboard: Add hosts page unit tests Fixes: https://tracker.ceph.com/issues/46448 Signed-off-by: Volker Theile (cherry picked from commit f2270d901853d6dc0620bb1b23d64df51c5683f0) Conflicts: src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts Trivial - small conflict in import section. --- .../cluster/hosts/hosts.component.spec.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts index 5b16f2b41805f..05f3d962f0e40 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts @@ -3,6 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; +import * as _ from 'lodash'; import { BsDropdownModule } from 'ngx-bootstrap/dropdown'; import { TabsModule } from 'ngx-bootstrap/tabs'; import { ToastrModule } from 'ngx-toastr'; @@ -11,6 +12,8 @@ import { of } from 'rxjs'; import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; import { CoreModule } from '../../../core/core.module'; import { HostService } from '../../../shared/api/host.service'; +import { ActionLabels } from '../../../shared/constants/app.constants'; +import { CdTableAction } from '../../../shared/models/cd-table-action'; import { Permissions } from '../../../shared/models/permissions'; import { AuthStorageService } from '../../../shared/services/auth-storage.service'; import { SharedModule } from '../../../shared/shared.module'; @@ -93,30 +96,39 @@ describe('HostsComponent', () => { }); })); - describe('getEditDisableDesc', () => { - it('should return message (not managed by Orchestrator)', () => { + describe('test edit button', () => { + let tableAction: CdTableAction; + + beforeEach(() => { + tableAction = _.find(component.tableActions, { name: ActionLabels.EDIT }); + }); + + it('should disable button and return message (not managed by Orchestrator)', () => { component.selection.add({ sources: { ceph: true, orchestrator: false } }); + expect(tableAction.disable(component.selection)).toBeTruthy(); expect(component.getEditDisableDesc(component.selection)).toBe( 'Host editing is disabled because the host is not managed by Orchestrator.' ); }); - it('should return undefined (no selection)', () => { + it('should disable button and return undefined (no selection)', () => { + expect(tableAction.disable(component.selection)).toBeTruthy(); expect(component.getEditDisableDesc(component.selection)).toBeUndefined(); }); - it('should return undefined (managed by Orchestrator)', () => { + it('should enable button and return undefined (managed by Orchestrator)', () => { component.selection.add({ sources: { ceph: false, orchestrator: true } }); + expect(tableAction.disable(component.selection)).toBeFalsy(); expect(component.getEditDisableDesc(component.selection)).toBeUndefined(); }); }); -- 2.39.5