Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  fix: update Test
  • Loading branch information
osahner committed Dec 15, 2017
2 parents 97a7080 + 59babfd commit f7a8464
Showing 1 changed file with 72 additions and 49 deletions.
121 changes: 72 additions & 49 deletions src/http-client-busy.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { async, ComponentFixture, fakeAsync, inject, TestBed } from '@angular/core/testing';
import { Component } from '@angular/core';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule, HttpHeaders } from '@angular/common/http';
import { CounterService, HttpClientBusyInterceptor, HttpClientBusyModule } from './index';
import { By } from '@angular/platform-browser';
import { CounterService, HttpClientBusyDirective, HttpClientBusyInterceptor, HttpClientBusyModule } from './index';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { HttpClientBusyDirective } from './http-client-busy.directive';

@Component({
selector: 'test-cmp',
Expand All @@ -17,61 +21,80 @@ class TestComponent {
}

describe('HttpClientBusyDirective', () => {
let http: HttpClient;
let fixture: ComponentFixture<TestComponent>;
let component: TestComponent;

beforeEach(
() => {
TestBed.configureTestingModule({
declarations: [
TestComponent
],
imports: [
HttpClientTestingModule,
HttpClientModule,
HttpClientBusyModule
],
providers: [
CounterService,
{ provide: HTTP_INTERCEPTORS, useClass: HttpClientBusyInterceptor, multi: true }
]
}).compileComponents().then(() => {
});
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent
],
imports: [
HttpClientModule,
HttpClientBusyModule
],
providers: [
CounterService,
{ provide: HTTP_INTERCEPTORS, useClass: HttpClientBusyInterceptor, multi: true }
]
});
TestBed.compileComponents();
}));

beforeEach(inject([HttpClient], (s: HttpClient) => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
http = s;
fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
}));

it('init directive', fakeAsync(() => {
// fixture = TestBed.overrideTemplate(TestComponent,
// `<div [httpClientBusy]="{ busy: 'busy', idle: 'idle' }"></div>`).createComponent(TestComponent);
fixture.detectChanges();
tick(100);
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));
expect(directiveEl).not.toBeNull();
})
);

const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));
expect(directiveEl).not.toBeNull();
// const directiveInstance = directiveEl.injector.get(HttpClientBusyDirective);
}));
it('update directive class',
async(() => {
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));

// TODO Get the HttpClient Test running
/*it('update directive', inject([HttpClient], (http: HttpClient) => {
fixture.detectChanges();
tick(100);
http.put('https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.subscribe(() => {
expect(directiveEl.nativeElement.classList.contains('idle'))
.toBe(true, 'should contain idle class');
});

setTimeout(function () {
expect(directiveEl.nativeElement.classList.contains('busy'))
.toBe(true, 'should contain busy class');
}, 500)

})
);

const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));
expect(directiveEl).not.toBeNull();
it('handle errors',
async(() => {
const directiveEl = fixture.debugElement.query(By.directive(HttpClientBusyDirective));

http.put('https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=2s', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.subscribe(() => {
console.error('longrunning done');
});
http.put('http://www.mocky.io/v2/5a2fae752d00009614a83b2f?mocky-delay=1s', {
headers: new HttpHeaders().set('Accept', 'application/json')
})
.catch(() => {
return Observable.of({});
})
.subscribe(() => {
expect(directiveEl.nativeElement.classList.contains('idle'))
.toBe(true, 'should contain idle class');
});

flushMicrotasks();
tick(100);
setTimeout(function () {
expect(directiveEl.nativeElement.classList.contains('busy'))
.toBe(true, 'should contain busy class');
}, 500)

expect(directiveEl).not.toBeNull();
}));*/
})
);
});

0 comments on commit f7a8464

Please sign in to comment.