-
Notifications
You must be signed in to change notification settings - Fork 1
Tta 193 add loading page to new ip check load time #939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolsss
merged 14 commits into
master
from
TTA-193-add-loading-page-to-new-ip-check-load-time
Oct 17, 2022
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d41a02c
feat: TTA-193 add preload page
andresacg30 8f9730e
fix: TTA-181 change husky hint when commit message is wrong (#937)
mmaquina 4715458
chore(release): 1.75.21 [skip ci]nn
semantic-release-bot 3ff389b
feat: TTA-193 add service and interceptor for spinner loading
465c2c2
feat: TTA-193 add spinner overlay and style it
56747ce
test: TTA-193 make test
andresacg30 615effc
update package-lock.json version
andresacg30 97abddb
Merge branch 'master' into TTA-193-add-loading-page-to-new-ip-check-l…
andresacg30 bd1ba98
test: add test for interceptor and service
andresacg30 0a07ce9
test: TTA-193 increase code coverage
andresacg30 91d1e2e
test: TTA-193 increase code coverage
andresacg30 3398358
fix: spinner test
1415da1
fix: spinner test
e0fe698
fix: load spinner when route is recent
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <router-outlet></router-outlet> | ||
| <router-outlet></router-outlet> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/app/modules/shared/components/spinner-overlay/spinner-overlay.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <mat-spinner diameter="80"></mat-spinner> |
5 changes: 5 additions & 0 deletions
5
src/app/modules/shared/components/spinner-overlay/spinner-overlay.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @use "../../../../../styles/colors.scss" as colors; | ||
|
|
||
| :host ::ng-deep .mat-progress-spinner circle, .mat-spinner circle { | ||
| stroke: colors.$warning; | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/app/modules/shared/components/spinner-overlay/spinner-overlay.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { SpinnerOverlayComponent } from './spinner-overlay.component'; | ||
|
|
||
| describe('SpinnerOverlayComponent', () => { | ||
| let component: SpinnerOverlayComponent; | ||
| let fixture: ComponentFixture<SpinnerOverlayComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| declarations: [ SpinnerOverlayComponent ] | ||
| }) | ||
| .compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(SpinnerOverlayComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
11 changes: 11 additions & 0 deletions
11
src/app/modules/shared/components/spinner-overlay/spinner-overlay.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-spinner-overlay', | ||
| templateUrl: './spinner-overlay.component.html', | ||
| styleUrls: ['./spinner-overlay.component.scss'], | ||
| }) | ||
|
|
||
| export class SpinnerOverlayComponent { | ||
| constructor() {} | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/app/modules/shared/interceptors/spinner.interceptor.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Overlay } from '@angular/cdk/overlay'; | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import { SpinnerInterceptor } from './spinner.interceptor'; | ||
| import { HttpHandler, HttpRequest, HttpResponse, HttpEvent } from '@angular/common/http'; | ||
| import { Observable, of, Subscription } from 'rxjs'; | ||
| import { SpinnerOverlayService } from '../services/spinner-overlay.service'; | ||
|
|
||
|
|
||
| describe('SpinnerInterceptorService test', () => { | ||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| SpinnerInterceptor, | ||
| Overlay | ||
| ], | ||
| }); | ||
|
|
||
| class MockHttpHandler implements HttpHandler { | ||
| handle(req: HttpRequest<any>): Observable<HttpEvent<any>> { | ||
| return of(new HttpResponse()); | ||
| } | ||
| } | ||
|
|
||
| let overlay: Overlay; | ||
| let httpHandler: HttpHandler; | ||
| let spinnerInterceptor: SpinnerInterceptor; | ||
| let spinnerOverlayService: SpinnerOverlayService; | ||
|
|
||
| beforeEach(() => { | ||
| overlay = jasmine.createSpyObj('Overlay', ['create']); | ||
| httpHandler = new MockHttpHandler(); | ||
| spinnerInterceptor = new SpinnerInterceptor(new SpinnerOverlayService(overlay)); | ||
| spinnerOverlayService = new SpinnerOverlayService(overlay); | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(spinnerInterceptor).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('if request is made then spinnerInterceptor is called', () => { | ||
| const request = new HttpRequest('GET', '/foo'); | ||
| const spinnerSubscription: Subscription = spinnerOverlayService.spinner$.subscribe(); | ||
| spyOn(spinnerSubscription, 'unsubscribe') | ||
| spyOn(spinnerInterceptor, 'intercept').and.callThrough(); | ||
|
|
||
| spinnerInterceptor.intercept(request, httpHandler); | ||
|
|
||
| expect(spinnerInterceptor.intercept).toHaveBeenCalledWith(request, httpHandler); | ||
| expect(spinnerSubscription.unsubscribe).toBeTruthy(); | ||
| }); | ||
|
|
||
| }); |
25 changes: 25 additions & 0 deletions
25
src/app/modules/shared/interceptors/spinner.interceptor.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { | ||
| HttpEvent, | ||
| HttpHandler, | ||
| HttpInterceptor, | ||
| HttpRequest, | ||
| } from '@angular/common/http'; | ||
| import { Injectable } from '@angular/core'; | ||
| import { Observable, Subscription } from 'rxjs'; | ||
| import { finalize } from 'rxjs/operators'; | ||
| import { SpinnerOverlayService } from '../services/spinner-overlay.service'; | ||
|
|
||
| @Injectable() | ||
| export class SpinnerInterceptor implements HttpInterceptor { | ||
| constructor(private readonly spinnerOverlayService: SpinnerOverlayService) {} | ||
|
|
||
| intercept( | ||
| req: HttpRequest<any>, | ||
| next: HttpHandler | ||
| ): Observable<HttpEvent<any>> { | ||
| const spinnerSubscription: Subscription = this.spinnerOverlayService.spinner$.subscribe(); | ||
| return next | ||
| .handle(req) | ||
| .pipe(finalize(() => spinnerSubscription.unsubscribe())); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
src/app/modules/shared/services/spinner-overlay.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import { Overlay } from '@angular/cdk/overlay'; | ||
|
|
||
| import { SpinnerOverlayService } from './spinner-overlay.service'; | ||
| import { SpinnerInterceptor } from '../interceptors/spinner.interceptor'; | ||
| import { HttpEvent, HttpHandler, HttpRequest, HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http'; | ||
| import { Observable, of } from 'rxjs'; | ||
| import { ComponentPortal } from 'ngx-toastr'; | ||
|
|
||
|
|
||
| describe('SpinnerOverlayService test', () => { | ||
|
|
||
| class MockHttpHandler extends HttpHandler { | ||
| handle(req: HttpRequest<any>): Observable<HttpEvent<any>> { | ||
| return of(new HttpResponse()); | ||
| } | ||
| } | ||
|
|
||
| let spinnerService: SpinnerOverlayService; | ||
| let spinnerInterceptor: SpinnerInterceptor; | ||
| let mockHttpHandler: HttpHandler; | ||
| let overlayRef: any; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| Overlay, | ||
| SpinnerInterceptor, | ||
| { | ||
| provide: HTTP_INTERCEPTORS, | ||
| useClass: SpinnerInterceptor, | ||
| multi: true, | ||
| }, | ||
| ], | ||
| }); | ||
| spinnerService = TestBed.inject(SpinnerOverlayService); | ||
| spinnerInterceptor = TestBed.inject(SpinnerInterceptor); | ||
| mockHttpHandler = new MockHttpHandler(); | ||
| overlayRef = spinnerService.overlayRef; | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(spinnerService).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('if request is made then spinnerService is show', () => { | ||
| const request = new HttpRequest('GET', '/foo'); | ||
| spyOn(spinnerService, 'show'); | ||
| spyOn(spinnerService, 'hide'); | ||
|
|
||
| spinnerInterceptor.intercept(request, mockHttpHandler); | ||
|
|
||
| expect(spinnerService.show).toHaveBeenCalled(); | ||
| expect(overlayRef).toBeUndefined(); | ||
| expect(ComponentPortal).toBeTruthy(); | ||
| expect(spinnerService.hide).toBeTruthy(); | ||
| }); | ||
|
|
||
| }); |
45 changes: 45 additions & 0 deletions
45
src/app/modules/shared/services/spinner-overlay.service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Overlay, OverlayRef } from '@angular/cdk/overlay'; | ||
| import { ComponentPortal } from '@angular/cdk/portal'; | ||
| import { Injectable } from '@angular/core'; | ||
| import { defer, NEVER } from 'rxjs'; | ||
| import { finalize, share } from 'rxjs/operators'; | ||
| import { SpinnerOverlayComponent } from './../components/spinner-overlay/spinner-overlay.component'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class SpinnerOverlayService { | ||
| static spinner$: any; | ||
| public overlayRef: OverlayRef = undefined; | ||
|
|
||
|
|
||
| constructor(private readonly overlay: Overlay) { } | ||
|
|
||
| public readonly spinner$ = defer(() => { | ||
| this.show(); | ||
| return NEVER.pipe( | ||
| finalize(() => { | ||
| this.hide(); | ||
| }) | ||
| ); | ||
| }).pipe(share()); | ||
|
|
||
| public show(): void { | ||
| Promise.resolve(null).then(() => { | ||
| this.overlayRef = this.overlay.create({ | ||
| positionStrategy: this.overlay | ||
| .position() | ||
| .global() | ||
| .centerHorizontally() | ||
| .centerVertically(), | ||
| hasBackdrop: true, | ||
| }); | ||
| this.overlayRef.attach(new ComponentPortal(SpinnerOverlayComponent)); | ||
| }); | ||
| } | ||
|
|
||
| public hide(): void { | ||
| this.overlayRef.detach(); | ||
| this.overlayRef = undefined; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.