Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@
"createDefaultProgram": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates",
"plugin:rxjs/recommended"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error"
],
"no-extra-boolean-cast": [
"off"
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "",
"style": "kebab-case",
"type": "element"
"style": "kebab-case"
}
],
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "",
"style": "camelCase",
"type": "attribute"
"style": "camelCase"
}
],
"comma-dangle": [
Expand Down Expand Up @@ -75,7 +83,8 @@
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended"
"plugin:@angular-eslint/template/recommended",
"plugin:@angular-eslint/template/accessibility"
],
"rules": {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/ng-http-loader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnInit, Type } from '@angular/core';
import { merge, Observable, partition, timer } from 'rxjs';
import { debounce, distinctUntilChanged, switchMap, tap } from 'rxjs/operators';
import { PendingRequestsInterceptor } from '../services/pending-requests-interceptor.service';
Expand All @@ -28,7 +28,7 @@ export class NgHttpLoaderComponent implements OnInit {
@Input() backdrop = true;
@Input() backgroundColor!: string;
@Input() debounceDelay = 0;
@Input() entryComponent: any = null;
@Input() entryComponent!: Type<unknown> | null;
@Input() extraDuration = 0;
@Input() filteredHeaders: string[] = [];
@Input() filteredMethods: string[] = [];
Expand Down
8 changes: 4 additions & 4 deletions src/lib/services/pending-requests-interceptor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ export class PendingRequestsInterceptor implements HttpInterceptor {
});
}

