Skip to content

Commit 586b293

Browse files
committed
- optional steps can belong to the css class default too now
- added additional tests for clicks on links in the navigation bar - imporoved the existing tests for the navigation bar - added string as a valid type for the destinationStep input to the goToStep directive - added Code climate for code coverage
1 parent 6abd28f commit 586b293

File tree

6 files changed

+92
-18
lines changed

6 files changed

+92
-18
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ node_js:
1010

1111
before_install: if [[ `npm -v` != 3* || `npm -v` != 4* ]]; then npm i -g npm@3; fi
1212

13+
addons:
14+
code_climate:
15+
repo_token: 185e4d44752c64f89d9e5c50eb3a8d5ec421acf3b58b7cdb01ddcff2257336dd
16+
17+
after_success:
18+
- npm install -g codeclimate-test-reporter
19+
- codeclimate-test-reporter < lcov.info

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
[![Dependency Status](https://david-dm.org/madoar/ng2-wizard.svg)](https://david-dm.org/madoar/ng2-wizard)
55
[![Dev-Dependency Status](https://david-dm.org/madoar/ng2-wizard/dev-status.svg)](https://david-dm.org/madoar/ng2-wizard?type=dev)
66
[![Dependency Licence Status](https://dependencyci.com/github/madoar/ng2-wizard/badge)](https://dependencyci.com/github/madoar/ng2-wizard)
7+
[![Code Climate](https://codeclimate.com/github/madoar/ng2-wizard/badges/gpa.svg)](https://codeclimate.com/github/madoar/ng2-wizard)
8+
[![Test Coverage](https://codeclimate.com/github/madoar/ng2-wizard/badges/coverage.svg)](https://codeclimate.com/github/madoar/ng2-wizard/coverage)
79

810
This project contains a functional wizard component for [Angular 2](https://angular.io/).
911

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"less": "^2.7.1",
8383
"less-loader": "^2.2.3",
8484
"node-sass": "^3.4.2",
85-
"phantomjs-prebuilt": "^2.1.4",
85+
"phantomjs-prebuilt": "^2.1.14",
8686
"postcss-loader": "^1.1.0",
8787
"protractor": "^4.0.10",
8888
"raw-loader": "0.5.1",

src/components/components/wizard-navigation-bar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ul class="steps-indicator steps-{{numberOfWizardSteps()}}">
22
<li *ngFor="let step of getWizardSteps()"
33
[ngClass]="{
4-
default: !step.completed && !step.selected && !step.optional,
4+
default: !step.completed && !step.selected,
55
current: step.selected && !step.completed,
66
done: step.completed && !step.selected,
77
editing: step.selected && step.completed,

src/components/components/wizard-navigation-bar.component.spec.ts

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ describe('WizardNavigationBarComponent', () => {
6969
expect(navBar.query(By.css('li.optional'))).toBe(navBar.query(By.css('li:nth-child(2)')));
7070
expect(navBar.queryAll(By.css('li.optional')).length).toBe(1);
7171

72-
// only the third step is marked as default (neither done, current or optional)
72+
// the second and third step is marked as default (neither done or current)
7373
expect(navBar.query(By.css('li.default'))).toBeTruthy();
74-
expect(navBar.query(By.css('li.default'))).toBe(navBar.query(By.css('li:nth-child(3)')));
75-
expect(navBar.queryAll(By.css('li.default')).length).toBe(1);
74+
expect(navBar.queryAll(By.css('li.default'))[0]).toBe(navBar.query(By.css('li:nth-child(2)')));
75+
expect(navBar.queryAll(By.css('li.default'))[1]).toBe(navBar.query(By.css('li:nth-child(3)')));
76+
expect(navBar.queryAll(By.css('li.default')).length).toBe(2);
7677
});
7778

7879
it('should show the second step correctly', () => {
@@ -98,7 +99,7 @@ describe('WizardNavigationBarComponent', () => {
9899
// no step is marked as optional, because the optional step is the current step
99100
expect(navBar.query(By.css('li.optional'))).toBeNull();
100101

101-
// only the third step is marked as default (neither done, current or optional)
102+
// only the third step is marked as default (neither done or current)
102103
expect(navBar.query(By.css('li.default'))).toBeTruthy();
103104
expect(navBar.query(By.css('li.default'))).toBe(navBar.query(By.css('li:nth-child(3)')));
104105
expect(navBar.queryAll(By.css('li.default')).length).toBe(1);
@@ -120,8 +121,8 @@ describe('WizardNavigationBarComponent', () => {
120121

121122
// the first and second step should be marked as done
122123
expect(navBar.query(By.css('li.done'))).toBeTruthy();
123-
expect(navBar.query(By.css('li.done:first-child'))).toBe(navBar.query(By.css('li:nth-child(1)')));
124-
expect(navBar.query(By.css('li.done:nth-child(2)'))).toBe(navBar.query(By.css('li:nth-child(2)')));
124+
expect(navBar.queryAll(By.css('li.done'))[0]).toBe(navBar.query(By.css('li:nth-child(1)')));
125+
expect(navBar.queryAll(By.css('li.done'))[1]).toBe(navBar.query(By.css('li:nth-child(2)')));
125126
expect(navBar.queryAll(By.css('li.done')).length).toBe(2);
126127

127128
// no step is marked as editing
@@ -159,8 +160,10 @@ describe('WizardNavigationBarComponent', () => {
159160
expect(navBar.query(By.css('li.optional'))).toBe(navBar.query(By.css('li:nth-child(2)')));
160161
expect(navBar.queryAll(By.css('li.optional')).length).toBe(1);
161162

162-
// no step is marked as default (neither done, current or optional)
163-
expect(navBar.query(By.css('li.default'))).toBeNull();
163+
// the second step is marked as default (neither done nor current)
164+
expect(navBar.query(By.css('li.default'))).toBeTruthy();
165+
expect(navBar.query(By.css('li.default'))).toBe(navBar.query(By.css('li:nth-child(2)')));
166+
expect(navBar.queryAll(By.css('li.default')).length).toBe(1);
164167
});
165168

166169
it('should show the first step correctly, after going back from the second step to the first step', () => {
@@ -188,10 +191,11 @@ describe('WizardNavigationBarComponent', () => {
188191
expect(navBar.query(By.css('li.optional'))).toBe(navBar.query(By.css('li:nth-child(2)')));
189192
expect(navBar.queryAll(By.css('li.optional')).length).toBe(1);
190193

191-
// no step is marked as default (neither done, current or optional)
194+
// the second and third step is marked as default (neither done or current)
192195
expect(navBar.query(By.css('li.default'))).toBeTruthy();
193-
expect(navBar.query(By.css('li.default'))).toBe(navBar.query(By.css('li:nth-child(3)')));
194-
expect(navBar.queryAll(By.css('li.default')).length).toBe(1);
196+
expect(navBar.queryAll(By.css('li.default'))[0]).toBe(navBar.query(By.css('li:nth-child(2)')));
197+
expect(navBar.queryAll(By.css('li.default'))[1]).toBe(navBar.query(By.css('li:nth-child(3)')));
198+
expect(navBar.queryAll(By.css('li.default')).length).toBe(2);
195199
});
196200

197201
it('should show the first step correctly, after first jumping from the first to the third step and then back from the third step to the first step', () => {
@@ -219,10 +223,11 @@ describe('WizardNavigationBarComponent', () => {
219223
expect(navBar.query(By.css('li.optional'))).toBe(navBar.query(By.css('li:nth-child(2)')));
220224
expect(navBar.queryAll(By.css('li.optional')).length).toBe(1);
221225

222-
// the third step is marked as default (neither done, current or optional)
226+
// the second and third step is marked as default (neither done or current)
223227
expect(navBar.query(By.css('li.default'))).toBeTruthy();
224-
expect(navBar.query(By.css('li.default'))).toBe(navBar.query(By.css('li:nth-child(3)')));
225-
expect(navBar.queryAll(By.css('li.default')).length).toBe(1);
228+
expect(navBar.queryAll(By.css('li.default'))[0]).toBe(navBar.query(By.css('li:nth-child(2)')));
229+
expect(navBar.queryAll(By.css('li.default'))[1]).toBe(navBar.query(By.css('li:nth-child(3)')));
230+
expect(navBar.queryAll(By.css('li.default')).length).toBe(2);
226231
});
227232

228233
it('should show the second step correctly, after first jumping from the first to the third step and then back from the third step to the second step', () => {
@@ -250,9 +255,69 @@ describe('WizardNavigationBarComponent', () => {
250255
// no step is marked as optional, because the optional step is the current step
251256
expect(navBar.query(By.css('li.optional'))).toBeNull();
252257

253-
// the third step is marked as default (neither done, current or optional)
258+
// the third step is marked as default (neither done or current)
254259
expect(navBar.query(By.css('li.default'))).toBeTruthy();
255260
expect(navBar.query(By.css('li.default'))).toBe(navBar.query(By.css('li:nth-child(3)')));
256261
expect(navBar.queryAll(By.css('li.default')).length).toBe(1);
257262
});
263+
264+
it('should move back to the first step from the second step, after clicking on the corresponding link', () => {
265+
const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1) > a')).nativeElement;
266+
267+
expect(wizardTest.wizard.currentStepIndex).toBe(0);
268+
269+
// go to the second step
270+
wizardTest.wizard.goToNextStep();
271+
expect(wizardTest.wizard.currentStepIndex).toBe(1);
272+
273+
// go back to the first step
274+
goToFirstStepLink.click();
275+
wizardTestFixture.detectChanges();
276+
277+
expect(wizardTest.wizard.currentStepIndex).toBe(0);
278+
});
279+
280+
it('should move back to the first step from the third step, after clicking on the corresponding link', () => {
281+
const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1) > a')).nativeElement;
282+
283+
expect(wizardTest.wizard.currentStepIndex).toBe(0);
284+
285+
// go to the second step
286+
wizardTest.wizard.goToStep(2);
287+
expect(wizardTest.wizard.currentStepIndex).toBe(2);
288+
289+
// go back to the first step
290+
goToFirstStepLink.click();
291+
wizardTestFixture.detectChanges();
292+
293+
expect(wizardTest.wizard.currentStepIndex).toBe(0);
294+
});
295+
296+
it('should move back to the second step from the third step, after clicking on the corresponding link', () => {
297+
const goToSecondStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(2) > a')).nativeElement;
298+
299+
expect(wizardTest.wizard.currentStepIndex).toBe(0);
300+
301+
// go to the second step
302+
wizardTest.wizard.goToStep(2);
303+
expect(wizardTest.wizard.currentStepIndex).toBe(2);
304+
305+
// go back to the first step
306+
goToSecondStepLink.click();
307+
wizardTestFixture.detectChanges();
308+
309+
expect(wizardTest.wizard.currentStepIndex).toBe(1);
310+
});
311+
312+
it('should not move to the second step from the first step, after clicking on the corresponding link', () => {
313+
const goToFirstStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(1)'));
314+
const goToSecondStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(2)'));
315+
const goToThirdStepLink = wizardTestFixture.debugElement.query(By.css('li:nth-child(3)'));
316+
317+
expect(wizardTest.wizard.currentStepIndex).toBe(0);
318+
// links contain a class that is not clickable (contains "pointer-events: none;")
319+
expect(goToFirstStepLink.classes.hasOwnProperty('current')).toBeTruthy('First step label is clickable');
320+
expect(goToSecondStepLink.classes.hasOwnProperty('default')).toBeTruthy('Second step label is clickable');
321+
expect(goToThirdStepLink.classes.hasOwnProperty('default')).toBeTruthy('Third step label is clickable');
322+
});
258323
});

src/components/directives/go-to-step.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class GoToStepDirective {
1414
public finalize = new EventEmitter();
1515

1616
@Input('goToStep')
17-
public destinationStep: WizardStepComponent | number;
17+
public destinationStep: WizardStepComponent | number | string;
1818

1919
constructor(private wizard: WizardComponent) { }
2020

0 commit comments

Comments
 (0)