Skip to content

Commit

Permalink
Call reset method in next tick (#264)
Browse files Browse the repository at this point in the history
- call reset method in next tick
- format the tests
- use fakeAsync in the second beforeEach block
- remove unnecessary AfterViewInit from the wizard component tests
- organizing the imports inside the tests
- fixing a spelling error
Co-authored-by: earshinov <earshinov@gmail.com>
  • Loading branch information
madoar committed Feb 24, 2020
1 parent 86b0595 commit d3f4071
Show file tree
Hide file tree
Showing 28 changed files with 323 additions and 220 deletions.
20 changes: 12 additions & 8 deletions src/lib/components/wizard-completion-step.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {MovingDirection} from '../util/moving-direction.enum';
import {WizardComponent} from './wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { MovingDirection } from '../util/moving-direction.enum';
import { WizardComponent } from './wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -53,13 +53,17 @@ describe('WizardCompletionStepComponent', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create', () => {
expect(wizardTest).toBeTruthy();
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/wizard-navigation-bar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ describe('WizardNavigationBarComponent', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create', () => {
expect(wizardTest).toBeTruthy();
Expand Down
20 changes: 12 additions & 8 deletions src/lib/components/wizard-step.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {MovingDirection} from '../util/moving-direction.enum';
import {WizardComponent} from './wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { MovingDirection } from '../util/moving-direction.enum';
import { WizardComponent } from './wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -53,13 +53,17 @@ describe('WizardStepComponent', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create', () => {
expect(wizardTest).toBeTruthy();
Expand Down
22 changes: 9 additions & 13 deletions src/lib/components/wizard.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AfterViewInit, ChangeDetectorRef, Component, ViewChild } from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { WizardComponent } from './wizard.component';
import { WizardStep } from '../util/wizard-step.interface';
import { WizardComponent } from './wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand All @@ -23,7 +23,7 @@ import { WizardStep } from '../util/wizard-step.interface';
</aw-wizard>
`
})
class WizardTestComponent implements AfterViewInit {
class WizardTestComponent {
public navigateForward = 'deny';
public navigateBackward = 'deny';

Expand All @@ -36,14 +36,6 @@ class WizardTestComponent implements AfterViewInit {

@ViewChild(WizardComponent)
public wizard: WizardComponent;

constructor(private _changeDetectionRef: ChangeDetectorRef) {
}

public ngAfterViewInit(): void {
// Force another change detection in order to fix an occuring ExpressionChangedAfterItHasBeenCheckedError
this._changeDetectionRef.detectChanges();
}
}

describe('WizardComponent', () => {
Expand All @@ -59,13 +51,17 @@ describe('WizardComponent', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create', () => {
expect(wizardTest).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/wizard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export class WizardComponent implements AfterContentInit {
// initialize the model
this.updateWizardSteps(this.wizardStepsQueryList.toArray());

// finally reset the whole wizard componennt
this.reset();
// finally reset the whole wizard component
setTimeout(() => this.reset());
}

/**
Expand Down
17 changes: 11 additions & 6 deletions src/lib/directives/completed-step.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {ArchwizardModule} from '../archwizard.module';
import {WizardComponent} from '../components/wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ArchwizardModule } from '../archwizard.module';
import { WizardComponent } from '../components/wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -31,11 +31,16 @@ describe('WizardStep', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizard = wizardTestFixture.componentInstance.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should mark initially completed steps', () => {
expect(wizard.getStepAtIndex(0).completed).toBe(false);
Expand Down
20 changes: 12 additions & 8 deletions src/lib/directives/enable-back-links.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {MovingDirection} from '../util/moving-direction.enum';
import {WizardComponent} from '../components/wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { MovingDirection } from '../util/moving-direction.enum';
import { WizardComponent } from '../components/wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -56,13 +56,17 @@ describe('EnableBackLinksDirective', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create', () => {
expect(wizardTest).toBeTruthy();
Expand Down
20 changes: 12 additions & 8 deletions src/lib/directives/go-to-step.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {GoToStepDirective} from './go-to-step.directive';
import {WizardComponent} from '../components/wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { GoToStepDirective } from './go-to-step.directive';
import { WizardComponent } from '../components/wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -68,13 +68,17 @@ describe('GoToStepDirective', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create an instance', () => {
expect(wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'))
Expand Down
21 changes: 12 additions & 9 deletions src/lib/directives/next-step.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {NavigationMode} from '../navigation/navigation-mode.interface';
import {NextStepDirective} from './next-step.directive';
import {WizardComponent} from '../components/wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { WizardComponent } from '../components/wizard.component';
import { NextStepDirective } from './next-step.directive';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -53,13 +52,17 @@ describe('NextStepDirective', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create an instance', () => {
expect(wizardTestFixture.debugElement.query(
Expand Down
20 changes: 12 additions & 8 deletions src/lib/directives/optional-step.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {OptionalStepDirective} from './optional-step.directive';
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {WizardComponent} from '../components/wizard.component';
import { OptionalStepDirective } from './optional-step.directive';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { WizardComponent } from '../components/wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -40,13 +40,17 @@ describe('OptionalStepDirective', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create an instance', () => {
expect(wizardTestFixture.debugElement.query(By.directive(OptionalStepDirective))).toBeTruthy();
Expand Down
20 changes: 12 additions & 8 deletions src/lib/directives/previous-step.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, ViewChild} from '@angular/core';
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {ArchwizardModule} from '../archwizard.module';
import {PreviousStepDirective} from './previous-step.directive';
import {WizardComponent} from '../components/wizard.component';
import { Component, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ArchwizardModule } from '../archwizard.module';
import { PreviousStepDirective } from './previous-step.directive';
import { WizardComponent } from '../components/wizard.component';

@Component({
selector: 'aw-test-wizard',
Expand Down Expand Up @@ -52,13 +52,17 @@ describe('PreviousStepDirective', () => {
}).compileComponents();
}));

beforeEach(() => {
beforeEach(fakeAsync(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();

wizardTest = wizardTestFixture.componentInstance;
wizard = wizardTest.wizard;
});

// wait a tick to ensure that the initialization has been completed
tick();
wizardTestFixture.detectChanges();
}));

it('should create an instance', () => {
expect(wizardTestFixture.debugElement.query(
Expand Down

0 comments on commit d3f4071

Please sign in to comment.