@@ -12,11 +12,11 @@ import { SpinnerComponent } from '../../../src/components/spinner/spinner.compon
1212import { By } from '@angular/platform-browser' ;
1313import { Spinkit , SPINKIT_COMPONENTS } from '../../../src/spinkits' ;
1414import { Observable } from 'rxjs/Observable' ;
15- import { PendingInterceptorService } from '../../../src/services/pending-interceptor.service' ;
1615import { HttpClient } from '@angular/common/http' ;
1716import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
1817import { NgHttpLoaderServicesModule } from '../../../src/services/ng-http-loader-services.module' ;
1918import 'rxjs/add/observable/forkJoin' ;
19+ import { SpinnerVisibilityService } from '../../../src/services/spinner-visibility.service' ;
2020
2121describe ( 'SpinnerComponent' , ( ) => {
2222 let component : SpinnerComponent ;
@@ -99,8 +99,7 @@ describe('SpinnerComponent', () => {
9999 } ) ;
100100
101101 it ( 'should show and hide the spinner according to the pending http requests' , fakeAsync ( inject (
102- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
103- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
102+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
104103
105104 function runQuery ( url : string ) : Observable < any > {
106105 return http . get ( url ) ;
@@ -125,8 +124,7 @@ describe('SpinnerComponent', () => {
125124 ) ) ) ;
126125
127126 it ( 'should hide and show a the spinner for a single http request' , fakeAsync ( inject (
128- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
129- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
127+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
130128 http . get ( '/fake' ) . subscribe ( ) ;
131129
132130 tick ( ) ;
@@ -139,8 +137,7 @@ describe('SpinnerComponent', () => {
139137 ) ) ) ;
140138
141139 it ( 'should not show the spinner if the request is filtered' , fakeAsync ( inject (
142- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
143- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
140+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
144141 component . filteredUrlPatterns . push ( 'fake' ) ;
145142 fixture . detectChanges ( ) ;
146143
@@ -152,8 +149,7 @@ describe('SpinnerComponent', () => {
152149 ) ) ) ;
153150
154151 it ( 'should take care of query strings in filteredUrlPatterns' , fakeAsync ( inject (
155- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
156- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
152+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
157153 component . filteredUrlPatterns . push ( 'bar' ) ;
158154 fixture . detectChanges ( ) ;
159155
@@ -172,8 +168,7 @@ describe('SpinnerComponent', () => {
172168 ) ) ) ;
173169
174170 it ( 'should correctly filter with several requests and one pattern' , fakeAsync ( inject (
175- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
176- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
171+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
177172 component . filteredUrlPatterns . push ( '\\d' ) ;
178173 fixture . detectChanges ( ) ;
179174
@@ -197,28 +192,25 @@ describe('SpinnerComponent', () => {
197192 expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( new Error ( '`filteredUrlPatterns` must be an array.' ) ) ;
198193 } ) ;
199194
200- it ( 'should show the spinner even if the component is created after the http request is performed' ,
201- fakeAsync ( inject ( [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
202- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
203- http . get ( '/fake' ) . subscribe ( ) ;
195+ it ( 'should show the spinner even if the component is created after the http request is performed' , fakeAsync ( inject (
196+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
197+ http . get ( '/fake' ) . subscribe ( ) ;
204198
205- const newFixture = TestBed . createComponent ( SpinnerComponent ) ;
206- const newComponent = newFixture . componentInstance ;
199+ const newFixture = TestBed . createComponent ( SpinnerComponent ) ;
200+ const newComponent = newFixture . componentInstance ;
207201
208- tick ( ) ;
209- expect ( newComponent . isSpinnerVisible ) . toBeTruthy ( ) ;
210- httpMock . expectOne ( '/fake' ) . flush ( { } ) ;
202+ tick ( ) ;
203+ expect ( newComponent . isSpinnerVisible ) . toBeTruthy ( ) ;
204+ httpMock . expectOne ( '/fake' ) . flush ( { } ) ;
211205
212- tick ( ) ;
213- expect ( newComponent . isSpinnerVisible ) . toBeFalsy ( ) ;
214- httpMock . verify ( ) ;
215- }
216- ) )
217- ) ;
206+ tick ( ) ;
207+ expect ( newComponent . isSpinnerVisible ) . toBeFalsy ( ) ;
208+ httpMock . verify ( ) ;
209+ }
210+ ) ) ) ;
218211
219212 it ( 'should correctly handle the debounce delay for a single http request' , fakeAsync ( inject (
220- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
221- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
213+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
222214 component . debounceDelay = 2000 ;
223215 http . get ( '/fake' ) . subscribe ( ) ;
224216
@@ -249,8 +241,7 @@ describe('SpinnerComponent', () => {
249241 ) ) ) ;
250242
251243 it ( 'should correctly handle the debounce delay for multiple http requests' , fakeAsync ( inject (
252- [ PendingInterceptorService , HttpClient , HttpTestingController ] ,
253- ( service : PendingInterceptorService , http : HttpClient , httpMock : HttpTestingController ) => {
244+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
254245 component . debounceDelay = 2000 ;
255246
256247 function runQuery ( url : string ) : Observable < any > {
@@ -296,4 +287,14 @@ describe('SpinnerComponent', () => {
296287 discardPeriodicTasks ( ) ;
297288 }
298289 ) ) ) ;
290+
291+ it ( 'should be possible to manually show/hide the spinner' , inject (
292+ [ SpinnerVisibilityService ] , ( visibilityService : SpinnerVisibilityService ) => {
293+ visibilityService . visibilitySubject . next ( true ) ;
294+ expect ( component . isSpinnerVisible ) . toBeTruthy ( ) ;
295+
296+ visibilityService . visibilitySubject . next ( false ) ;
297+ expect ( component . isSpinnerVisible ) . toBeFalsy ( ) ;
298+ }
299+ ) ) ;
299300} ) ;
0 commit comments