-
Notifications
You must be signed in to change notification settings - Fork 297
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
Development
: Remove deprecated router module in client tests
#9439
Changes from all commits
bb7faa8
e28ccaa
e5d8554
81b451f
e1cb2bb
f4b46bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,6 @@ import { ComplaintsForTutorComponent } from 'app/complaints/complaints-for-tutor | |||||
import { ExerciseGroup } from 'app/entities/exercise-group.model'; | ||||||
import { TextareaCounterComponent } from 'app/shared/textarea/textarea-counter.component'; | ||||||
import { MockComponent, MockDirective, MockPipe, MockProvider } from 'ng-mocks'; | ||||||
import { RouterTestingModule } from '@angular/router/testing'; | ||||||
import { AlertService } from 'app/core/util/alert.service'; | ||||||
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe'; | ||||||
import { ArtemisDatePipe } from 'app/shared/pipes/artemis-date.pipe'; | ||||||
|
@@ -18,6 +17,7 @@ import { of } from 'rxjs'; | |||||
import { Course } from 'app/entities/course.model'; | ||||||
import { Exercise } from 'app/entities/exercise.model'; | ||||||
import { TranslateDirective } from 'app/shared/language/translate.directive'; | ||||||
import { provideRouter } from '@angular/router'; | ||||||
|
||||||
describe('ComplaintsForTutorComponent', () => { | ||||||
let complaintsForTutorComponent: ComplaintsForTutorComponent; | ||||||
|
@@ -29,15 +29,15 @@ describe('ComplaintsForTutorComponent', () => { | |||||
|
||||||
beforeEach(() => { | ||||||
TestBed.configureTestingModule({ | ||||||
imports: [RouterTestingModule.withRoutes([]), FormsModule], | ||||||
imports: [FormsModule], | ||||||
declarations: [ | ||||||
ComplaintsForTutorComponent, | ||||||
MockPipe(ArtemisTranslatePipe), | ||||||
MockPipe(ArtemisDatePipe), | ||||||
MockComponent(TextareaCounterComponent), | ||||||
MockDirective(TranslateDirective), | ||||||
], | ||||||
providers: [MockProvider(ComplaintResponseService), MockProvider(ComplaintService), MockProvider(AlertService)], | ||||||
providers: [provideRouter([]), MockProvider(ComplaintResponseService), MockProvider(ComplaintService), MockProvider(AlertService)], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM: TestBed configuration updated correctly The replacement of Consider moving - providers: [MockProvider(ComplaintResponseService), MockProvider(ComplaintService), MockProvider(AlertService), provideRouter([])],
+ providers: [provideRouter([]), MockProvider(ComplaintResponseService), MockProvider(ComplaintService), MockProvider(AlertService)], 📝 Committable suggestion
Suggested change
|
||||||
}) | ||||||
.compileComponents() | ||||||
.then(() => { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import { of } from 'rxjs'; | |
import { Course } from 'app/entities/course.model'; | ||
import { MockComponent, MockDirective, MockModule, MockPipe } from 'ng-mocks'; | ||
import { OrionFilterDirective } from 'app/shared/orion/orion-filter.directive'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { MockHasAnyAuthorityDirective } from '../../helpers/mocks/directive/mock-has-any-authority.directive'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { ArtemisDatePipe } from 'app/shared/pipes/artemis-date.pipe'; | ||
|
@@ -15,7 +14,7 @@ import { CourseExercisesComponent } from 'app/overview/course-exercises/course-e | |
import { CourseExerciseRowComponent } from 'app/overview/course-exercises/course-exercise-row.component'; | ||
import { SidePanelComponent } from 'app/shared/side-panel/side-panel.component'; | ||
import { MockTranslateService, TranslatePipeMock } from '../../helpers/mocks/service/mock-translate.service'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { ActivatedRoute, RouterModule } from '@angular/router'; | ||
import { ModelingExercise } from 'app/entities/modeling-exercise.model'; | ||
import { Exercise } from 'app/entities/exercise.model'; | ||
import dayjs from 'dayjs/esm'; | ||
|
@@ -45,7 +44,7 @@ describe('CourseExercisesComponent', () => { | |
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule, FormsModule, RouterTestingModule.withRoutes([]), MockModule(ReactiveFormsModule), MockDirective(TranslateDirective)], | ||
imports: [ArtemisTestModule, FormsModule, RouterModule.forRoot([]), MockModule(ReactiveFormsModule), MockDirective(TranslateDirective)], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM: TestBed configuration updated correctly. The TestBed configuration has been updated to use Consider extracting the router configuration to a constant for better readability: const routes: Routes = [];
// ...
imports: [ArtemisTestModule, FormsModule, RouterModule.forRoot(routes), MockModule(ReactiveFormsModule), MockDirective(TranslateDirective)], This approach improves code organization and makes it easier to add routes in the future if needed. |
||
declarations: [ | ||
CourseExercisesComponent, | ||
SidebarComponent, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { ArtemisTestModule } from '../../../test.module'; | |
import { MockSyncStorage } from '../../../helpers/mocks/service/mock-sync-storage.service'; | ||
import { LocalStorageService, SessionStorageService } from 'ngx-webstorage'; | ||
import { MockComponent, MockDirective, MockPipe } from 'ng-mocks'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { MockHasAnyAuthorityDirective } from '../../../helpers/mocks/directive/mock-has-any-authority.directive'; | ||
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe'; | ||
import { ArtemisDatePipe } from 'app/shared/pipes/artemis-date.pipe'; | ||
|
@@ -15,6 +14,7 @@ import { of } from 'rxjs'; | |
import { StatisticsAverageScoreGraphComponent } from 'app/shared/statistics-graph/statistics-average-score-graph.component'; | ||
import { ExerciseType } from 'app/entities/exercise.model'; | ||
import { DocumentationButtonComponent } from 'app/shared/components/documentation-button/documentation-button.component'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
describe('CourseManagementStatisticsComponent', () => { | ||
let fixture: ComponentFixture<CourseManagementStatisticsComponent>; | ||
|
@@ -31,7 +31,7 @@ describe('CourseManagementStatisticsComponent', () => { | |
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule, RouterTestingModule.withRoutes([])], | ||
imports: [ArtemisTestModule, RouterModule.forRoot([])], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Approved: RouterTestingModule replacement implemented correctly. The change from However, consider the following suggestions for potential improvements:
These suggestions aim to ensure that the routing setup in the test environment closely mirrors the actual usage in the component. |
||
declarations: [ | ||
CourseManagementStatisticsComponent, | ||
MockComponent(StatisticsGraphComponent), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,8 @@ import { By } from '@angular/platform-browser'; | |
import { TranslateService } from '@ngx-translate/core'; | ||
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { ArtemisDatePipe } from 'app/shared/pipes/artemis-date.pipe'; | ||
import { Router } from '@angular/router'; | ||
import { Router, provideRouter } from '@angular/router'; | ||
|
||
describe('CourseRegistrationButtonComponent', () => { | ||
let fixture: ComponentFixture<CourseUnenrollmentModalComponent>; | ||
|
@@ -29,9 +28,9 @@ describe('CourseRegistrationButtonComponent', () => { | |
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule, ReactiveFormsModule, RouterTestingModule.withRoutes([])], | ||
imports: [ArtemisTestModule, ReactiveFormsModule], | ||
declarations: [CourseUnenrollmentModalComponent, MockPipe(ArtemisTranslatePipe), MockPipe(ArtemisDatePipe)], | ||
providers: [MockProvider(CourseManagementService), MockProvider(AlertService), MockProvider(TranslateService)], | ||
providers: [provideRouter([]), MockProvider(CourseManagementService), MockProvider(AlertService), MockProvider(TranslateService)], | ||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM: TestBed configuration updated correctly. The TestBed configuration has been properly updated to use A minor suggestion for consistency: Consider moving providers: [
MockProvider(CourseManagementService),
MockProvider(AlertService),
MockProvider(TranslateService),
provideRouter([])
], |
||
}) | ||
.compileComponents() | ||
.then(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { HttpHeaders, HttpResponse } from '@angular/common/http'; | ||
import { HttpTestingController } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { ActivatedRoute, Router, RouterModule } from '@angular/router'; | ||
import { Location } from '@angular/common'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { DueDateStat } from 'app/course/dashboards/due-date-stat.model'; | ||
import { CourseForDashboardDTO } from 'app/course/manage/course-for-dashboard-dto'; | ||
|
@@ -93,7 +92,7 @@ describe('CoursesComponent', () => { | |
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule, RouterTestingModule.withRoutes([{ path: 'courses/:courseId/exams/:examId', component: DummyComponent }])], | ||
imports: [ArtemisTestModule, RouterModule.forRoot([{ path: 'courses/:courseId/exams/:examId', component: DummyComponent }])], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using provideRouter() for a more lightweight test setup. While the change from RouterTestingModule to RouterModule.forRoot() aligns with the PR objective, using RouterModule.forRoot() in tests sets up the full router configuration, which might be unnecessary for most test scenarios. Consider using provideRouter() for a more lightweight and focused test setup. Here's a suggested refactor: -imports: [ArtemisTestModule, RouterModule.forRoot([{ path: 'courses/:courseId/exams/:examId', component: DummyComponent }])],
+imports: [ArtemisTestModule],
+providers: [
+ ...
+ provideRouter([{ path: 'courses/:courseId/exams/:examId', component: DummyComponent }])
+], This change will provide a more efficient routing setup for your tests while still allowing you to test navigation-related functionality.
|
||
declarations: [ | ||
CoursesComponent, | ||
MockDirective(MockHasAnyAuthorityDirective), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ArtemisTestModule } from '../../../test.module'; | ||
import { CourseDetailDoughnutChartComponent } from 'app/course/manage/detail/course-detail-doughnut-chart.component'; | ||
|
@@ -7,6 +6,7 @@ import { MockModule, MockPipe } from 'ng-mocks'; | |
import { DoughnutChartType } from 'app/course/manage/detail/course-detail.component'; | ||
import { Course } from 'app/entities/course.model'; | ||
import { PieChartModule } from '@swimlane/ngx-charts'; | ||
import { provideRouter } from '@angular/router'; | ||
|
||
describe('CourseDetailDoughnutChartComponent', () => { | ||
let fixture: ComponentFixture<CourseDetailDoughnutChartComponent>; | ||
|
@@ -19,8 +19,9 @@ describe('CourseDetailDoughnutChartComponent', () => { | |
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule, RouterTestingModule.withRoutes([]), MockModule(PieChartModule)], | ||
imports: [ArtemisTestModule, MockModule(PieChartModule)], | ||
declarations: [CourseDetailDoughnutChartComponent, MockPipe(ArtemisTranslatePipe)], | ||
providers: [provideRouter([])], | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM: Addition of provideRouter to providers. The addition of Consider adding a comment explaining why an empty array is used for providers: [
// Provide empty routes array as no specific routes are needed for these tests
provideRouter([])
], |
||
.compileComponents() | ||
.then(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { MockDirective, MockModule, MockPipe, MockProvider } from 'ng-mocks'; | ||
import { of } from 'rxjs'; | ||
|
@@ -16,6 +15,7 @@ import { NgxChartsSingleSeriesDataEntry } from 'app/shared/chart/ngx-charts-data | |
import { ExerciseType } from 'app/entities/exercise.model'; | ||
import { LocaleConversionService } from 'app/shared/service/locale-conversion.service'; | ||
import { TranslateDirective } from 'app/shared/language/translate.directive'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
describe('ExamScoresAverageScoresGraphComponent', () => { | ||
let fixture: ComponentFixture<ExamScoresAverageScoresGraphComponent>; | ||
|
@@ -55,7 +55,7 @@ describe('ExamScoresAverageScoresGraphComponent', () => { | |
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ArtemisTestModule, RouterTestingModule.withRoutes([]), MockModule(BarChartModule)], | ||
imports: [ArtemisTestModule, MockModule(BarChartModule), RouterModule.forRoot([])], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM: TestBed configuration updated correctly. The replacement of Consider extracting the router configuration to a constant at the top of the file for better maintainability: const routes = [];
// ... other setup code ...
imports: [ArtemisTestModule, MockModule(BarChartModule), RouterModule.forRoot(routes)], This approach allows for easier modification of routes if needed in the future. |
||
declarations: [ExamScoresAverageScoresGraphComponent, MockPipe(ArtemisTranslatePipe), MockDirective(TranslateDirective)], | ||
providers: [ | ||
MockProvider(CourseManagementService, { | ||
|
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.
🧹 Nitpick (assertive)
LGTM: TestBed configuration updated correctly.
The replacement of
RouterTestingModule
withRouterModule.forRoot()
is implemented correctly. This change provides a more realistic routing setup for the tests while maintaining the existing route structure.Consider extracting the routes to a separate constant for better readability and reusability:
This approach can improve maintainability if these routes are used in multiple test files.