Skip to content

Commit

Permalink
Clean up navigation unit tests
Browse files Browse the repository at this point in the history
It makes little sense to have tests for StrictNavigationMode, SemiStrictNavigationMode, FreeNavigationMode after the corresponding classes have been removed in madoar#211
  • Loading branch information
earshinov committed Jun 11, 2019
1 parent cb7a910 commit db2c902
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WizardTestComponent {
public wizard: WizardComponent;
}

describe('FreeNavigationMode', () => {
describe('Wizard navigation with navigateForward=allow', () => {
let wizardTestFixture: ComponentFixture<WizardTestComponent>;

let wizardTest: WizardTestComponent;
Expand Down Expand Up @@ -73,6 +73,8 @@ describe('FreeNavigationMode', () => {
tick();
wizardTestFixture.detectChanges();

// If forward navigation is allowed, visited steps after
// the selected step are still considered completed
checkWizardState(wizard, 0, [0, 1, 2], true);

wizard.goToStep(1);
Expand Down Expand Up @@ -103,7 +105,7 @@ describe('FreeNavigationMode', () => {
}));

it('should go to previous step', fakeAsync(() => {
expect(wizard.getStepAtIndex(0).completed).toBe(false);
checkWizardState(wizard, 0, [], false);

wizard.goToStep(1);
tick();
Expand All @@ -115,6 +117,8 @@ describe('FreeNavigationMode', () => {
tick();
wizardTestFixture.detectChanges();

// If forward navigation is allowed, visited steps after
// the selected step are still considered completed
checkWizardState(wizard, 0, [0, 1], false);
}));

Expand Down Expand Up @@ -161,6 +165,11 @@ describe('FreeNavigationMode', () => {

checkWizardState(wizard, 0, [], false);

wizard.defaultStepIndex = 1;
wizard.reset();

checkWizardState(wizard, 1, [], false);

wizard.defaultStepIndex = 2;
wizard.reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {checkWizardState} from '../util/test-utils';
@Component({
selector: 'aw-test-wizard',
template: `
<aw-wizard [awNavigationMode] navigateForward="allow">
<aw-wizard>
<aw-wizard-step stepTitle='Steptitle 1'>
Step 1
</aw-wizard-step>
Expand All @@ -25,7 +25,7 @@ class WizardTestComponent {
public wizard: WizardComponent;
}

describe('SemiStrictNavigationMode', () => {
describe('Wizard navigation with completion step', () => {
let wizardTestFixture: ComponentFixture<WizardTestComponent>;

let wizardTest: WizardTestComponent;
Expand Down Expand Up @@ -67,24 +67,28 @@ describe('SemiStrictNavigationMode', () => {
tick();
wizardTestFixture.detectChanges();

// Completion step is marked completed right after being navigated to,
// and marks the whole wizard completed as well.
checkWizardState(wizard, 2, [0, 1, 2], true);

wizard.goToStep(0);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [0, 1], false);
checkWizardState(wizard, 0, [0], false);

wizard.goToStep(1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0, 1], false);
checkWizardState(wizard, 1, [0], false);

wizard.goToStep(2);
tick();
wizardTestFixture.detectChanges();

// Completion step is marked completed right after being navigated to,
// and marks the whole wizard completed as well.
checkWizardState(wizard, 2, [0, 1, 2], true);

wizard.goToStep(1);
Expand All @@ -100,25 +104,22 @@ describe('SemiStrictNavigationMode', () => {
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0], false);
expect(wizard.completed).toBe(false);
}));

it('should go to previous step', fakeAsync(() => {
expect(wizard.getStepAtIndex(0).completed).toBe(false);
checkWizardState(wizard, 0, [], false);

wizard.goToStep(1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0], false);
expect(wizard.completed).toBe(false);

wizard.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [0, 1], false);
expect(wizard.completed).toBe(false);
checkWizardState(wizard, 0, [0], false);
}));

it('should stay at the current step', fakeAsync(() => {
Expand Down Expand Up @@ -152,6 +153,8 @@ describe('SemiStrictNavigationMode', () => {
tick();
wizardTestFixture.detectChanges();

// Completion step is marked completed right after being navigated to,
// and marks the whole wizard completed as well.
checkWizardState(wizard, 2, [0, 1, 2], true);

wizard.reset();
Expand All @@ -164,15 +167,15 @@ describe('SemiStrictNavigationMode', () => {

checkWizardState(wizard, 0, [], false);

wizard.defaultStepIndex = 1;
wizard.reset();

checkWizardState(wizard, 1, [], false);

wizard.defaultStepIndex = 2;
expect(() => wizard.reset())
.toThrow(new Error(`The default step index 2 references a completion step`));

checkWizardState(wizard, 0, [], false);

wizard.defaultStepIndex = 1;
wizard.reset();

checkWizardState(wizard, 1, [], false);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WizardTestComponent {
public wizard: WizardComponent;
}

describe('StrictNavigationMode', () => {
describe('Wizard navigation with optional step', () => {
let wizardTestFixture: ComponentFixture<WizardTestComponent>;

let wizardTest: WizardTestComponent;
Expand Down Expand Up @@ -118,6 +118,28 @@ describe('StrictNavigationMode', () => {
checkWizardState(wizard, 0, [0], false);
}));

it('should stay at the current step', fakeAsync(() => {
expect(wizard.getStepAtIndex(0).completed).toBe(false);

wizard.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [], false);

wizard.goToStep(-1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [], false);

wizard.goToStep(0);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [0], false);
}));

it('should reset the wizard correctly', fakeAsync(() => {
wizard.goToNextStep();
tick();
Expand All @@ -143,5 +165,10 @@ describe('StrictNavigationMode', () => {
wizard.reset();

checkWizardState(wizard, 1, [], false);

wizard.defaultStepIndex = 2;
wizard.reset();

checkWizardState(wizard, 2, [], false);
}));
});
174 changes: 174 additions & 0 deletions src/lib/navigation/wizard-navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
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 {checkWizardState} from '../util/test-utils';

@Component({
selector: 'aw-test-wizard',
template: `
<aw-wizard>
<aw-wizard-step stepTitle='Steptitle 1'>
Step 1
</aw-wizard-step>
<aw-wizard-step stepTitle='Steptitle 2'>
Step 2
</aw-wizard-step>
<aw-wizard-step stepTitle='Steptitle 3'>
Step 3
</aw-wizard-step>
</aw-wizard>
`
})
class WizardTestComponent {
@ViewChild(WizardComponent)
public wizard: WizardComponent;
}

describe('Wizard navigation', () => {
let wizardTestFixture: ComponentFixture<WizardTestComponent>;

let wizardTest: WizardTestComponent;
let wizard: WizardComponent;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [WizardTestComponent],
imports: [ArchwizardModule]
}).compileComponents();
}));

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

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

it('should return correct can go to step', async(() => {
wizard.canGoToStep(-1).then(result => expect(result).toBe(false));
wizard.canGoToStep(0).then(result => expect(result).toBe(true));
wizard.canGoToStep(1).then(result => expect(result).toBe(true));
wizard.canGoToStep(2).then(result => expect(result).toBe(false));
wizard.canGoToStep(3).then(result => expect(result).toBe(false));
}));

it('should go to step', fakeAsync(() => {
checkWizardState(wizard, 0, [], false);

wizard.goToStep(1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0], false);

wizard.goToStep(2);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 2, [0, 1], false);

wizard.goToStep(0);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [0], false);

wizard.goToStep(1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0], false);

wizard.goToStep(2);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 2, [0, 1], false);

wizard.goToStep(1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0, 1], false);
}));

it('should go to next step', fakeAsync(() => {
wizard.goToNextStep();
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0], false);
}));

it('should go to previous step', fakeAsync(() => {
checkWizardState(wizard, 0, [], false);

wizard.goToStep(1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 1, [0], false);

wizard.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [0], false);
}));

it('should stay at the current step', fakeAsync(() => {
expect(wizard.getStepAtIndex(0).completed).toBe(false);

wizard.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [], false);

wizard.goToStep(-1);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [], false);

wizard.goToStep(0);
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 0, [0], false);
}));

it('should reset the wizard correctly', fakeAsync(() => {
wizard.goToNextStep();
tick();
wizardTestFixture.detectChanges();

wizard.goToNextStep();
tick();
wizardTestFixture.detectChanges();

checkWizardState(wizard, 2, [0, 1], false);

wizard.reset();

checkWizardState(wizard, 0, [], false);

wizard.defaultStepIndex = -1;
expect(() => wizard.reset())
.toThrow(new Error(`The wizard doesn't contain a step with index -1`));

checkWizardState(wizard, 0, [], false);

wizard.defaultStepIndex = 1;
wizard.reset();

checkWizardState(wizard, 1, [], false);

wizard.defaultStepIndex = 2;
wizard.reset();

checkWizardState(wizard, 2, [], false);
}));
});

0 comments on commit db2c902

Please # to comment.