forked from madoar/angular-archwizard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It makes little sense to have tests for StrictNavigationMode, SemiStrictNavigationMode, FreeNavigationMode after the corresponding classes have been removed in madoar#211
- Loading branch information
Showing
4 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})); | ||
}); |