From 771810e1c0f6c3084a977b79301a578987975d4d Mon Sep 17 00:00:00 2001 From: Paul Mck Date: Fri, 22 Feb 2019 17:13:03 +0300 Subject: [PATCH] model details simple tests --- .../model-details.component.html | 29 +++---- .../model-details.component.scss | 2 +- .../model-details.component.spec.ts | 82 ++++++++++++++++++- .../model-details/model-details.component.ts | 11 +-- .../components/sidebar/sidebar.component.html | 1 - 5 files changed, 101 insertions(+), 24 deletions(-) diff --git a/src/modules/models/components/model-details/model-details.component.html b/src/modules/models/components/model-details/model-details.component.html index 9e8d8c5b..5b69427e 100644 --- a/src/modules/models/components/model-details/model-details.component.html +++ b/src/modules/models/components/model-details/model-details.component.html @@ -1,25 +1,20 @@
-
+
{{ (model$ | async)?.name }}
-
+
-
+
Versions
- - - Ooops! It looks like API does not return any builds for this model. Please check model. - - - - + +
@@ -36,7 +31,7 @@
Versions
- +
{{ modelVersion.id }}{{ modelVersion.modelVersion }} {{ modelVersion.started | utcToLocal | amTimeAgo }} @@ -53,13 +48,13 @@
Versions
- + {{appName}} - - + -
@@ -88,4 +83,10 @@
Versions
- \ No newline at end of file + + + + + Ooops! It looks like API does not return any builds for this model. Please check model. + + \ No newline at end of file diff --git a/src/modules/models/components/model-details/model-details.component.scss b/src/modules/models/components/model-details/model-details.component.scss index b73d488d..b0e4045a 100644 --- a/src/modules/models/components/model-details/model-details.component.scss +++ b/src/modules/models/components/model-details/model-details.component.scss @@ -3,7 +3,7 @@ .model-details { - >p { + > p { >span { font-weight: bold; } diff --git a/src/modules/models/components/model-details/model-details.component.spec.ts b/src/modules/models/components/model-details/model-details.component.spec.ts index 50f712c0..5413dc96 100644 --- a/src/modules/models/components/model-details/model-details.component.spec.ts +++ b/src/modules/models/components/model-details/model-details.component.spec.ts @@ -1,15 +1,25 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; +import { HydroServingState } from '@core/reducers'; import { DialogService } from '@dialog/dialog.service'; +import * as fromModels from '@models/reducers'; +import { Store, StoreModule, combineReducers } from '@ngrx/store'; import { SharedModule } from '@shared/shared.module'; +import { MockModel1 } from '@testing/factories/model'; +import { MockModelVersion1Model1, MockModelVersion2Model1 } from '@testing/factories/modelVersion'; import { MockStoreProvider } from '@testing/mocks'; import { MomentModule } from 'angular2-moment'; +import { of } from 'rxjs'; import { ModelDetailsComponent } from './model-details.component'; -describe('ModelDetailsComponent', () => { +import * as fromModelsActions from '@models/actions'; + +fdescribe('ModelDetailsComponent', () => { let component: ModelDetailsComponent; let fixture: ComponentFixture; + let element: HTMLElement; + let store: Store; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -20,18 +30,30 @@ describe('ModelDetailsComponent', () => { SharedModule, MomentModule, RouterTestingModule, + StoreModule.forRoot({ + feature: combineReducers(fromModels.reducers), + }), ], providers: [ MockStoreProvider, DialogService, ], - }) - .compileComponents(); + }).compileComponents(); + })); beforeEach(() => { fixture = TestBed.createComponent(ModelDetailsComponent); component = fixture.componentInstance; + element = fixture.nativeElement; + + store = TestBed.get(Store); + + spyOn(store, 'dispatch').and.callThrough(); + store.dispatch(new fromModelsActions.GetModelVersionsSuccessAction([MockModelVersion1Model1])); + + component.model$ = of(MockModel1); + fixture.detectChanges(); }); @@ -39,4 +61,58 @@ describe('ModelDetailsComponent', () => { expect(component).toBeTruthy(); }); + describe('header element', () => { + let headerElement: HTMLElement; + + beforeEach(() => { + headerElement = element.querySelector('.content-header'); + }); + + it('exists', () => { + expect(headerElement).toBeTruthy(); + }); + + it('has title element with models name', () => { + const title = headerElement.querySelector('.content-header__title'); + + expect(title).toBeTruthy(); + expect(title.textContent).toEqual(MockModel1.name); + }); + + it('has remove button', () => { + const button = headerElement.querySelector('button'); + + expect(button).toBeTruthy(); + }); + }); + + describe('versions block', () => { + let versionsElement: HTMLElement; + beforeEach(() => { + versionsElement = element.querySelector('.versions'); + }); + + it('exists', () => { + expect(versionsElement).toBeTruthy(); + }); + + describe('if modelVersions is empty', () => { + let errorElement: HTMLElement; + beforeEach(() => { + component.modelVersions$ = of([]); + fixture.detectChanges(); + errorElement = versionsElement.querySelector('span.alert'); + + }); + + it('shows error message element', () => { + expect(errorElement).toBeTruthy(); + }); + + it('shows error text', () => { + expect(errorElement.textContent) + .toEqual('Ooops! It looks like API does not return any builds for this model. Please check model. '); + }); + }); + }); }); diff --git a/src/modules/models/components/model-details/model-details.component.ts b/src/modules/models/components/model-details/model-details.component.ts index b4e2f7c4..5cc99bd7 100644 --- a/src/modules/models/components/model-details/model-details.component.ts +++ b/src/modules/models/components/model-details/model-details.component.ts @@ -2,14 +2,14 @@ import { Component, ChangeDetectionStrategy } from '@angular/core'; import { Store } from '@ngrx/store'; import { HydroServingState } from '@core/reducers'; -import { Model, ModelVersion } from '@shared/models/_index'; +import { Model, ModelVersion, IModel, IModelVersion } from '@shared/models/_index'; import * as fromModels from '@models/reducers'; import { Observable } from 'rxjs'; import { DialogService } from '@dialog/dialog.service'; import { DialogDeleteModelComponent, SELECTED_MODEL$ } from '@models/components/dialogs'; -import { switchMap, filter } from 'rxjs/operators'; +import { switchMap, filter, tap } from 'rxjs/operators'; @Component({ selector: 'hs-model-details', templateUrl: './model-details.component.html', @@ -17,15 +17,16 @@ import { switchMap, filter } from 'rxjs/operators'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class ModelDetailsComponent { - public model$: Observable; - public modelVersions$: Observable; + public model$: Observable; + public modelVersions$: Observable; constructor( private store: Store, private dialog: DialogService ) { this.model$ = this.store.select(fromModels.getSelectedModel).pipe( - filter(model => !!model)); + filter(model => !!model) + ); this.modelVersions$ = this.model$.pipe( switchMap(({id}) => this.store.select(fromModels.getModelVersionsByModelId(id))) diff --git a/src/modules/shared/components/sidebar/sidebar.component.html b/src/modules/shared/components/sidebar/sidebar.component.html index 1dad02a3..2ddf96fd 100644 --- a/src/modules/shared/components/sidebar/sidebar.component.html +++ b/src/modules/shared/components/sidebar/sidebar.component.html @@ -1,7 +1,6 @@