forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stepper): Add e2e test (angular#6776)
* add e2e test for stepper * create material example to run e2e tests * Modifiy example
- Loading branch information
1 parent
5f4c44e
commit bef6271
Showing
11 changed files
with
166 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
browser, by, element, ElementFinder, ExpectedConditions | ||
} from 'protractor'; | ||
import {expectFocusOn, expectToExist} from '../util/asserts'; | ||
import {pressKeys} from '../util/actions'; | ||
import {Key} from 'selenium-webdriver'; | ||
import {screenshot} from '../screenshot'; | ||
|
||
describe('stepper', () => { | ||
beforeEach(() => browser.get('/stepper')); | ||
|
||
it('should render a stepper', () => { | ||
expectToExist('md-horizontal-stepper'); | ||
screenshot('md-horizontal-stepper'); | ||
}); | ||
|
||
describe('basic behavior', () => { | ||
it('should change steps correctly when stepper button is clicked', async () => { | ||
const previousButton = element.all(by.buttonText('Back')); | ||
const nextButton = element.all(by.buttonText('Next')); | ||
|
||
expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) | ||
.toBe('1\nFill out your name'); | ||
|
||
screenshot('start'); | ||
nextButton.get(0).click(); | ||
|
||
expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) | ||
.toBe('2\nFill out your address'); | ||
|
||
await browser.wait(ExpectedConditions.not( | ||
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element'))))); | ||
screenshot('click next'); | ||
|
||
previousButton.get(0).click(); | ||
|
||
expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) | ||
.toBe('1\nFill out your name'); | ||
|
||
await browser.wait(ExpectedConditions.not( | ||
ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element'))))); | ||
screenshot('click back'); | ||
}); | ||
|
||
it('should change focus with keyboard interaction', () => { | ||
let stepHeaders = element.all(by.css('md-step-header')); | ||
stepHeaders.get(0).click(); | ||
|
||
expectFocusOn(stepHeaders.get(0)); | ||
|
||
pressKeys(Key.RIGHT); | ||
expectFocusOn(stepHeaders.get(1)); | ||
|
||
pressKeys(Key.RIGHT); | ||
expectFocusOn(stepHeaders.get(2)); | ||
|
||
pressKeys(Key.RIGHT); | ||
expectFocusOn(stepHeaders.get(0)); | ||
|
||
pressKeys(Key.LEFT); | ||
expectFocusOn(stepHeaders.get(2)); | ||
|
||
pressKeys(Key.SPACE, Key.ENTER); | ||
expectFocusOn(stepHeaders.get(2)); | ||
}); | ||
}); | ||
|
||
describe('linear stepper', () => { | ||
let linearButton: ElementFinder; | ||
|
||
beforeEach(() => { | ||
linearButton = element(by.id('toggle-linear')); | ||
linearButton.click(); | ||
}); | ||
|
||
it('should not move to next step when stepper button is clicked', () => { | ||
let nextButton = element.all(by.buttonText('Next')); | ||
nextButton.get(0).click(); | ||
|
||
expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) | ||
.toBe('1\nFill out your name'); | ||
}); | ||
}); | ||
}); |
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
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
1 change: 1 addition & 0 deletions
1
src/material-examples/stepper-overview/stepper-overview-example.css
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 @@ | ||
/** No CSS for this example */ |
33 changes: 33 additions & 0 deletions
33
src/material-examples/stepper-overview/stepper-overview-example.html
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,33 @@ | ||
<button (click)="isLinear=!isLinear" id="toggle-linear">Enable linear</button> | ||
<md-horizontal-stepper [linear]="isLinear"> | ||
<md-step [stepControl]="firstFormGroup"> | ||
<form [formGroup]="firstFormGroup"> | ||
<ng-template mdStepLabel>Fill out your name</ng-template> | ||
<md-form-field> | ||
<input mdInput placeholder="Last name, First name" formControlName="firstCtrl" required> | ||
</md-form-field> | ||
<div> | ||
<button md-button mdStepperNext>Next</button> | ||
</div> | ||
</form> | ||
</md-step> | ||
<md-step [stepControl]="secondFormGroup"> | ||
<form [formGroup]="secondFormGroup"> | ||
<ng-template mdStepLabel>Fill out your address</ng-template> | ||
<md-form-field> | ||
<input mdInput placeholder="Address" formControlName="secondCtrl" required> | ||
</md-form-field> | ||
<div> | ||
<button md-button mdStepperPrevious>Back</button> | ||
<button md-button mdStepperNext>Next</button> | ||
</div> | ||
</form> | ||
</md-step> | ||
<md-step> | ||
<ng-template mdStepLabel>Done</ng-template> | ||
You are now done. | ||
<div> | ||
<button md-button mdStepperPrevious>Back</button> | ||
</div> | ||
</md-step> | ||
</md-horizontal-stepper> |
27 changes: 27 additions & 0 deletions
27
src/material-examples/stepper-overview/stepper-overview-example.ts
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,27 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; | ||
|
||
/** | ||
* @title Stepper overview | ||
*/ | ||
@Component({ | ||
selector: 'stepper-overview-example', | ||
templateUrl: 'stepper-overview-example.html', | ||
styleUrls: ['stepper-overview-example.css'] | ||
}) | ||
export class StepperOverviewExample { | ||
isLinear = false; | ||
firstFormGroup: FormGroup; | ||
secondFormGroup: FormGroup; | ||
|
||
constructor(private _formBuilder: FormBuilder) { } | ||
|
||
ngOnInit() { | ||
this.firstFormGroup = this._formBuilder.group({ | ||
firstCtrl: ['', Validators.required] | ||
}); | ||
this.secondFormGroup = this._formBuilder.group({ | ||
secondCtrl: ['', Validators.required] | ||
}); | ||
} | ||
} |