|
| 1 | +import { |
| 2 | + browser, by, element, ElementFinder, ExpectedConditions |
| 3 | +} from 'protractor'; |
| 4 | +import {expectFocusOn, expectToExist} from '../util/asserts'; |
| 5 | +import {pressKeys} from '../util/actions'; |
| 6 | +import {Key} from 'selenium-webdriver'; |
| 7 | +import {screenshot} from '../screenshot'; |
| 8 | + |
| 9 | +describe('stepper', () => { |
| 10 | + beforeEach(() => browser.get('/stepper')); |
| 11 | + |
| 12 | + it('should render a stepper', () => { |
| 13 | + expectToExist('md-horizontal-stepper'); |
| 14 | + screenshot('md-horizontal-stepper'); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('basic behavior', () => { |
| 18 | + it('should change steps correctly when stepper button is clicked', async () => { |
| 19 | + const previousButton = element.all(by.buttonText('Back')); |
| 20 | + const nextButton = element.all(by.buttonText('Next')); |
| 21 | + |
| 22 | + expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) |
| 23 | + .toBe('1\nFill out your name'); |
| 24 | + |
| 25 | + screenshot('start'); |
| 26 | + nextButton.get(0).click(); |
| 27 | + |
| 28 | + expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) |
| 29 | + .toBe('2\nFill out your address'); |
| 30 | + |
| 31 | + await browser.wait(ExpectedConditions.not( |
| 32 | + ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element'))))); |
| 33 | + screenshot('click next'); |
| 34 | + |
| 35 | + previousButton.get(0).click(); |
| 36 | + |
| 37 | + expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) |
| 38 | + .toBe('1\nFill out your name'); |
| 39 | + |
| 40 | + await browser.wait(ExpectedConditions.not( |
| 41 | + ExpectedConditions.presenceOf(element(by.css('div.mat-ripple-element'))))); |
| 42 | + screenshot('click back'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should change focus with keyboard interaction', () => { |
| 46 | + let stepHeaders = element.all(by.css('md-step-header')); |
| 47 | + stepHeaders.get(0).click(); |
| 48 | + |
| 49 | + expectFocusOn(stepHeaders.get(0)); |
| 50 | + |
| 51 | + pressKeys(Key.RIGHT); |
| 52 | + expectFocusOn(stepHeaders.get(1)); |
| 53 | + |
| 54 | + pressKeys(Key.RIGHT); |
| 55 | + expectFocusOn(stepHeaders.get(2)); |
| 56 | + |
| 57 | + pressKeys(Key.RIGHT); |
| 58 | + expectFocusOn(stepHeaders.get(0)); |
| 59 | + |
| 60 | + pressKeys(Key.LEFT); |
| 61 | + expectFocusOn(stepHeaders.get(2)); |
| 62 | + |
| 63 | + pressKeys(Key.SPACE, Key.ENTER); |
| 64 | + expectFocusOn(stepHeaders.get(2)); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('linear stepper', () => { |
| 69 | + let linearButton: ElementFinder; |
| 70 | + |
| 71 | + beforeEach(() => { |
| 72 | + linearButton = element(by.id('toggle-linear')); |
| 73 | + linearButton.click(); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should not move to next step when stepper button is clicked', () => { |
| 77 | + let nextButton = element.all(by.buttonText('Next')); |
| 78 | + nextButton.get(0).click(); |
| 79 | + |
| 80 | + expect(element(by.css('md-step-header[aria-selected="true"]')).getText()) |
| 81 | + .toBe('1\nFill out your name'); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments