-
Notifications
You must be signed in to change notification settings - Fork 98
/
enable-back-links.directive.spec.ts
135 lines (107 loc) · 4.58 KB
/
enable-back-links.directive.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import {Component} 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 {WizardState} from '../navigation/wizard-state.model';
import {MovingDirection} from '../util/moving-direction.enum';
@Component({
selector: 'aw-test-wizard',
template: `
<aw-wizard>
<aw-wizard-step stepTitle='Steptitle 1' (stepEnter)="enterInto($event, 1)" (stepExit)="exitFrom($event, 1)">
Step 1
</aw-wizard-step>
<aw-wizard-step stepTitle='Steptitle 2' [canExit]="isValid" awOptionalStep (stepEnter)="enterInto($event, 2)"
(stepExit)="exitFrom($event, 2)">
Step 2
</aw-wizard-step>
<aw-wizard-completion-step awEnableBackLinks stepTitle='Completion steptitle 3' (stepEnter)="enterInto($event, 3)"
(stepExit)="completionStepExit($event, 3)">
Step 3
</aw-wizard-completion-step>
</aw-wizard>
`
})
class WizardTestComponent {
public isValid: any = true;
public eventLog: Array<string> = [];
public completionStepExit: (direction: MovingDirection, source: number) => void = this.exitFrom;
public enterInto(direction: MovingDirection, destination: number): void {
this.eventLog.push(`enter ${MovingDirection[direction]} ${destination}`);
}
public exitFrom(direction: MovingDirection, source: number): void {
this.eventLog.push(`exit ${MovingDirection[direction]} ${source}`);
}
}
describe('EnableBackLinksDirective', () => {
let wizardTest: WizardTestComponent;
let wizardTestFixture: ComponentFixture<WizardTestComponent>;
let wizardState: WizardState;
let navigationMode: NavigationMode;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [WizardTestComponent],
imports: [ArchwizardModule]
}).compileComponents();
}));
beforeEach(() => {
wizardTestFixture = TestBed.createComponent(WizardTestComponent);
wizardTestFixture.detectChanges();
wizardTest = wizardTestFixture.componentInstance;
wizardState = wizardTestFixture.debugElement.query(By.css('aw-wizard')).injector.get(WizardState);
navigationMode = wizardState.navigationMode;
});
it('should create', () => {
expect(wizardTest).toBeTruthy();
expect(wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-step')).length).toBe(2);
expect(wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-completion-step')).length).toBe(1);
});
it('should be able to leave the completion step', fakeAsync(() => {
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
navigationMode.canGoToStep(0).then(result => expect(result).toBe(true));
navigationMode.canGoToStep(1).then(result => expect(result).toBe(true));
}));
it('should be able to leave the completion step in any direction', fakeAsync(() => {
wizardTest.isValid = false;
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(2);
expect(wizardState.currentStep.canExit).toBe(true);
}));
it('should leave the completion step', fakeAsync(() => {
wizardTest.isValid = false;
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(2);
navigationMode.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(1);
expect(wizardTest.eventLog)
.toEqual(['enter Forwards 1', 'exit Forwards 1', 'enter Forwards 3', 'exit Backwards 3', 'enter Backwards 2']);
}));
it('should work with changed stepExit value', fakeAsync(() => {
wizardTest.isValid = false;
wizardTest.completionStepExit = (direction: MovingDirection, source: number) => {
wizardTest.eventLog.push(`changed exit ${MovingDirection[direction]} ${source}`);
};
expect(wizardState.completed).toBe(false);
navigationMode.goToStep(2);
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(2);
expect(wizardState.completed).toBe(true);
navigationMode.goToPreviousStep();
tick();
wizardTestFixture.detectChanges();
expect(wizardState.currentStepIndex).toBe(1);
expect(wizardTest.eventLog)
.toEqual(['enter Forwards 1', 'exit Forwards 1', 'enter Forwards 3', 'changed exit Backwards 3', 'enter Backwards 2']);
expect(wizardState.completed).toBe(false);
}));
});