Skip to content

Commit 3c8baa8

Browse files
refactor(Application): Convert remaining components to standalone (#2247)
Convert remaining components to standalone. Remove AppModule and replace with bootstrapApplication(AppComponent)
1 parent 9e59754 commit 3c8baa8

File tree

90 files changed

+907
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+907
-702
lines changed

src/app/announcement/announcement.component.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ import {
44
MatDialogRef,
55
MAT_DIALOG_DATA,
66
MatDialog,
7-
MatDialogModule
7+
MatDialogModule,
8+
MatDialogTitle,
9+
MatDialogContent,
10+
MatDialogActions,
11+
MatDialogClose
812
} from '@angular/material/dialog';
913
import { MatIconModule } from '@angular/material/icon';
10-
import { MatButtonModule } from '@angular/material/button';
14+
import { MatButtonModule, MatButton } from '@angular/material/button';
15+
import { CdkScrollable } from '@angular/cdk/scrolling';
1116

1217
@Component({
1318
encapsulation: ViewEncapsulation.None,
@@ -31,9 +36,16 @@ export class AnnouncementComponent {
3136
}
3237

3338
@Component({
39+
imports: [
40+
MatDialogTitle,
41+
CdkScrollable,
42+
MatDialogContent,
43+
MatDialogActions,
44+
MatButton,
45+
MatDialogClose
46+
],
3447
selector: 'announcement-dialog',
35-
templateUrl: 'announcement-dialog.component.html',
36-
standalone: false
48+
templateUrl: 'announcement-dialog.component.html'
3749
})
3850
export class AnnouncementDialogComponent {
3951
constructor(

src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PersonalLibraryComponent } from './modules/library/personal-library/per
55
import { PublicLibraryComponent } from './modules/library/public-library/public-library.component';
66
import { RouterModule, Routes } from '@angular/router';
77

8-
const routes: Routes = [
8+
export const appRoutes: Routes = [
99
{ path: '', loadChildren: () => import('./home/home.module').then((m) => m.HomeModule) },
1010
{
1111
path: 'about',
@@ -78,7 +78,7 @@ export class XhrInterceptor implements HttpInterceptor {
7878
}
7979

8080
@NgModule({
81-
imports: [RouterModule.forRoot(routes, { paramsInheritanceStrategy: 'always' }), FormsModule],
81+
imports: [RouterModule.forRoot(appRoutes, { paramsInheritanceStrategy: 'always' }), FormsModule],
8282
exports: [RouterModule],
8383
providers: [{ provide: HTTP_INTERCEPTORS, useClass: XhrInterceptor, multi: true }]
8484
})

src/app/app.component.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { TestBed, ComponentFixture } from '@angular/core/testing';
22
import { AppComponent } from './app.component';
3-
import { NO_ERRORS_SCHEMA } from '@angular/core';
43
import { Observable, BehaviorSubject } from 'rxjs';
54
import { UtilService } from './services/util.service';
65
import { Announcement } from './domain/announcement';
76
import { ConfigService } from './services/config.service';
87
import { Config } from './domain/config';
98
import { environment } from '../environments/environment';
109
import { provideRouter } from '@angular/router';
10+
import { MockComponents, MockProviders } from 'ng-mocks';
11+
import { UserService } from './services/user.service';
12+
import { MobileMenuComponent } from './modules/mobile-menu/mobile-menu.component';
13+
import { provideHttpClient } from '@angular/common/http';
14+
import { HeaderComponent } from './modules/header/header.component';
1115

1216
export class MockConfigService {
1317
private config$: BehaviorSubject<Config> = new BehaviorSubject<Config>(null);
@@ -54,13 +58,14 @@ describe('AppComponent', () => {
5458

5559
beforeEach(() => {
5660
TestBed.configureTestingModule({
57-
declarations: [AppComponent],
61+
imports: [AppComponent, MockComponents(HeaderComponent, MobileMenuComponent)],
5862
providers: [
5963
{ provide: ConfigService, useClass: MockConfigService },
6064
{ provide: UtilService, useClass: MockUtilService },
65+
MockProviders(UserService),
66+
provideHttpClient(),
6167
provideRouter([])
62-
],
63-
schemas: [NO_ERRORS_SCHEMA]
68+
]
6469
});
6570
fixture = TestBed.createComponent(AppComponent);
6671
component = fixture.componentInstance;

src/app/app.component.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
import { Component, Inject, DOCUMENT } from '@angular/core';
2-
32
import { Router, NavigationEnd, NavigationStart } from '@angular/router';
43
import { DomSanitizer } from '@angular/platform-browser';
54
import { MatIconRegistry } from '@angular/material/icon';
6-
import { Subscription } from 'rxjs';
75
import { UtilService } from './services/util.service';
86
import { ConfigService } from './services/config.service';
97
import { Announcement } from './domain/announcement';
108
import { environment } from '../environments/environment';
119
import { BreakpointObserver } from '@angular/cdk/layout';
10+
import { CommonModule } from '@angular/common';
11+
import { MatSidenavModule } from '@angular/material/sidenav';
12+
import { MatButtonModule } from '@angular/material/button';
13+
import { MatIconModule } from '@angular/material/icon';
14+
import { RouterModule } from '@angular/router';
15+
import { MobileMenuComponent } from './modules/mobile-menu/mobile-menu.component';
16+
import { AnnouncementComponent } from './announcement/announcement.component';
17+
import { HeaderComponent } from './modules/header/header.component';
18+
import { FooterComponent } from './modules/footer/footer.component';
19+
1220
declare let gtag: Function;
1321

1422
@Component({
23+
imports: [
24+
CommonModule,
25+
MatSidenavModule,
26+
MatButtonModule,
27+
MatIconModule,
28+
RouterModule,
29+
MobileMenuComponent,
30+
AnnouncementComponent,
31+
HeaderComponent,
32+
FooterComponent
33+
],
1534
selector: 'app-root',
16-
templateUrl: './app.component.html',
17-
styleUrls: ['./app.component.scss'],
18-
standalone: false
35+
styleUrl: './app.component.scss',
36+
templateUrl: './app.component.html'
1937
})
2038
export class AppComponent {
2139
title = 'app';

src/app/app.module.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/app/common/edit-profile/edit-profile.component.html

Whitespace-only changes.

src/app/common/edit-profile/edit-profile.component.spec.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/app/common/edit-profile/edit-profile.component.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import { Component } from '@angular/core';
21
import { MatDialog } from '@angular/material/dialog';
32
import { MatSnackBar } from '@angular/material/snack-bar';
43
import { UnlinkGoogleAccountConfirmComponent } from '../../modules/shared/unlink-google-account-confirm/unlink-google-account-confirm.component';
54

6-
@Component({
7-
selector: 'edit-profile',
8-
templateUrl: './edit-profile.component.html',
9-
styleUrls: ['./edit-profile.component.scss'],
10-
standalone: false
11-
})
12-
export class EditProfileComponent {
5+
export abstract class EditProfileComponent {
136
changed: boolean = false;
147

15-
constructor(public dialog: MatDialog, public snackBar: MatSnackBar) {}
8+
constructor(
9+
public dialog: MatDialog,
10+
public snackBar: MatSnackBar
11+
) {}
1612

1713
handleUpdateProfileResponse(response) {
1814
if (response.status === 'success') {

src/app/contact/contact-form/contact-form.component.spec.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22
import { ContactFormComponent } from './contact-form.component';
3-
import { ReactiveFormsModule } from '@angular/forms';
4-
import { RouterTestingModule } from '@angular/router/testing';
5-
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
6-
import { MatInputModule } from '@angular/material/input';
7-
import { MatSelectModule } from '@angular/material/select';
8-
import { NO_ERRORS_SCHEMA } from '@angular/core';
93
import { ConfigService } from '../../services/config.service';
104
import { StudentService } from '../../student/student.service';
115
import { User } from '../../domain/user';
126
import { BehaviorSubject, Observable, of } from 'rxjs';
137
import { LibraryService } from '../../services/library.service';
148
import { RECAPTCHA_V3_SITE_KEY, ReCaptchaV3Service, RecaptchaV3Module } from 'ng-recaptcha-2';
15-
import { provideHttpClientTesting } from '@angular/common/http/testing';
16-
import { HttpClient, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
9+
import { HttpClient, provideHttpClient } from '@angular/common/http';
1710
import { UserService } from '../../services/user.service';
1811
import { By } from '@angular/platform-browser';
12+
import { provideRouter } from '@angular/router';
1913

2014
export class MockStudentService {
2115
getTeacherList(): Observable<User> {
@@ -37,26 +31,29 @@ let userService: UserService;
3731
describe('ContactFormComponent', () => {
3832
beforeEach(waitForAsync(() => {
3933
TestBed.configureTestingModule({
40-
declarations: [ContactFormComponent],
41-
schemas: [NO_ERRORS_SCHEMA],
42-
imports: [
43-
BrowserAnimationsModule,
44-
MatInputModule,
45-
MatSelectModule,
46-
ReactiveFormsModule,
47-
RecaptchaV3Module,
48-
RouterTestingModule
49-
],
34+
imports: [ContactFormComponent],
5035
providers: [
5136
ConfigService,
5237
{ provide: LibraryService, useClass: MockLibraryService },
5338
{ provide: RECAPTCHA_V3_SITE_KEY, useValue: recaptchaPrivateKey },
39+
{
40+
provide: ReCaptchaV3Service,
41+
useValue: {
42+
execute: jasmine.createSpy('execute').and.returnValue(of('mock-token'))
43+
}
44+
},
5445
{ provide: StudentService, useClass: MockStudentService },
5546
UserService,
56-
provideHttpClient(withInterceptorsFromDi()),
57-
provideHttpClientTesting()
47+
provideHttpClient(),
48+
provideRouter([])
5849
]
59-
}).compileComponents();
50+
})
51+
.overrideComponent(ContactFormComponent, {
52+
remove: {
53+
imports: [RecaptchaV3Module]
54+
}
55+
})
56+
.compileComponents();
6057
}));
6158

6259
beforeEach(() => {
@@ -164,7 +161,6 @@ function submit_showRecaptchaErrorMessage(): void {
164161
it('should show recaptcha error message', async () => {
165162
isRecaptchaEnabledSpy.and.returnValue(true);
166163
component.ngOnInit();
167-
spyOn(recaptchaV3Service, 'execute').and.returnValue(of('generated-token'));
168164
const httpPostSpy = httpPostSpyAndReturn('error');
169165
await submitAndDetectChanges();
170166
expect(httpPostSpy).toHaveBeenCalled();

0 commit comments

Comments
 (0)