private shouldBypassMethod(req: HttpRequest<any>): boolean {
private shouldBypassMethod(req: HttpRequest<unknown>): boolean {
return this._filteredMethods.some(e => {
return e.toUpperCase() === req.method.toUpperCase();
});
}

private shouldBypassHeader(req: HttpRequest<any>): boolean {
private shouldBypassHeader(req: HttpRequest<unknown>): boolean {
return this._filteredHeaders.some(e => {
return req.headers.has(e);
});
}

private shouldBypass(req: HttpRequest<any>): boolean {
private shouldBypass(req: HttpRequest<unknown>): boolean {
return this._forceByPass
|| this.shouldBypassUrl(req.urlWithParams)
|| this.shouldBypassMethod(req)
|| this.shouldBypassHeader(req);
}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const shouldBypass = this.shouldBypass(req);

if (!shouldBypass) {
Expand Down
4 changes: 1 addition & 3 deletions src/test/components/ng-http-loader.component.on-push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NgHttpLoaderModule } from '../../lib/ng-http-loader.module';

Expand All @@ -22,7 +22,6 @@ export class HostComponent {
}

describe('NgHttpLoaderComponent OnPush', () => {
let component: HostComponent;
let fixture: ComponentFixture<HostComponent>;
let http: HttpClient;
let httpMock: HttpTestingController;
Expand All @@ -37,7 +36,6 @@ describe('NgHttpLoaderComponent OnPush', () => {

beforeEach(() => {
fixture = TestBed.createComponent(HostComponent);
component = fixture.componentInstance;
http = TestBed.inject(HttpClient);
httpMock = TestBed.inject(HttpTestingController);
fixture.detectChanges();
Expand Down
20 changes: 1 addition & 19 deletions src/test/components/ng-http-loader.component.outlet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
import { NgHttpLoaderComponent } from '../../lib/components/ng-http-loader.component';
Expand Down Expand Up @@ -52,15 +52,6 @@ describe('NgHttpLoaderComponentOutlet', () => {
expect(component.spinner).toBeNull();
});

it('should correctly check [entryComponent] with empty string', () => {
const spinnerName = 'spinner-name';
component.spinner = spinnerName;
component.entryComponent = '';
component.ngOnInit();

expect(component.spinner).toBe(spinnerName);
});

it('should correctly check [entryComponent] with null', () => {
const spinnerName = 'spinner-name';
component.spinner = spinnerName;
Expand All @@ -69,13 +60,4 @@ describe('NgHttpLoaderComponentOutlet', () => {

expect(component.spinner).toBe(spinnerName);
});

it('should correctly check [entryComponent] with undefined', () => {
const spinnerName = 'spinner-name';
component.spinner = spinnerName;
component.entryComponent = undefined;
component.ngOnInit();

expect(component.spinner).toBe(spinnerName);
});
});
10 changes: 5 additions & 5 deletions src/test/components/ng-http-loader.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('NgHttpLoaderComponent', () => {
});

it('should show and hide the spinner according to the pending HTTP requests', fakeAsync(() => {
const runQuery$ = (url: string): Observable<any> => http.get(url);
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
const firstRequest = httpMock.expectOne('/fake');
const secondRequest = httpMock.expectOne('/fake2');
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('NgHttpLoaderComponent', () => {

it('should correctly handle the debounce delay for multiple HTTP requests', fakeAsync(() => {
component.debounceDelay = 2000;
const runQuery$ = (url: string): Observable<any> => http.get(url);
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
const firstRequest = httpMock.expectOne('/fake');
const secondRequest = httpMock.expectOne('/fake2');
Expand Down Expand Up @@ -510,7 +510,7 @@ describe('NgHttpLoaderComponent', () => {

it('should correctly handle the minimum spinner duration for multiple HTTP requests', fakeAsync(() => {
component.minDuration = 5000;
const runQuery$ = (url: string): Observable<any> => http.get(url);
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
const firstRequest = httpMock.expectOne('/fake');
const secondRequest = httpMock.expectOne('/fake2');
Expand Down Expand Up @@ -548,7 +548,7 @@ describe('NgHttpLoaderComponent', () => {

it('should correctly handle the extra spinner duration for multiple HTTP requests', fakeAsync(() => {
component.extraDuration = 5000;
const runQuery$ = (url: string): Observable<any> => http.get(url);
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();
const firstRequest = httpMock.expectOne('/fake');
const secondRequest = httpMock.expectOne('/fake2');
Expand Down Expand Up @@ -622,7 +622,7 @@ describe('NgHttpLoaderComponent', () => {

it('should handle the extra spinner duration for multiple HTTP requests ran one after the others', fakeAsync(() => {
component.extraDuration = 10;
const runQuery$ = (url: string): Observable<any> => http.get(url);
const runQuery$ = (url: string): Observable<unknown> => http.get(url);
runQuery$('/fake').subscribe();
const firstRequest = httpMock.expectOne('/fake');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { SkChasingDotsComponent } from '../../../lib/components/sk-chasing-dots/sk-chasing-dots.component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { SkCubeGridComponent } from '../../../lib/components/sk-cube-grid/sk-cube-grid.component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { SkWanderingCubesComponent } from '../../../lib/components/sk-wandering-cubes/sk-wandering-cubes.component';

Expand Down
2 changes: 1 addition & 1 deletion src/test/ng-http-loader.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('NgHttpLoaderModule', () => {

it('should create an instance with providers via forRoot()', () => {
const ngHttpLoaderModuleWithProviders = NgHttpLoaderModule.forRoot();
// @ts-ignore
// @ts-expect-error This is error free
expect(ngHttpLoaderModuleWithProviders.providers[0][0].useExisting.name).toEqual(PendingRequestsInterceptor.name);
});
});
11 changes: 7 additions & 4 deletions src/test/services/pending-requests-interceptor.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { forkJoin, Observable } from 'rxjs';
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('PendingRequestsInterceptor', () => {
});

it('should be aware of the pending HTTP requests', () => {
const runQuery$ = (url: string): Observable<any> => http.get(url);
const runQuery$ = (url: string): Observable<unknown> => http.get(url);

forkJoin([runQuery$('/fake'), runQuery$('/fake2')]).subscribe();

Expand Down Expand Up @@ -81,10 +81,13 @@ describe('PendingRequestsInterceptor', () => {

it('should fail correctly', () => {
const statusTextNotFound = 'NOT FOUND';

http.get('/fake').subscribe({
next: () => expect(true).toBe(false),
error: (error: any) => expect(error.statusText).toBe(statusTextNotFound)
error: (error: unknown) => {
if (error instanceof HttpResponse) {
expect(error.statusText).toBe(statusTextNotFound);
}
}
});

const testRequest = httpMock.expectOne('/fake');
Expand Down