Skip to content

Commit

Permalink
SHIBUI-814 Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 21, 2018
1 parent 153e2c7 commit 3220671
Show file tree
Hide file tree
Showing 23 changed files with 112 additions and 39 deletions.
5 changes: 4 additions & 1 deletion ui/src/app/i18n/component/translate.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Component: I18n translation', () => {
let fixture: ComponentFixture<TestHostComponent>;
let instance: TestHostComponent;
let store: Store<fromI18n.State>;
let service: I18nService;

const msg = {
foo: 'foo',
Expand All @@ -45,7 +46,7 @@ describe('Component: I18n translation', () => {
imports: [
CommonModule,
StoreModule.forRoot({
'message': combineReducers(fromI18n.reducers),
'i18n': combineReducers(fromI18n.reducers),
})
],
declarations: [
Expand All @@ -54,6 +55,7 @@ describe('Component: I18n translation', () => {
],
});
store = TestBed.get(Store);
service = TestBed.get(I18nService);

spyOn(store, 'dispatch').and.callThrough();

Expand All @@ -62,6 +64,7 @@ describe('Component: I18n translation', () => {
});

it('should set the correct text', () => {
spyOn(service, 'translate').and.returnValue('foo');
store.dispatch(new MessagesLoadSuccessAction(msg));

store.select(fromI18n.getMessages).subscribe(() => {
Expand Down
75 changes: 75 additions & 0 deletions ui/src/app/i18n/directive/translate.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { I18nService } from '../service/i18n.service';
import { CommonModule } from '@angular/common';
import { StoreModule, combineReducers, Store } from '@ngrx/store';

import * as fromI18n from '../reducer';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { Component } from '@angular/core';
import { MessagesLoadSuccessAction } from '../action/message.action';
import { TranslateDirective } from './translate.directive';
import { MockI18nService, MockI18nModule } from '../../../testing/i18n.stub';

@Component({
template: `
<div [translate]="foo">Word</div>
`
})
class TestHostComponent {
private _foo: string;

public get foo(): string {
return this._foo;
}

public set foo(val: string) {
this._foo = val;
}
}

describe('Directive: I18n translation', () => {
let fixture: ComponentFixture<TestHostComponent>;
let instance: TestHostComponent;
let store: Store<fromI18n.State>;
let service: I18nService;

const msg = {
foo: 'foo',
bar: 'bar',
baz: 'baz'
};

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{ provide: I18nService, useClass: MockI18nService }
],
imports: [
CommonModule,
StoreModule.forRoot({
'i18n': combineReducers(fromI18n.reducers),
})
],
declarations: [
TranslateDirective,
TestHostComponent
],
});
store = TestBed.get(Store);
service = TestBed.get(I18nService);

spyOn(store, 'dispatch').and.callThrough();

fixture = TestBed.createComponent(TestHostComponent);
instance = fixture.componentInstance;
});

it('should set the correct text', () => {
spyOn(service, 'translate').and.returnValue('foo');
store.dispatch(new MessagesLoadSuccessAction(msg));

store.select(fromI18n.getMessages).subscribe(() => {
fixture.detectChanges();
expect(fixture.nativeElement.textContent).toContain(msg.foo);
});
});
});
4 changes: 3 additions & 1 deletion ui/src/app/i18n/i18n.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { TranslatePipe } from './pipe/i18n.pipe';
import { CoreModule } from '../core/core.module';
import { TranslateDirective } from './directive/translate.directive';
import { TranslateComponent } from './component/translate.component';
import { I18nTextComponent } from './component/i18n-text.component';

export const COMPONENTS = [
TranslateComponent
TranslateComponent,
I18nTextComponent
];
export const DIRECTIVES = [
TranslateDirective
Expand Down
7 changes: 5 additions & 2 deletions ui/src/app/i18n/pipe/i18n.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MockI18nService, MockI18nModule } from '../../../testing/i18n.stub';

@Component({
template: `
<span>{{ foo | translate:{ foo: 'bar' } }}</span>
<span>{{ foo | translate }}</span>
`
})
class TestHostComponent {
Expand All @@ -30,6 +30,7 @@ describe('Pipe: I18n translation', () => {
let fixture: ComponentFixture<TestHostComponent>;
let instance: TestHostComponent;
let store: Store<fromI18n.State>;
let service: I18nService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -39,7 +40,7 @@ describe('Pipe: I18n translation', () => {
imports: [
CommonModule,
StoreModule.forRoot({
'message': combineReducers(fromI18n.reducers),
'i18n': combineReducers(fromI18n.reducers),
})
],
declarations: [
Expand All @@ -48,6 +49,7 @@ describe('Pipe: I18n translation', () => {
],
});
store = TestBed.get(Store);
service = TestBed.get(I18nService);

spyOn(store, 'dispatch').and.callThrough();

Expand All @@ -56,6 +58,7 @@ describe('Pipe: I18n translation', () => {
});

it('should set the correct text', () => {
spyOn(service, 'translate').and.returnValue('hi there');
store.dispatch(new MessagesLoadSuccessAction({ foo: 'hi there' }));

store.select(fromI18n.getMessages).subscribe(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule, Store, combineReducers } from '@ngrx/store';
import { ProviderValueEmitter, ProviderStatusEmitter } from '../../../domain/service/provider-change-emitter.service';
import { NgbPopoverModule, NgbPopoverConfig } from '@ng-bootstrap/ng-bootstrap/popover/popover.module';
import { AssertionFormComponent } from './assertion-form.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, ViewChild } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ReactiveFormsModule, FormBuilder, Validators } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule, Store, combineReducers } from '@ngrx/store';
import { ProviderValueEmitter, ProviderStatusEmitter } from '../../../domain/service/provider-change-emitter.service';
import { NgbPopoverModule, NgbPopoverConfig } from '@ng-bootstrap/ng-bootstrap/popover/popover.module';
import { ListValuesService } from '../../../domain/service/list-values.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ActivatedRouteStub } from '../../../../../testing/activated-route.stub'
import * as stubs from '../../../../../testing/resolver.stub';
import { FileBackedHttpMetadataResolver } from '../../entity';
import { InputDefaultsDirective } from '../../../../shared/directive/input-defaults.directive';
import { I18nTextComponent } from '../../../../shared/component/i18n-text.component';
import { MockI18nModule } from '../../../../../testing/i18n.stub';

@Component({
Expand Down Expand Up @@ -56,7 +55,6 @@ describe('Finished Form Component', () => {
declarations: [
FinishFormComponent,
RouterLinkStubDirective,
I18nTextComponent,
InputDefaultsDirective,
TestHostComponent
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { KeyInfoFormComponent } from './key-info-form.component';
import * as stubs from '../../../../../testing/resolver.stub';
import { FileBackedHttpMetadataResolver } from '../../entity';
import { InputDefaultsDirective } from '../../../../shared/directive/input-defaults.directive';
import { I18nTextComponent } from '../../../../shared/component/i18n-text.component';
import { MockI18nModule } from '../../../../../testing/i18n.stub';

@Component({
Expand Down Expand Up @@ -55,8 +54,7 @@ describe('Security (Key) Info Form Component', () => {
declarations: [
KeyInfoFormComponent,
TestHostComponent,
InputDefaultsDirective,
I18nTextComponent
InputDefaultsDirective
],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { LogoutFormComponent } from './logout-form.component';
import * as stubs from '../../../../../testing/resolver.stub';
import { FileBackedHttpMetadataResolver } from '../../entity';
import { InputDefaultsDirective } from '../../../../shared/directive/input-defaults.directive';
import { I18nTextComponent } from '../../../../shared/component/i18n-text.component';
import { MockI18nModule } from '../../../../../testing/i18n.stub';

@Component({
Expand Down Expand Up @@ -53,8 +52,7 @@ describe('Logout Endpoints Form Component', () => {
declarations: [
LogoutFormComponent,
TestHostComponent,
InputDefaultsDirective,
I18nTextComponent
InputDefaultsDirective
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MetadataUiFormComponent } from './metadata-ui-form.component';
import * as stubs from '../../../../../testing/resolver.stub';
import { FileBackedHttpMetadataResolver } from '../../entity';
import { InputDefaultsDirective } from '../../../../shared/directive/input-defaults.directive';
import { I18nTextComponent } from '../../../../shared/component/i18n-text.component';
import { MockI18nModule } from '../../../../../testing/i18n.stub';

@Component({
Expand Down Expand Up @@ -51,8 +50,7 @@ describe('Metadata UI Form Component', () => {
declarations: [
MetadataUiFormComponent,
TestHostComponent,
InputDefaultsDirective,
I18nTextComponent
InputDefaultsDirective
],
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule, Store, combineReducers } from '@ngrx/store';
import { ProviderValueEmitter, ProviderStatusEmitter } from '../../../domain/service/provider-change-emitter.service';
import { NgbPopoverModule, NgbPopoverConfig } from '@ng-bootstrap/ng-bootstrap/popover/popover.module';
import { ListValuesService } from '../../../domain/service/list-values.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, ViewChild } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { ReactiveFormsModule, FormBuilder, Validators } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule, Store, combineReducers } from '@ngrx/store';
import { ProviderValueEmitter, ProviderStatusEmitter } from '../../../domain/service/provider-change-emitter.service';
import { NgbPopoverModule, NgbPopoverConfig } from '@ng-bootstrap/ng-bootstrap/popover/popover.module';
import { ListValuesService } from '../../../domain/service/list-values.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as fromRoot from '../reducer';
import { SchemaFormModule, WidgetRegistry, DefaultWidgetRegistry } from 'ngx-schema-form';
import * as fromWizard from '../../../wizard/reducer';
import { ProviderEditorNavComponent, NAV_FORMATS } from './provider-editor-nav.component';
import { I18nTextComponent } from '../../../shared/component/i18n-text.component';
import { ValidFormIconComponent } from '../../../shared/component/valid-form-icon.component';
import { WizardStep } from '../../../wizard/model';
import { MockI18nModule } from '../../../../testing/i18n.stub';
Expand Down Expand Up @@ -55,7 +54,6 @@ describe('Provider Editor Nav Component', () => {
],
declarations: [
ProviderEditorNavComponent,
I18nTextComponent,
ValidFormIconComponent,
TestHostComponent
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { NgbModalStub } from '../../../../testing/modal.stub';
import { MetadataProvider } from '../../domain/model';
import { of } from 'rxjs';
import { DifferentialService } from '../../../core/service/differential.service';
import { MockI18nModule } from '../../../../testing/i18n.stub';

@Component({
template: `
Expand Down Expand Up @@ -61,7 +62,8 @@ describe('Provider Edit Component', () => {
schemaCollection: []
}
})
})
}),
MockI18nModule
],
declarations: [
ProviderEditComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { ProviderFilterListComponent } from './provider-filter-list.component';
import * as fromRoot from '../reducer';
import * as fromWizard from '../../../wizard/reducer';
import { ProviderEditorNavComponent } from '../component/provider-editor-nav.component';
import { I18nTextComponent } from '../../../shared/component/i18n-text.component';
import { ValidFormIconComponent } from '../../../shared/component/valid-form-icon.component';
import { DeleteFilterComponent } from '../component/delete-filter.component';
import { NgbModalStub } from '../../../../testing/modal.stub';
import { MockI18nModule } from '../../../../testing/i18n.stub';

@Component({
template: `
Expand All @@ -37,12 +37,12 @@ describe('Provider Filter List Component', () => {
StoreModule.forRoot({
provider: combineReducers(fromRoot.reducers),
wizard: combineReducers(fromWizard.reducers)
})
}),
MockI18nModule
],
declarations: [
ProviderFilterListComponent,
ProviderEditorNavComponent,
I18nTextComponent,
ValidFormIconComponent,
DeleteFilterComponent,
TestHostComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { WizardModule } from '../../../wizard/wizard.module';
import { ProviderWizardSummaryComponent } from '../component/provider-wizard-summary.component';
import { SummaryPropertyComponent } from '../component/summary-property.component';
import * as fromWizard from '../../../wizard/reducer';
import { MockI18nModule } from '../../../../testing/i18n.stub';

@Component({
template: `
Expand Down Expand Up @@ -38,7 +39,8 @@ describe('Provider Wizard Component', () => {
StoreModule.forRoot({
provider: combineReducers(fromRoot.reducers),
wizard: combineReducers(fromWizard.reducers)
})
}),
MockI18nModule
],
declarations: [
ProviderWizardComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as fromResolver from '../reducer';
import { CopyResolverComponent } from './copy-resolver.component';
import { SharedModule } from '../../../shared/shared.module';
import { NavigatorService } from '../../../core/service/navigator.service';
import { I18nTextComponent } from '../../../shared/component/i18n-text.component';
import { MockI18nModule } from '../../../../testing/i18n.stub';

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import {
EventEmitter
} from '@angular/core';
import { FormBuilder, FormGroup, FormControl, FormControlName, Validators, AbstractControl } from '@angular/forms';
import { Observable, Subject, of } from 'rxjs';
import { Observable, of } from 'rxjs';
import { Store } from '@ngrx/store';

import { startWith, take, last } from 'rxjs/operators';
import { take } from 'rxjs/operators';

import { AddDraftRequest } from '../action/draft.action';
import { AddResolverRequest, UploadResolverRequest } from '../action/collection.action';
import * as fromResolver from '../reducer';
import { EntityValidators } from '../../domain/service/entity-validators.service';
import { SearchIds } from '../action/search.action';
import * as fromProvider from '../reducer';
import { FileBackedHttpMetadataResolver } from '../../domain/entity';
import { CreateResolverCopyRequest, UpdateResolverCopySections } from '../action/copy.action';


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { SharedModule } from '../../../shared/shared.module';
import { NavigatorService } from '../../../core/service/navigator.service';
import * as fromResolver from '../reducer';
import { ActivatedRouteStub } from '../../../../testing/activated-route.stub';
import { I18nTextComponent } from '../../../shared/component/i18n-text.component';
import { MockI18nModule } from '../../../../testing/i18n.stub';

describe('New Resolver Page', () => {
Expand Down
Loading

0 comments on commit 3220671

Please sign in to comment.