Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c47c883

Browse files
committed
chore: clean codes
1 parent d93dfc1 commit c47c883

File tree

9 files changed

+96
-228
lines changed

9 files changed

+96
-228
lines changed

‎ui/apps/todolist/src/app/core/auth-inteceptor.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import {
3-
HttpInterceptor,
4-
HttpRequest,
5-
HttpHandler,
6-
HttpSentEvent,
7-
HttpHeaderResponse,
8-
HttpProgressEvent,
9-
HttpResponse,
10-
HttpUserEvent,
11-
HttpEvent,
12-
HttpErrorResponse,
13-
} from '@angular/common/http';
2+
import { HttpInterceptor, HttpRequest, HttpHandler, HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpEvent, HttpErrorResponse } from '@angular/common/http';
143
import { Observable } from 'rxjs';
154
import { tap } from 'rxjs/operators';
165
import { TokenStorage } from './token-storage';

‎ui/apps/todolist/src/app/core/core.module.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule, Optional, SkipSelf } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { HttpClientModule,HTTP_INTERCEPTORS } from '@angular/common/http';
3+
import { HTTP_INTERCEPTORS,provideHttpClient,withInterceptorsFromDi } from '@angular/common/http';
44
import { AuthGuard } from './auth-guard';
55
import { AuthService } from './auth.service';
66
import { TokenStorage } from './token-storage';
@@ -9,26 +9,23 @@ import { AuthInterceptor } from './auth-inteceptor';
99
import { LoadGuard } from './load-guard';
1010
import { TokenInterceptor } from './token-inteceptor';
1111

