diff --git a/package.json b/package.json index 36462cc724..8d3c936212 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "express": "4.16.2", "fast-json-patch": "^2.0.7", "file-saver": "^1.3.8", + "filesize": "^6.1.0", "font-awesome": "4.7.0", "https": "1.0.0", "js-cookie": "2.2.0", diff --git a/src/app/core/auth/auth.effects.spec.ts b/src/app/core/auth/auth.effects.spec.ts index c08615ecc9..79fe385c6d 100644 --- a/src/app/core/auth/auth.effects.spec.ts +++ b/src/app/core/auth/auth.effects.spec.ts @@ -150,7 +150,8 @@ describe('AuthEffects', () => { describe('authenticatedSuccess$', () => { - it('should return a RETRIEVE_AUTHENTICATED_EPERSON action in response to a AUTHENTICATED_SUCCESS action', () => { + it('should return a RETRIEVE_AUTHENTICATED_EPERSON action in response to a AUTHENTICATED_SUCCESS action', (done) => { + spyOn((authEffects as any).authService, 'storeToken'); actions = hot('--a-', { a: { type: AuthActionTypes.AUTHENTICATED_SUCCESS, payload: { @@ -163,8 +164,14 @@ describe('AuthEffects', () => { const expected = cold('--b-', { b: new RetrieveAuthenticatedEpersonAction(EPersonMock._links.self.href) }); + authEffects.authenticatedSuccess$.subscribe(() => { + expect(authServiceStub.storeToken).toHaveBeenCalledWith(token); + }); + expect(authEffects.authenticatedSuccess$).toBeObservable(expected); + done(); }); + }); describe('checkToken$', () => { diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index c6d447961a..5591ffbe39 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -65,7 +65,6 @@ export class AuthEffects { @Effect() public authenticateSuccess$: Observable = this.actions$.pipe( ofType(AuthActionTypes.AUTHENTICATE_SUCCESS), - tap((action: AuthenticationSuccessAction) => this.authService.storeToken(action.payload)), map((action: AuthenticationSuccessAction) => new AuthenticatedAction(action.payload)) ); @@ -82,6 +81,7 @@ export class AuthEffects { @Effect() public authenticatedSuccess$: Observable = this.actions$.pipe( ofType(AuthActionTypes.AUTHENTICATED_SUCCESS), + tap((action: AuthenticatedSuccessAction) => this.authService.storeToken(action.payload.authToken)), map((action: AuthenticatedSuccessAction) => new RetrieveAuthenticatedEpersonAction(action.payload.userHref)) ); diff --git a/src/app/shared/utils/file-size-pipe.ts b/src/app/shared/utils/file-size-pipe.ts index a796edb073..2d219cdaf4 100644 --- a/src/app/shared/utils/file-size-pipe.ts +++ b/src/app/shared/utils/file-size-pipe.ts @@ -1,4 +1,5 @@ import { Pipe, PipeTransform } from '@angular/core'; +import * as fileSize from 'filesize'; /* * Convert bytes into largest possible unit. @@ -12,30 +13,7 @@ import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'dsFileSize' }) export class FileSizePipe implements PipeTransform { - - private units: string[] = [ - 'bytes', - 'KiB', - 'MiB', - 'GiB', - 'TiB', - 'PiB' - ]; - transform(bytes: number = 0, precision: number = 2): string { - let result: string; - if (isNaN(parseFloat(String(bytes))) || !isFinite(bytes)) { - result = '?'; - } else { - let unit = 0; - - while (bytes >= 1024) { - bytes /= 1024; - unit++; - } - - result = bytes.toFixed(+ precision) + ' ' + this.units[unit]; - } - return result; + return fileSize(bytes, { standard: 'jedec', round: precision }); } } diff --git a/src/polyfills.ts b/src/polyfills.ts index ca40a803ba..151f4a4c45 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -52,11 +52,6 @@ * */ -/*************************************************************************************************** - * Zone JS is required by default for Angular itself. - */ -import 'zone.js/dist/zone'; // Included with Angular CLI. - /*************************************************************************************************** * APPLICATION IMPORTS */ @@ -64,4 +59,6 @@ import 'zone.js/dist/zone'; // Included with Angular CLI. import 'core-js/es'; import 'core-js/features/reflect'; +import 'zone.js/dist/zone'; // Included with Angular CLI. + import 'reflect-metadata'; diff --git a/yarn.lock b/yarn.lock index 402f51a0e0..12346a8e51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4309,6 +4309,11 @@ filesize@^3.6.1: resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.6.1.tgz#090bb3ee01b6f801a8a8be99d31710b3422bb317" integrity sha512-7KjR1vv6qnicaPMi1iiTcI85CyYwRO/PSFCu6SvqL8jN2Wjt/NIYQTFtFs7fSDCYOstUkEWIQGFUg5YZQfjlcg== +filesize@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/filesize/-/filesize-6.1.0.tgz#e81bdaa780e2451d714d71c0d7a4f3238d37ad00" + integrity sha512-LpCHtPQ3sFx67z+uh2HnSyWSLLu5Jxo21795uRDuar/EOuYWXib5EmPaGIBuSnRqH2IODiKA2k5re/K9OnN/Yg== + fill-range@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7"