Skip to content

Commit

Permalink
chore(ui): Add some ng test (chutney-testing#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrouand authored Mar 23, 2020
1 parent afe7179 commit 8a9de8a
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
server/conf/
/backups
.env/
/ui/coverage

######################
# Chutney persistence dir
Expand Down
9 changes: 8 additions & 1 deletion ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"stylePreprocessorOptions": {
"includePaths": [
"src/styles"
]
},
"styles": [
"src/styles/vendor.scss",
"src/styles/global.scss",
"src/styles/forms.scss",
"src/styles/tags.scss",
"src/styles/themes/default.theme.scss"
],
"scripts": [],
"scripts": [
"node_modules/asciidoctor.js/dist/asciidoctor.min.js"
],
"assets": [
"src/assets",
"src/manifest.json",
Expand Down
25 changes: 25 additions & 0 deletions ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { TestBed, async, getTestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { TranslateModule } from '@ngx-translate/core';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
TranslateModule.forRoot()
],
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', () => {

const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});
30 changes: 30 additions & 0 deletions ui/src/app/core/services/backups.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { BackupsService, BackupDto } from './backups.service';
import { Backup } from '@core/model/backups.model';
import { of } from 'rxjs';

describe('BackupsService', () => {

let sut: BackupsService;
let httpClientSpy: { get: jasmine.Spy };

beforeEach(() => {
httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']);
sut = new BackupsService(<any> httpClientSpy);
});

it('should return expected backups (HttpClient called once)', () => {
const expectedBackups: BackupDto[] =
[new BackupDto(true, true, true, true, true)];

httpClientSpy.get.and.returnValue(of(expectedBackups));

sut.list().subscribe(
backups => expect(backups).toEqual([new Backup(true, true, true, true, true)], 'expected backups'),
fail
);
expect(httpClientSpy.get.calls.count()).toBe(1, 'one call');
});
});



Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

<div class="row">
<ng-container *ngIf="!listView">
<div class="d-flex mr-auto ml-3"
<div id="cards" class="d-flex mr-auto ml-3"
*ngFor="let scenario of (scenarii | scenarioSearch : tagData.selected() : scenarioTypeData.selected() : tagData.isNoTagSelected() : tagData.isSelectAll() | searchTextPipe : scenariiFilter : ['title', 'description'] | sortByField : sortField : asc)">
<chutney-scenario-card [scenario]="scenario"></chutney-scenario-card>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { ScenariiComponent } from './scenarii.component';
import { SharedModule } from '@shared/shared.module';

import { MoleculesModule } from '../../../../molecules/molecules.module';

import { MomentModule } from 'angular2-moment';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { of } from 'rxjs';
import { ScenarioIndex } from '@core/model';
import { ScenarioService } from '@core/services';

describe('ScenariiComponent', () => {

beforeEach(async(() => {
TestBed.resetTestingModule();
const scenarioService = jasmine.createSpyObj('ScenarioService', ['findScenarios']);
const mockScenarioIndex = [new ScenarioIndex('1', 'title1', 'description', 'source', new Date(), [], []),
new ScenarioIndex('2', 'title2', 'description', 'source', new Date(), [], [])];
scenarioService.findScenarios.and.returnValue(of(mockScenarioIndex));
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
TranslateModule.forRoot(),
MoleculesModule,
SharedModule,
MomentModule,
NgbModule
],
declarations: [
ScenariiComponent
],
providers: [
{ provide: ScenarioService, useValue: scenarioService }
]
}).compileComponents();
}));

it('should create the component ScenariiComponent with two scenarios', () => {
const fixture = TestBed.createComponent(ScenariiComponent);
fixture.detectChanges();

const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();

const html: HTMLElement = fixture.nativeElement;
const cards = html.querySelectorAll('#cards > chutney-scenario-card');

expect(cards.length).toBe(2);
expect(cards[0].querySelector('.scenario-title').textContent).toBe('title1');
expect(cards[1].querySelector('.scenario-title').textContent).toBe('title2');
expect(fixture.componentInstance.scenarii.length).toBe(2);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { EventManagerService } from '@shared/event-manager.service';
import { ScenarioService } from '@core/services';
import { SelectableTags, ScenarioIndex, ScenarioType } from '@model';
import { distinct, flatMap } from '@shared/tools/array-utils';
Expand Down Expand Up @@ -30,7 +29,6 @@ export class ScenariiComponent implements OnInit {
constructor(
private router: Router,
private scenarioService: ScenarioService,
private eventManager: EventManagerService,
private stateService: StateService
) {
}
Expand Down
1 change: 0 additions & 1 deletion ui/src/app/modules/scenarios/scenario.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
ComponentEditionComponent,
ExecuteComponent,
HeaderComponent,

],
providers: [
{
Expand Down
25 changes: 0 additions & 25 deletions ui/src/app/organisms/step/step.component.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions ui/src/app/organisms/step/step.module.spec.ts

This file was deleted.

25 changes: 0 additions & 25 deletions ui/src/app/organisms/step/substep/substep.component.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ui/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone-testing';
import { getTestBed, TestBed } from '@angular/core/testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
Expand Down

0 comments on commit 8a9de8a

Please sign in to comment.