|
|
|
@ -1,47 +1,37 @@ |
|
|
|
import { |
|
|
|
Router, |
|
|
|
RouteReuseStrategy, |
|
|
|
NavigationStart, |
|
|
|
NavigationEnd, |
|
|
|
NavigationError, |
|
|
|
} from '@angular/router'; |
|
|
|
import { createHostFactory, SpectatorHost, SpyObject } from '@ngneat/spectator/jest'; |
|
|
|
import { Actions, NgxsModule, Store } from '@ngxs/store'; |
|
|
|
import { Subject, Subscription, Observable, Subscriber, timer } from 'rxjs'; |
|
|
|
import { NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router'; |
|
|
|
import { createComponentFactory, Spectator, SpyObject } from '@ngneat/spectator/jest'; |
|
|
|
import { Subject, timer } from 'rxjs'; |
|
|
|
import { LoaderBarComponent } from '../components/loader-bar/loader-bar.component'; |
|
|
|
import { StartLoader, StopLoader, SubscriptionService } from '@abp/ng.core'; |
|
|
|
import { HttpWaitService, SubscriptionService } from '@abp/ng.core'; |
|
|
|
import { HttpRequest } from '@angular/common/http'; |
|
|
|
|
|
|
|
describe('LoaderBarComponent', () => { |
|
|
|
let spectator: SpectatorHost<LoaderBarComponent>; |
|
|
|
let spectator: Spectator<LoaderBarComponent>; |
|
|
|
let router: SpyObject<Router>; |
|
|
|
const events$ = new Subject(); |
|
|
|
|
|
|
|
const createHost = createHostFactory({ |
|
|
|
const createComponent = createComponentFactory({ |
|
|
|
component: LoaderBarComponent, |
|
|
|
mocks: [Router], |
|
|
|
imports: [NgxsModule.forRoot()], |
|
|
|
detectChanges: false, |
|
|
|
providers: [SubscriptionService], |
|
|
|
providers: [SubscriptionService, { provide: Router, useValue: { events: events$ } }], |
|
|
|
}); |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
spectator = createHost('<abp-loader-bar></abp-loader-bar>'); |
|
|
|
spectator = createComponent({}); |
|
|
|
spectator.component.intervalPeriod = 1; |
|
|
|
spectator.component.stopDelay = 1; |
|
|
|
router = spectator.inject(Router); |
|
|
|
(router as any).events = events$; |
|
|
|
}); |
|
|
|
|
|
|
|
it('should initial variable values are correct', () => { |
|
|
|
spectator.component.interval = new Subscription(); |
|
|
|
expect(spectator.component.containerClass).toBe('abp-loader-bar'); |
|
|
|
expect(spectator.component.color).toBe('#77b6ff'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should increase the progressLevel', done => { |
|
|
|
spectator.detectChanges(); |
|
|
|
spectator.inject(Store).dispatch(new StartLoader(new HttpRequest('GET', 'test'))); |
|
|
|
const httpWaitService = spectator.inject(HttpWaitService); |
|
|
|
httpWaitService.addRequest(new HttpRequest('GET', 'test')); |
|
|
|
spectator.detectChanges(); |
|
|
|
setTimeout(() => { |
|
|
|
expect(spectator.component.progressLevel > 0).toBeTruthy(); |
|
|
|
@ -51,7 +41,8 @@ describe('LoaderBarComponent', () => { |
|
|
|
|
|
|
|
test.skip('should be interval unsubscribed', done => { |
|
|
|
spectator.detectChanges(); |
|
|
|
spectator.inject(Store).dispatch(new StartLoader(new HttpRequest('GET', 'test'))); |
|
|
|
const httpWaitService = spectator.inject(HttpWaitService); |
|
|
|
httpWaitService.addRequest(new HttpRequest('GET', 'test')); |
|
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
|
|
|
|
|
timer(400).subscribe(() => { |
|
|
|
@ -62,11 +53,11 @@ describe('LoaderBarComponent', () => { |
|
|
|
|
|
|
|
it('should start and stop the loading with navigation', done => { |
|
|
|
spectator.detectChanges(); |
|
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
|
|
|
|
|
(router as any).events.next(new NavigationEnd(1, 'test', 'test')); |
|
|
|
(router as any).events.next(new NavigationError(1, 'test', 'test')); |
|
|
|
events$.next(new NavigationEnd(1, 'test', 'test')); |
|
|
|
events$.next(new NavigationError(1, 'test', 'test')); |
|
|
|
expect(spectator.component.progressLevel).toBe(100); |
|
|
|
|
|
|
|
timer(2).subscribe(() => { |
|
|
|
@ -77,10 +68,10 @@ describe('LoaderBarComponent', () => { |
|
|
|
|
|
|
|
it('should stop the loading with navigation', done => { |
|
|
|
spectator.detectChanges(); |
|
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
|
|
|
|
|
spectator.inject(Store).dispatch(new StopLoader(new HttpRequest('GET', 'test'))); |
|
|
|
events$.next(new NavigationEnd(1, 'testend', 'testend')); |
|
|
|
expect(spectator.component.progressLevel).toBe(100); |
|
|
|
|
|
|
|
timer(2).subscribe(() => { |
|
|
|
@ -92,8 +83,8 @@ describe('LoaderBarComponent', () => { |
|
|
|
describe('#startLoading', () => { |
|
|
|
it('should return when isLoading is true', done => { |
|
|
|
spectator.detectChanges(); |
|
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|