12-
@NgModule({
13-
imports: [CommonModule, HttpClientModule, RouterModule],
14-
providers: [
15-
AuthGuard,
16-
LoadGuard,
17-
AuthService,
18-
TokenStorage,
19-
{
20-
provide: HTTP_INTERCEPTORS,
21-
useClass: TokenInterceptor,
22-
multi: true,
23-
},
24-
{
25-
provide: HTTP_INTERCEPTORS,
26-
useClass: AuthInterceptor,
27-
multi: true,
28-
},
29-
],
30-
declarations: [],
31-
})
12+
@NgModule({ declarations: [], imports: [CommonModule, RouterModule], providers: [
13+
AuthGuard,
14+
LoadGuard,
15+
AuthService,
16+
TokenStorage,
17+
{
18+
provide: HTTP_INTERCEPTORS,
19+
useClass: TokenInterceptor,
20+
multi: true,
21+
},
22+
{
23+
provide: HTTP_INTERCEPTORS,
24+
useClass: AuthInterceptor,
25+
multi: true,
26+
},
27+
provideHttpClient(withInterceptorsFromDi()),
28+
] })
3229
export class CoreModule {
3330
// Prevent reimport of the CoreModule
3431
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {

‎ui/apps/todolist/src/app/core/token-inteceptor.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import {
3-
HttpInterceptor,
4-
HttpRequest,
5-
HttpHandler,
6-
HttpSentEvent,
7-
HttpHeaderResponse,
8-
HttpProgressEvent,
9-
HttpResponse,
10-
HttpUserEvent,
11-
HttpEvent,
12-
HttpErrorResponse
13-
} from '@angular/common/http';
2+
import { HttpInterceptor, HttpRequest, HttpHandler, HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpEvent, HttpErrorResponse } from '@angular/common/http';
143
import { Observable } from 'rxjs';
154
import { TokenStorage } from './token-storage';
165
import { Router } from '@angular/router';

‎ui/apps/todolist/src/app/home/home.component.spec.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
// Http testing module and mocking controller
2-
import {
3-
HttpClientTestingModule,
4-
HttpTestingController
5-
} from '@angular/common/http/testing';
6-
import {
7-
HttpClient,
8-
HttpClientModule,
9-
HttpErrorResponse
10-
} from '@angular/common/http';
2+
import { HttpTestingController } from '@angular/common/http/testing';
3+
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
114
import { TestBed, async, inject } from '@angular/core/testing';
125
import {
136
BaseRequestOptions,

‎ui/apps/todolist/src/app/http-client.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Http testing module and mocking controller
2-
import {
3-
HttpClientTestingModule,
4-
HttpTestingController
5-
} from '@angular/common/http/testing';
2+
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
63

74
// Other imports
85
import { TestBed } from '@angular/core/testing';
9-
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
6+
import { HttpClient, HttpErrorResponse,provideHttpClient,withInterceptorsFromDi } from '@angular/common/http';
107

118
import { HttpHeaders } from '@angular/common/http';
129

@@ -22,8 +19,9 @@ describe('HttpClient testing', () => {
2219

2320
beforeEach(() => {
2421
TestBed.configureTestingModule({
25-
imports: [HttpClientTestingModule]
26-
});
22+
imports: [],
23+
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
24+
});
2725

2826
// Inject the http service and test controller for each test
2927
httpClient = TestBed.get(HttpClient);

‎ui/apps/todolist/src/app/post/shared/post-form/post-form.component.spec.ts

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
// Http testing module and mocking controller
2-
import {
3-
HttpClientTestingModule,
4-
HttpTestingController
5-
} from '@angular/common/http/testing';
6-
import {
7-
HttpClient,
8-
HttpClientModule,
9-
HttpErrorResponse
10-
} from '@angular/common/http';
112
import {
123
ComponentFixture,
134
TestBed,
14-
async,
15-
inject,
16-
ComponentFixtureAutoDetect,
5+
waitForAsync,
176
tick,
187
fakeAsync
198
} from '@angular/core/testing';
20-
import {
21-
BaseRequestOptions,
22-
Http,
23-
Response,
24-
ResponseOptions
25-
} from '@angular/http';
26-
import { Observable, of, empty, from, interval, defer } from 'rxjs';
9+
import { Observable, of, EMPTY, from } from 'rxjs';
2710
import { PostFormComponent } from './post-form.component';
2811
import { PostService } from '../post.service';
2912
import { Post } from '../post.model';
3013
import { SharedModule } from '../../../shared/shared.module';
3114
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
32-
import { DebugElement,Component } from '@angular/core';
15+
import { DebugElement } from '@angular/core';
3316
import { By } from '@angular/platform-browser';
3417

3518
const posts = [
@@ -58,10 +41,10 @@ class MockPostService {
5841
return from(posts);
5942
}
6043
savePost(post: Post): Observable<any> {
61-
return empty();
44+
return EMPTY;
6245
}
6346
updatePost(id: string, post: Post): Observable<any> {
64-
return empty();
47+
return EMPTY;
6548
}
6649
}
6750

@@ -76,7 +59,7 @@ describe('Component: PostFormComponent', () => {
7659
'updatePost'
7760
]);
7861

79-
beforeEach(async(() => {
62+
beforeEach(waitForAsync(() => {
8063
TestBed.configureTestingModule({
8164
imports: [BrowserAnimationsModule, SharedModule],
8265
declarations: [PostFormComponent],
@@ -86,7 +69,7 @@ describe('Component: PostFormComponent', () => {
8669
}));
8770

8871
beforeEach(() => {
89-
postService = TestBed.get(PostService);
72+
postService = TestBed.inject(PostService);
9073
fixture = TestBed.createComponent(PostFormComponent);
9174
component = fixture.componentInstance;
9275
fixture.detectChanges();
@@ -105,14 +88,14 @@ describe('Component: PostFormComponent', () => {
10588
it('should have <button> with "save"', () => {
10689
const buttonElement: HTMLElement = fixture.nativeElement;
10790
const p = buttonElement.querySelector('button');
108-
expect(p.textContent).toContain('save');
91+
expect(p?.textContent).toContain('save');
10992
});
11093

11194
it('should find the <button> with fixture.debugElement.nativeElement)', () => {
11295
const compDe: DebugElement = fixture.debugElement;
11396
const compEl: HTMLElement = compDe.nativeElement;
11497
const p = compEl.querySelector('button');
115-
expect(p.textContent).toContain('save');
98+
expect(p?.textContent).toContain('save');
11699
});
117100

118101
it('should find the <button> with fixture.debugElement.query(By.css)', () => {
@@ -176,7 +159,7 @@ describe('Component: PostFormComponent(input & output)', () => {
176159
fixture.detectChanges();
177160

178161
expect(saved).toBeTruthy();
179-
expect(savePostSpy.calls.count()).toBe(1,'savePost called');
162+
expect(savePostSpy.calls.count()).toBe(1);
180163
}));
181164

182165
it('should raise `saved` event when the form is submitted (triggerEventHandler):failed to save', fakeAsync(() => {
@@ -198,7 +181,7 @@ describe('Component: PostFormComponent(input & output)', () => {
198181
fixture.detectChanges();
199182

200183
expect(saved).toBeFalsy();
201-
expect(savePostSpy).toThrowError();
184+
expect(savePostSpy).toThrow();
202185
}));
203186

204187
it('should raise `saved` event when the form is submitted (triggerEventHandler):update', fakeAsync(() => {
@@ -226,7 +209,7 @@ describe('Component: PostFormComponent(input & output)', () => {
226209
fixture.detectChanges();
227210

228211
expect(saved).toBeTruthy();
229-
expect(updatePostSpy.calls.count()).toBe(1,'updatePost called');
212+
expect(updatePostSpy.calls.count()).toBe(1);
230213
}));
231214

232215
it('should raise `saved` event when the form is submitted (triggerEventHandler):failed to update', fakeAsync(() => {
@@ -250,7 +233,7 @@ describe('Component: PostFormComponent(input & output)', () => {
250233
fixture.detectChanges();
251234

252235
expect(saved).toBeFalsy();
253-
expect(updatePostSpy.calls.count()).toBe(1,'updatePost called');
254-
expect(updatePostSpy).toThrowError();
236+
expect(updatePostSpy.calls.count()).toBe(1);
237+
expect(updatePostSpy).toThrow();
255238
}));
256239
});

‎ui/apps/todolist/src/app/post/shared/post.service.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Http testing module and mocking controller
2-
import { HttpClientTestingModule,HttpTestingController } from '@angular/common/http/testing';
3-
import { HttpClient, HttpClientModule,HttpErrorResponse } from '@angular/common/http';
2+
import { HttpTestingController,provideHttpClientTesting } from '@angular/common/http/testing';
3+
import { HttpClient, HttpErrorResponse,provideHttpClient,withInterceptorsFromDi } from '@angular/common/http';
44
import { TestBed, async, inject } from '@angular/core/testing';
55
import { BaseRequestOptions, Http, Response, ResponseOptions } from '@angular/http';
66
import { Observable } from 'rxjs';
@@ -39,11 +39,9 @@ describe('Service: Post', () => {
3939

4040
beforeEach(() => {
4141
TestBed.configureTestingModule({
42-
// Import the HttpClient mocking services
43-
imports: [HttpClientTestingModule],
44-
// Provide the service-under-test and its dependencies
45-
providers: [PostService, HttpErrorHandler, MessageService],
46-
});
42+
imports: [],
43+
providers: [PostService, HttpErrorHandler, MessageService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
44+
});
4745

4846
// Inject the http, test controller, and service-under-test
4947
// as they will be referenced by each test.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /