|
|
@ -1,33 +1,29 @@ |
|
|
import { NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router'; |
|
|
import { NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router'; |
|
|
import { createHostFactory, SpectatorHost, SpyObject } from '@ngneat/spectator/jest'; |
|
|
import { createComponentFactory, Spectator, SpyObject } from '@ngneat/spectator/jest'; |
|
|
import { Subject, Subscription, timer } from 'rxjs'; |
|
|
import { Subject, timer } from 'rxjs'; |
|
|
import { LoaderBarComponent } from '../components/loader-bar/loader-bar.component'; |
|
|
import { LoaderBarComponent } from '../components/loader-bar/loader-bar.component'; |
|
|
import { SubscriptionService } from '@abp/ng.core'; |
|
|
import { HttpWaitService, SubscriptionService } from '@abp/ng.core'; |
|
|
import { HttpRequest } from '@angular/common/http'; |
|
|
import { HttpRequest } from '@angular/common/http'; |
|
|
import { HttpWaitService } from '../../../../core/src/lib/services'; |
|
|
|
|
|
|
|
|
|
|
|
describe('LoaderBarComponent', () => { |
|
|
describe('LoaderBarComponent', () => { |
|
|
let spectator: SpectatorHost<LoaderBarComponent>; |
|
|
let spectator: Spectator<LoaderBarComponent>; |
|
|
let router: SpyObject<Router>; |
|
|
let router: SpyObject<Router>; |
|
|
const events$ = new Subject(); |
|
|
const events$ = new Subject(); |
|
|
|
|
|
|
|
|
const createHost = createHostFactory({ |
|
|
const createComponent = createComponentFactory({ |
|
|
component: LoaderBarComponent, |
|
|
component: LoaderBarComponent, |
|
|
mocks: [Router], |
|
|
|
|
|
detectChanges: false, |
|
|
detectChanges: false, |
|
|
providers: [SubscriptionService], |
|
|
providers: [SubscriptionService, { provide: Router, useValue: { events: events$ } }], |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
spectator = createHost('<abp-loader-bar></abp-loader-bar>'); |
|
|
spectator = createComponent({}); |
|
|
spectator.component.intervalPeriod = 1; |
|
|
spectator.component.intervalPeriod = 1; |
|
|
spectator.component.stopDelay = 1; |
|
|
spectator.component.stopDelay = 1; |
|
|
router = spectator.inject(Router); |
|
|
router = spectator.inject(Router); |
|
|
(router as any).events = events$; |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should initial variable values are correct', () => { |
|
|
it('should initial variable values are correct', () => { |
|
|
spectator.component.interval = new Subscription(); |
|
|
|
|
|
expect(spectator.component.containerClass).toBe('abp-loader-bar'); |
|
|
expect(spectator.component.containerClass).toBe('abp-loader-bar'); |
|
|
expect(spectator.component.color).toBe('#77b6ff'); |
|
|
expect(spectator.component.color).toBe('#77b6ff'); |
|
|
}); |
|
|
}); |
|
|
@ -57,11 +53,11 @@ describe('LoaderBarComponent', () => { |
|
|
|
|
|
|
|
|
it('should start and stop the loading with navigation', done => { |
|
|
it('should start and stop the loading with navigation', done => { |
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
|
|
|
|
|
|
(router as any).events.next(new NavigationEnd(1, 'test', 'test')); |
|
|
events$.next(new NavigationEnd(1, 'test', 'test')); |
|
|
(router as any).events.next(new NavigationError(1, 'test', 'test')); |
|
|
events$.next(new NavigationError(1, 'test', 'test')); |
|
|
expect(spectator.component.progressLevel).toBe(100); |
|
|
expect(spectator.component.progressLevel).toBe(100); |
|
|
|
|
|
|
|
|
timer(2).subscribe(() => { |
|
|
timer(2).subscribe(() => { |
|
|
@ -72,10 +68,10 @@ describe('LoaderBarComponent', () => { |
|
|
|
|
|
|
|
|
it('should stop the loading with navigation', done => { |
|
|
it('should stop the loading with navigation', done => { |
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
expect(spectator.component.interval.closed).toBe(false); |
|
|
|
|
|
|
|
|
(router as any).events.next(new NavigationEnd(1, 'testend', 'testend')); |
|
|
events$.next(new NavigationEnd(1, 'testend', 'testend')); |
|
|
expect(spectator.component.progressLevel).toBe(100); |
|
|
expect(spectator.component.progressLevel).toBe(100); |
|
|
|
|
|
|
|
|
timer(2).subscribe(() => { |
|
|
timer(2).subscribe(() => { |
|
|
@ -87,8 +83,8 @@ describe('LoaderBarComponent', () => { |
|
|
describe('#startLoading', () => { |
|
|
describe('#startLoading', () => { |
|
|
it('should return when isLoading is true', done => { |
|
|
it('should return when isLoading is true', done => { |
|
|
spectator.detectChanges(); |
|
|
spectator.detectChanges(); |
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
(router as any).events.next(new NavigationStart(1, 'test')); |
|
|
events$.next(new NavigationStart(1, 'test')); |
|
|
done(); |
|
|
done(); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|