Skip to content

Commit

Permalink
Migrate to latest Play version - addresses #92
Browse files Browse the repository at this point in the history
Fixes UI unit tests.
  • Loading branch information
resamsel committed Oct 2, 2020
1 parent 1fd3411 commit b06e03b
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { LOGIN_URL } from '@translatr/utils';

import { AuthInterceptor } from './auth.interceptor';

describe('ErrorInterceptor', () => {
describe('AuthInterceptor', () => {
beforeEach(() =>
TestBed.configureTestingModule({
providers: [AuthInterceptor]
providers: [AuthInterceptor, { provide: LOGIN_URL, useValue: '' }],
imports: [RouterTestingModule]
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { WINDOW } from '@translatr/utils';
import {
EmptyViewTestingModule,
FeatureFlagTestingModule,
MetricTestingModule
MetricTestingModule,
ProjectInfographicTestingModule
} from '@translatr/components/testing';
import { NavListTestingModule } from '../../../shared/nav-list/testing';
import { ActivityListTestingModule } from '../../../shared/activity-list/testing';
Expand All @@ -38,6 +39,7 @@ describe('ProjectInfoComponent', () => {
ShortNumberModule,
FeatureFlagTestingModule,
EmptyViewTestingModule,
ProjectInfographicTestingModule,

RouterTestingModule,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { FeatureFlagModule, UserEditFormModule } from '@dev/translatr-components';
import { LanguageProvider } from '@dev/translatr-sdk';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { TranslocoModule } from '@ngneat/transloco';
import { SidenavModule } from '../../nav/sidenav/sidenav.module';
import { RegistrationPageRoutingModule } from './registration-page-routing.module';

import { RegistrationPageComponent } from './registration-page.component';

Expand All @@ -8,7 +19,22 @@ describe('RegistrationPageComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [RegistrationPageComponent]
declarations: [RegistrationPageComponent],
imports: [
HttpClientTestingModule,
RouterTestingModule,
NoopAnimationsModule,

RegistrationPageRoutingModule,
SidenavModule,
TranslocoModule,
FeatureFlagModule,
UserEditFormModule,
MatCardModule,
MatButtonModule,
FontAwesomeModule
],
providers: [LanguageProvider]
}).compileComponents();
}));

Expand Down
3 changes: 2 additions & 1 deletion ui/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest'
'^.+\\.(ts|js|html)$': 'ts-jest',
'.+\\.(svg)$': 'jest-transform-stub'
},
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { RouterTestingModule } from '@angular/router/testing';
import { FontAwesomeTestingModule } from '@fortawesome/angular-fontawesome/testing';
import { NavbarTestingModule } from '@translatr/components/testing';
import { AuthClientService } from '@translatr/translatr-sdk/src/lib/services/auth-client.service';
import { ENDPOINT_URL } from '@translatr/utils';
Expand All @@ -15,7 +18,15 @@ describe('LoginPageComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [LoginPageComponent],
imports: [NavbarTestingModule, MatIconModule],
imports: [
RouterTestingModule,

NavbarTestingModule,

MatIconModule,
MatCardModule,
FontAwesomeTestingModule
],
providers: [
{
provide: AuthClientService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './project-infographic-testing.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, Input, NgModule } from '@angular/core';

@Component({
selector: 'dev-project-infographic',
template: ''
})
export class MockProjectInfographicComponent {
@Input() contributorCount: number;
@Input() localeCount: number;
@Input() keyCount: number;
@Input() messageCount: number;
}

@NgModule({
declarations: [MockProjectInfographicComponent],
exports: [MockProjectInfographicComponent]
})
export class ProjectInfographicTestingModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './project-infographic/testing';
1 change: 1 addition & 0 deletions ui/libs/translatr-components/src/lib/modules/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from './filter-field/testing';
export * from './metric/testing';
export * from './nav/testing';
export * from './pages/testing';
export * from './project/testing';
export * from './user/testing';
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './user-card/testing';
export * from './user-edit-form/testing';
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
mat-flat-button
color="primary"
(click)="editForm.onSubmit()"
[disabled]="editForm.form.invalid"
[disabled]="editForm.invalid"
transloco="button.save"
>Save
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MatSelectModule } from '@angular/material/select';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { UserEditDialogComponent } from '@dev/translatr-components';
import { TranslocoTestingModule } from '@ngneat/transloco';
import { UserEditFormTestingModule } from '@translatr/components/testing';
import { mockObservable } from '@translatr/utils/testing';

describe('UserEditDialogComponent', () => {
Expand All @@ -22,6 +23,8 @@ describe('UserEditDialogComponent', () => {
NoopAnimationsModule,
TranslocoTestingModule,

UserEditFormTestingModule,

MatFormFieldModule,
MatDialogModule,
MatInputModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './user-edit-form-testing.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component, EventEmitter, Input, NgModule, Output } from '@angular/core';
import { ConstraintViolationErrorInfo, User } from '@dev/translatr-model';

@Component({
selector: 'dev-user-edit-form',
template: ''
})
export class MockUserEditFormComponent {
@Input() user: User;
@Input() errors: ConstraintViolationErrorInfo;

@Output() edit = new EventEmitter<User>();

get invalid(): boolean {
return true;
}

onSubmit() {}
}

@NgModule({
declarations: [MockUserEditFormComponent],
exports: [MockUserEditFormComponent]
})
export class UserEditFormTestingModule {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslocoModule } from '@ngneat/transloco';

import { UserEditFormComponent } from './user-edit-form.component';

Expand All @@ -8,7 +14,16 @@ describe('UserEditFormComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [UserEditFormComponent]
declarations: [UserEditFormComponent],
imports: [
ReactiveFormsModule,
TranslocoModule,
NoopAnimationsModule,

MatFormFieldModule,
MatInputModule,
MatSelectModule
]
}).compileComponents();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ export class UserEditFormComponent implements OnInit {
? this.form.value.allowedRoles.indexOf(role) !== -1
: false;
}

get invalid(): boolean {
return this.form.invalid;
}
}
4 changes: 4 additions & 0 deletions ui/libs/translatr-sdk/src/lib/services/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';

export interface RestRequest {
Expand All @@ -8,6 +9,9 @@ export interface RestRequest {
path: string;
}

@Injectable({
providedIn: 'root'
})
export class ErrorHandler {
handleError(error: HttpErrorResponse, request?: RestRequest): Observable<never> {
return throwError(error);
Expand Down
5 changes: 5 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"core-js": "^2.6.11",
"d3": "5.16.0",
"d3-time": "^1.1.0",
"jest-transform-stub": "2.0.0",
"messageformat": "2.3.0",
"moment": "2.26.0",
"ngx-gravatar": "^7.2.2",
Expand Down

0 comments on commit b06e03b

Please sign in to comment.