From 7c8c8f514e2904822a2ab50e1a3d28e7e70f2832 Mon Sep 17 00:00:00 2001 From: Tomas Trajan Date: Wed, 1 Aug 2018 01:46:58 +0800 Subject: [PATCH] fix: code formatting, tslint errors, i18n test dependencies --- package-lock.json | 35 ++++++------------- package.json | 2 +- .../authenticated.component.spec.ts | 3 ++ .../examples/examples.component.spec.ts | 12 ++----- .../stock-market.component.spec.ts | 12 ++----- .../theming/child/child.component.spec.ts | 3 ++ .../theming/parent/parent.component.spec.ts | 6 +++- .../examples/todos/todos.component.spec.ts | 7 ++-- .../settings/settings/settings.component.html | 6 ++-- .../settings/settings.component.spec.ts | 25 +++++++------ src/app/static/about/about.component.spec.ts | 4 +-- .../features/features.component.spec.ts | 6 ++-- src/testing/utils.ts | 26 ++++++++++++++ tslint.json | 1 - 14 files changed, 74 insertions(+), 74 deletions(-) mode change 100644 => 100755 src/app/examples/authenticated/authenticated.component.spec.ts mode change 100644 => 100755 src/app/examples/examples/examples.component.spec.ts mode change 100644 => 100755 src/app/examples/stock-market/stock-market.component.spec.ts mode change 100644 => 100755 src/app/examples/theming/child/child.component.spec.ts mode change 100644 => 100755 src/app/examples/theming/parent/parent.component.spec.ts mode change 100644 => 100755 src/app/static/features/features.component.spec.ts mode change 100644 => 100755 tslint.json diff --git a/package-lock.json b/package-lock.json index dcb70870c..b5b48b3c1 100755 --- a/package-lock.json +++ b/package-lock.json @@ -11606,9 +11606,9 @@ "integrity": "sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==" }, "tslint": { - "version": "5.9.1", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.9.1.tgz", - "integrity": "sha1-ElX4ej/1frCw4fDmEKi0dIBGya4=", + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.11.0.tgz", + "integrity": "sha1-mPMMAurjzecAYgHkwzywi0hYHu0=", "dev": true, "requires": { "babel-code-frame": "^6.22.0", @@ -11622,41 +11622,26 @@ "resolve": "^1.3.2", "semver": "^5.3.0", "tslib": "^1.8.0", - "tsutils": "^2.12.1" + "tsutils": "^2.27.2" }, "dependencies": { "chalk": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", - "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", "dev": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "supports-color": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", - "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } } } }, "tsutils": { - "version": "2.22.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.22.0.tgz", - "integrity": "sha512-05iMIQXsLVBx2vPTvpsHriRuNpKpU1Z9jqYUOBvwglO6I+QzdA1UQcVoNhsVkSZfns5TjFMFbdxdrkOW6cfwUQ==", + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", "dev": true, "requires": { "tslib": "^1.8.1" diff --git a/package.json b/package.json index 52dca4650..4dedb0ebc 100755 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "rimraf": "^2.6.2", "standard-version": "^4.2.0", "ts-node": "~5.0.0", - "tslint": "~5.9.1", + "tslint": "~5.11.0", "typescript": "~2.7.2", "webpack-bundle-analyzer": "^2.11.1" } diff --git a/src/app/examples/authenticated/authenticated.component.spec.ts b/src/app/examples/authenticated/authenticated.component.spec.ts old mode 100644 new mode 100755 index d193f18db..ee9ed4a60 --- a/src/app/examples/authenticated/authenticated.component.spec.ts +++ b/src/app/examples/authenticated/authenticated.component.spec.ts @@ -1,5 +1,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { TestingModule } from '@testing/utils'; + import { AuthenticatedComponent } from './authenticated.component'; describe('AuthenticatedComponent', () => { @@ -9,6 +11,7 @@ describe('AuthenticatedComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ + imports: [TestingModule], declarations: [AuthenticatedComponent] }).compileComponents(); }) diff --git a/src/app/examples/examples/examples.component.spec.ts b/src/app/examples/examples/examples.component.spec.ts old mode 100644 new mode 100755 index 63245011d..8fcb2f03f --- a/src/app/examples/examples/examples.component.spec.ts +++ b/src/app/examples/examples/examples.component.spec.ts @@ -1,9 +1,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { SharedModule } from '@app/shared'; -import { CoreModule } from '@app/core'; +import { TestingModule } from '@testing/utils'; import { ExamplesComponent } from './examples.component'; @@ -14,12 +11,7 @@ describe('ExamplesComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ - imports: [ - NoopAnimationsModule, - RouterTestingModule, - SharedModule, - CoreModule - ], + imports: [TestingModule], declarations: [ExamplesComponent] }).compileComponents(); }) diff --git a/src/app/examples/stock-market/stock-market.component.spec.ts b/src/app/examples/stock-market/stock-market.component.spec.ts old mode 100644 new mode 100755 index ef0854a42..1302ae259 --- a/src/app/examples/stock-market/stock-market.component.spec.ts +++ b/src/app/examples/stock-market/stock-market.component.spec.ts @@ -1,9 +1,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { RouterTestingModule } from '@angular/router/testing'; import { CoreModule } from '@app/core'; -import { SharedModule } from '@app/shared'; +import { TestingModule } from '@testing/utils'; import { ExamplesModule } from '../examples.module'; @@ -16,13 +14,7 @@ describe('StockMarketComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ - imports: [ - RouterTestingModule, - NoopAnimationsModule, - CoreModule, - SharedModule, - ExamplesModule - ] + imports: [TestingModule, CoreModule, ExamplesModule] }).compileComponents(); }) ); diff --git a/src/app/examples/theming/child/child.component.spec.ts b/src/app/examples/theming/child/child.component.spec.ts old mode 100644 new mode 100755 index 96b9e04fb..d294910bb --- a/src/app/examples/theming/child/child.component.spec.ts +++ b/src/app/examples/theming/child/child.component.spec.ts @@ -1,5 +1,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { TestingModule } from '@testing/utils'; + import { ChildComponent } from './child.component'; describe('ChildComponent', () => { @@ -9,6 +11,7 @@ describe('ChildComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ + imports: [TestingModule], declarations: [ChildComponent] }).compileComponents(); }) diff --git a/src/app/examples/theming/parent/parent.component.spec.ts b/src/app/examples/theming/parent/parent.component.spec.ts old mode 100644 new mode 100755 index 83f603434..500381b8d --- a/src/app/examples/theming/parent/parent.component.spec.ts +++ b/src/app/examples/theming/parent/parent.component.spec.ts @@ -1,8 +1,11 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { ParentComponent } from './parent.component'; +import { TestingModule } from '@testing/utils'; + import { ChildComponent } from '../child/child.component'; +import { ParentComponent } from './parent.component'; + describe('ParentComponent', () => { let component: ParentComponent; let fixture: ComponentFixture; @@ -10,6 +13,7 @@ describe('ParentComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ + imports: [TestingModule], declarations: [ParentComponent, ChildComponent] }).compileComponents(); }) diff --git a/src/app/examples/todos/todos.component.spec.ts b/src/app/examples/todos/todos.component.spec.ts index ea09de134..244ace64f 100755 --- a/src/app/examples/todos/todos.component.spec.ts +++ b/src/app/examples/todos/todos.component.spec.ts @@ -5,11 +5,9 @@ import { inject } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { Store } from '@ngrx/store'; -import { SharedModule } from '@app/shared'; -import { TestStore } from '@testing/utils'; +import { TestStore, TestingModule } from '@testing/utils'; import { TodosComponent } from './todos.component'; import { @@ -54,8 +52,7 @@ describe('TodosComponent', () => { async(() => { TestBed.configureTestingModule({ declarations: [TodosComponent], - imports: [NoopAnimationsModule, SharedModule], - providers: [{ provide: Store, useClass: TestStore }] + imports: [TestingModule] }).compileComponents(); }) ); diff --git a/src/app/settings/settings/settings.component.html b/src/app/settings/settings/settings.component.html index f179727fa..d78335cd1 100755 --- a/src/app/settings/settings/settings.component.html +++ b/src/app/settings/settings/settings.component.html @@ -11,7 +11,8 @@

{{ 'anms.settings.general' | translate }}

+ (selectionChange)="onLanguageSelect($event)" + name="language"> {{ 'anms.settings.general.language.' + l.label | translate }} @@ -30,7 +31,8 @@

{{ 'anms.settings.themes' | translate }}

+ (selectionChange)="onThemeSelect($event)" + name="themes"> {{ 'anms.settings.themes.' + t.label | translate }} diff --git a/src/app/settings/settings/settings.component.spec.ts b/src/app/settings/settings/settings.component.spec.ts index fbc50757e..e8d5196ee 100755 --- a/src/app/settings/settings/settings.component.spec.ts +++ b/src/app/settings/settings/settings.component.spec.ts @@ -1,8 +1,6 @@ import { By } from '@angular/platform-browser'; import { Store } from '@ngrx/store'; import { MatSlideToggle } from '@angular/material'; -import { RouterTestingModule } from '@angular/router/testing'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { async, ComponentFixture, @@ -10,8 +8,7 @@ import { inject } from '@angular/core/testing'; -import { SharedModule } from '@app/shared'; -import { TestStore } from '@testing/utils'; +import { TestingModule, TestStore } from '@testing/utils'; import { SettingsComponent } from './settings.component'; import { @@ -28,16 +25,16 @@ describe('SettingsComponent', () => { let store: TestStore; let dispatchSpy; - const getSelectArrow = () => - fixture.debugElement.query(By.css('.mat-select-trigger')); - const getOptions = () => fixture.debugElement.queryAll(By.css('mat-option')); + const getThemeSelectArrow = () => + fixture.debugElement.queryAll(By.css('.mat-select-trigger'))[1]; + const getSelectOptions = () => + fixture.debugElement.queryAll(By.css('mat-option')); beforeEach( async(() => { TestBed.configureTestingModule({ - imports: [NoopAnimationsModule, RouterTestingModule, SharedModule], declarations: [SettingsComponent], - providers: [{ provide: Store, useClass: TestStore }] + imports: [TestingModule] }).compileComponents(); }) ); @@ -50,7 +47,8 @@ describe('SettingsComponent', () => { autoNightMode: true, pageAnimations: true, pageAnimationsDisabled: false, - elementsAnimations: true + elementsAnimations: true, + language: 'en' }); fixture = TestBed.createComponent(SettingsComponent); component = fixture.componentInstance; @@ -67,11 +65,11 @@ describe('SettingsComponent', () => { it('should dispatch change theme action on theme selection', () => { dispatchSpy = spyOn(store, 'dispatch'); - getSelectArrow().triggerEventHandler('click', {}); + getThemeSelectArrow().triggerEventHandler('click', {}); fixture.detectChanges(); - getOptions()[1].triggerEventHandler('click', {}); + getSelectOptions()[1].triggerEventHandler('click', {}); fixture.detectChanges(); @@ -129,7 +127,8 @@ describe('SettingsComponent', () => { autoNightMode: true, pageAnimations: true, pageAnimationsDisabled: true, // change animations disabled - elementsAnimations: true + elementsAnimations: true, + language: 'en' }); fixture.detectChanges(); diff --git a/src/app/static/about/about.component.spec.ts b/src/app/static/about/about.component.spec.ts index 6947fca42..037def958 100755 --- a/src/app/static/about/about.component.spec.ts +++ b/src/app/static/about/about.component.spec.ts @@ -1,6 +1,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { SharedModule } from '@app/shared'; +import { TestingModule } from '@testing/utils'; import { AboutComponent } from './about.component'; @@ -11,7 +11,7 @@ describe('AboutComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ - imports: [SharedModule], + imports: [TestingModule], declarations: [AboutComponent] }).compileComponents(); }) diff --git a/src/app/static/features/features.component.spec.ts b/src/app/static/features/features.component.spec.ts old mode 100644 new mode 100755 index d24354025..375cbeb78 --- a/src/app/static/features/features.component.spec.ts +++ b/src/app/static/features/features.component.spec.ts @@ -1,8 +1,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; -import { SharedModule } from '@app/shared'; -import { CoreModule } from '@app/core'; +import { TestingModule } from '@testing/utils'; import { FeaturesComponent } from './features.component'; @@ -13,7 +11,7 @@ describe('FeaturesComponent', () => { beforeEach( async(() => { TestBed.configureTestingModule({ - imports: [RouterTestingModule, SharedModule, CoreModule], + imports: [TestingModule], declarations: [FeaturesComponent] }).compileComponents(); }) diff --git a/src/testing/utils.ts b/src/testing/utils.ts index b54fac7a9..49fc724e0 100755 --- a/src/testing/utils.ts +++ b/src/testing/utils.ts @@ -1,4 +1,10 @@ +import { NgModule } from '@angular/core'; +import { SharedModule } from '@app/shared'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { TranslateModule } from '@ngx-translate/core'; +import { Store } from '@ngrx/store'; import { BehaviorSubject, Observable } from 'rxjs'; +import { RouterTestingModule } from '@angular/router/testing'; export class TestStore { private state: BehaviorSubject = new BehaviorSubject(undefined); @@ -13,3 +19,23 @@ export class TestStore { dispatch(action: any) {} } + +@NgModule({ + imports: [ + NoopAnimationsModule, + RouterTestingModule, + SharedModule, + TranslateModule.forRoot() + ], + exports: [ + NoopAnimationsModule, + RouterTestingModule, + SharedModule, + TranslateModule + ], + providers: [{ provide: Store, useClass: TestStore }] +}) +export class TestingModule { + constructor() { + } +} diff --git a/tslint.json b/tslint.json old mode 100644 new mode 100755 index 84e585d96..3ea984c77 --- a/tslint.json +++ b/tslint.json @@ -72,7 +72,6 @@ "no-trailing-whitespace": true, "no-unnecessary-initializer": true, "no-unused-expression": true, - "no-unused-variable": true, "no-use-before-declare": true, "no-var-keyword": true, "object-literal-sort-keys": false,