Skip to content

Commit 2b847b2

Browse files
committed
Split the E2E utils class into smaller files.
1 parent 3823135 commit 2b847b2

File tree

11 files changed

+158
-166
lines changed

11 files changed

+158
-166
lines changed

e2e/components/dialog/dialog.e2e.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import {browser, by, element, Key} from 'protractor';
2-
import {E2EUtils} from '../../utils.e2e';
2+
import {expectToExist, expectFocusOn} from '../../util/asserts';
3+
import {pressKeys, clickElementAtPoint} from '../../util/actions';
4+
import {waitForElement} from '../../util/query';
35

46
describe('dialog', () => {
5-
const utils = new E2EUtils();
6-
77
beforeEach(() => browser.get('/dialog'));
88

99
it('should open a dialog', () => {
1010
element(by.id('default')).click();
11-
utils.expectToExist('md-dialog-container');
11+
expectToExist('md-dialog-container');
1212
});
1313

1414
it('should close by clicking on the backdrop', () => {
1515
element(by.id('default')).click();
1616

1717
waitForDialog().then(() => {
1818
clickOnBackrop();
19-
utils.expectToExist('md-dialog-container', false);
19+
expectToExist('md-dialog-container', false);
2020
});
2121
});
2222

2323
it('should close by pressing escape', () => {
2424
element(by.id('default')).click();
2525

2626
waitForDialog().then(() => {
27-
utils.pressKeys(Key.ESCAPE);
28-
utils.expectToExist('md-dialog-container', false);
27+
pressKeys(Key.ESCAPE);
28+
expectToExist('md-dialog-container', false);
2929
});
3030
});
3131

@@ -34,15 +34,15 @@ describe('dialog', () => {
3434

3535
waitForDialog().then(() => {
3636
element(by.id('close')).click();
37-
utils.expectToExist('md-dialog-container', false);
37+
expectToExist('md-dialog-container', false);
3838
});
3939
});
4040

4141
it('should focus the first focusable element', () => {
4242
element(by.id('default')).click();
4343

4444
waitForDialog().then(() => {
45-
utils.expectFocusOn('md-dialog-container input');
45+
expectFocusOn('md-dialog-container input');
4646
});
4747
});
4848

@@ -53,7 +53,7 @@ describe('dialog', () => {
5353

5454
waitForDialog().then(() => {
5555
clickOnBackrop();
56-
utils.expectFocusOn(openButton);
56+
expectFocusOn(openButton);
5757
});
5858
});
5959

@@ -63,8 +63,8 @@ describe('dialog', () => {
6363
waitForDialog().then(() => {
6464
let tab = Key.TAB;
6565

66-
utils.pressKeys(tab, tab, tab);
67-
utils.expectFocusOn('#close');
66+
pressKeys(tab, tab, tab);
67+
expectFocusOn('#close');
6868
});
6969
});
7070

@@ -73,24 +73,24 @@ describe('dialog', () => {
7373

7474
waitForDialog().then(() => {
7575
clickOnBackrop();
76-
utils.expectToExist('md-dialog-container');
76+
expectToExist('md-dialog-container');
7777
});
7878
});
7979

8080
it('should be able to prevent closing by pressing escape', () => {
8181
element(by.id('disabled')).click();
8282

8383
waitForDialog().then(() => {
84-
utils.pressKeys(Key.ESCAPE);
85-
utils.expectToExist('md-dialog-container');
84+
pressKeys(Key.ESCAPE);
85+
expectToExist('md-dialog-container');
8686
});
8787
});
8888

8989
function waitForDialog() {
90-
return utils.waitForElement('md-dialog-container');
90+
return waitForElement('md-dialog-container');
9191
}
9292

9393
function clickOnBackrop() {
94-
utils.clickElementAtPoint('.cdk-overlay-backdrop', { x: 0, y: 0 });
94+
clickElementAtPoint('.cdk-overlay-backdrop', { x: 0, y: 0 });
9595
}
9696
});
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import {browser} from 'protractor';
2-
import {E2EUtils} from '../../utils.e2e';
2+
import {expectToExist} from '../../util/asserts';
33

44
describe('grid-list', () => {
5-
const utils = new E2EUtils();
6-
75
beforeEach(() => browser.get('/grid-list'));
86

97
it('should render a grid list container', () => {
10-
utils.expectToExist('md-grid-list');
8+
expectToExist('md-grid-list');
119
});
1210

1311
it('should render list items inside the grid list container', () => {
14-
utils.expectToExist('md-grid-list md-grid-tile');
12+
expectToExist('md-grid-list md-grid-tile');
1513
});
1614
});

e2e/components/list/list.e2e.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import {browser} from 'protractor';
2-
import {E2EUtils} from '../../utils.e2e';
2+
import {expectToExist} from '../../util/asserts';
33

44
describe('list', () => {
5-
const utils = new E2EUtils();
6-
75
beforeEach(() => browser.get('/list'));
86

97
it('should render a list container', () => {
10-
utils.expectToExist('md-list');
8+
expectToExist('md-list');
119
});
1210

1311
it('should render list items inside the list container', () => {
14-
utils.expectToExist('md-list md-list-item');
12+
expectToExist('md-list md-list-item');
1513
});
1614
});

e2e/components/menu/menu.e2e.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import {browser, Key, protractor} from 'protractor';
2-
import {E2EUtils} from '../../utils.e2e';
32
import {MenuPage} from './menu-page';
3+
import {expectToExist, expectAlignedWith, expectFocusOn, expectLocation} from '../../util/asserts';
4+
import {pressKeys} from '../../util/actions';
45

56
describe('menu', () => {
67
const menuSelector = '.md-menu-panel';
7-
const utils = new E2EUtils();
88
let page: MenuPage;
99

1010
beforeEach(() => page = new MenuPage());
1111

1212
it('should open menu when the trigger is clicked', () => {
13-
utils.expectToExist(menuSelector, false);
13+
expectToExist(menuSelector, false);
1414
page.trigger().click();
1515

16-
utils.expectToExist(menuSelector);
16+
expectToExist(menuSelector);
1717
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
1818
});
1919

2020
it('should close menu when menu item is clicked', () => {
2121
page.trigger().click();
2222
page.items(0).click();
23-
utils.expectToExist(menuSelector, false);
23+
expectToExist(menuSelector, false);
2424
});
2525

2626
it('should run click handlers on regular menu items', () => {
@@ -43,20 +43,20 @@ describe('menu', () => {
4343
page.triggerTwo().click();
4444

4545
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
46-
utils.expectAlignedWith(page.menu(), '#trigger-two');
46+
expectAlignedWith(page.menu(), '#trigger-two');
4747

4848
page.backdrop().click();
49-
utils.expectToExist(menuSelector, false);
49+
expectToExist(menuSelector, false);
5050

5151
// TODO(kara): temporary, remove when #1607 is fixed
5252
browser.sleep(250);
5353
page.trigger().click();
5454

5555
expect(page.menu().getText()).toEqual('One\nTwo\nThree\nFour');
56-
utils.expectAlignedWith(page.menu(), '#trigger');
56+
expectAlignedWith(page.menu(), '#trigger');
5757

5858
page.backdrop().click();
59-
utils.expectToExist(menuSelector, false);
59+
expectToExist(menuSelector, false);
6060
});
6161

6262
it('should mirror classes on host to menu template in overlay', () => {
@@ -70,71 +70,71 @@ describe('menu', () => {
7070
beforeEach(() => {
7171
// click start button to avoid tabbing past navigation
7272
page.start().click();
73-
utils.pressKeys(Key.TAB);
73+
pressKeys(Key.TAB);
7474
});
7575

7676
it('should auto-focus the first item when opened with ENTER', () => {
77-
utils.pressKeys(Key.ENTER);
78-
utils.expectFocusOn(page.items(0));
77+
pressKeys(Key.ENTER);
78+
expectFocusOn(page.items(0));
7979
});
8080

8181
it('should auto-focus the first item when opened with SPACE', () => {
82-
utils.pressKeys(Key.SPACE);
83-
utils.expectFocusOn(page.items(0));
82+
pressKeys(Key.SPACE);
83+
expectFocusOn(page.items(0));
8484
});
8585

8686
it('should not focus the first item when opened with mouse', () => {
8787
page.trigger().click();
88-
utils.expectFocusOn(page.trigger());
88+
expectFocusOn(page.trigger());
8989
});
9090

9191
it('should focus subsequent items when down arrow is pressed', () => {
92-
utils.pressKeys(Key.ENTER, Key.DOWN);
93-
utils.expectFocusOn(page.items(1));
92+
pressKeys(Key.ENTER, Key.DOWN);
93+
expectFocusOn(page.items(1));
9494
});
9595

9696
it('should focus previous items when up arrow is pressed', () => {
97-
utils.pressKeys(Key.ENTER, Key.DOWN, Key.UP);
98-
utils.expectFocusOn(page.items(0));
97+
pressKeys(Key.ENTER, Key.DOWN, Key.UP);
98+
expectFocusOn(page.items(0));
9999
});
100100

101101
it('should skip disabled items using arrow keys', () => {
102-
utils.pressKeys(Key.ENTER, Key.DOWN, Key.DOWN);
103-
utils.expectFocusOn(page.items(3));
102+
pressKeys(Key.ENTER, Key.DOWN, Key.DOWN);
103+
expectFocusOn(page.items(3));
104104

105-
utils.pressKeys(Key.UP);
106-
utils.expectFocusOn(page.items(1));
105+
pressKeys(Key.UP);
106+
expectFocusOn(page.items(1));
107107
});
108108

109109
it('should close the menu when tabbing past items', () => {
110-
utils.pressKeys(Key.ENTER, Key.TAB);
111-
utils.expectToExist(menuSelector, false);
110+
pressKeys(Key.ENTER, Key.TAB);
111+
expectToExist(menuSelector, false);
112112

113-
utils.pressKeys(Key.TAB, Key.ENTER);
114-
utils.expectToExist(menuSelector);
113+
pressKeys(Key.TAB, Key.ENTER);
114+
expectToExist(menuSelector);
115115

116-
utils.pressKeys(protractor.Key.chord(Key.SHIFT, Key.TAB));
117-
utils.expectToExist(menuSelector, false);
116+
pressKeys(protractor.Key.chord(Key.SHIFT, Key.TAB));
117+
expectToExist(menuSelector, false);
118118
});
119119

120120
it('should wrap back to menu when arrow keying past items', () => {
121121
let down = Key.DOWN;
122-
utils.pressKeys(Key.ENTER, down, down, down);
123-
utils.expectFocusOn(page.items(0));
122+
pressKeys(Key.ENTER, down, down, down);
123+
expectFocusOn(page.items(0));
124124

125-
utils.pressKeys(Key.UP);
126-
utils.expectFocusOn(page.items(3));
125+
pressKeys(Key.UP);
126+
expectFocusOn(page.items(3));
127127
});
128128

129129
it('should focus before and after trigger when tabbing past items', () => {
130130
let shiftTab = protractor.Key.chord(Key.SHIFT, Key.TAB);
131131

132-
utils.pressKeys(Key.ENTER, Key.TAB);
133-
utils.expectFocusOn(page.triggerTwo());
132+
pressKeys(Key.ENTER, Key.TAB);
133+
expectFocusOn(page.triggerTwo());
134134

135135
// navigate back to trigger
136-
utils.pressKeys(shiftTab, Key.ENTER, shiftTab);
137-
utils.expectFocusOn(page.start());
136+
pressKeys(shiftTab, Key.ENTER, shiftTab);
137+
expectFocusOn(page.start());
138138
});
139139

140140
});
@@ -145,7 +145,7 @@ describe('menu', () => {
145145
page.trigger().click();
146146

147147
// menu.x should equal trigger.x, menu.y should equal trigger.y
148-
utils.expectAlignedWith(page.menu(), '#trigger');
148+
expectAlignedWith(page.menu(), '#trigger');
149149
});
150150

151151
it('should align overlay end to origin end when x-position is "before"', () => {
@@ -156,7 +156,7 @@ describe('menu', () => {
156156
// menu = 112px wide. trigger = 60px wide. 112 - 60 = 52px of menu to the left of trigger.
157157
// trigger.x (left corner) - 52px (menu left of trigger) = expected menu.x (left corner)
158158
// menu.y should equal trigger.y because only x position has changed.
159-
utils.expectLocation(page.beforeMenu(), {x: trigger.x - 52, y: trigger.y});
159+
expectLocation(page.beforeMenu(), {x: trigger.x - 52, y: trigger.y});
160160
});
161161
});
162162

@@ -168,7 +168,7 @@ describe('menu', () => {
168168
// menu.x should equal trigger.x because only y position has changed.
169169
// menu = 64px high. trigger = 20px high. 64 - 20 = 44px of menu extending up past trigger.
170170
// trigger.y (top corner) - 44px (menu above trigger) = expected menu.y (top corner)
171-
utils.expectLocation(page.aboveMenu(), {x: trigger.x, y: trigger.y - 44});
171+
expectLocation(page.aboveMenu(), {x: trigger.x, y: trigger.y - 44});
172172
});
173173
});
174174

@@ -178,7 +178,7 @@ describe('menu', () => {
178178

179179
// trigger.x (left corner) - 52px (menu left of trigger) = expected menu.x
180180
// trigger.y (top corner) - 44px (menu above trigger) = expected menu.y
181-
utils.expectLocation(page.combinedMenu(), {x: trigger.x - 52, y: trigger.y - 44});
181+
expectLocation(page.combinedMenu(), {x: trigger.x - 52, y: trigger.y - 44});
182182
});
183183
});
184184

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import {browser} from 'protractor';
2-
import {E2EUtils} from '../../utils.e2e';
2+
import {expectToExist} from '../../util/asserts';
33

44
describe('progress-bar', () => {
5-
const utils = new E2EUtils();
6-
75
beforeEach(() => browser.get('/progress-bar'));
86

97
it('should render a determinate progress bar', () => {
10-
utils.expectToExist('md-progress-bar[mode="determinate"]');
8+
expectToExist('md-progress-bar[mode="determinate"]');
119
});
1210

1311
it('should render a buffer progress bar', () => {
14-
utils.expectToExist('md-progress-bar[mode="buffer"]');
12+
expectToExist('md-progress-bar[mode="buffer"]');
1513
});
1614

1715
it('should render a query progress bar', () => {
18-
utils.expectToExist('md-progress-bar[mode="query"]');
16+
expectToExist('md-progress-bar[mode="query"]');
1917
});
2018

2119
it('should render a indeterminate progress bar', () => {
22-
utils.expectToExist('md-progress-bar[mode="indeterminate"]');
20+
expectToExist('md-progress-bar[mode="indeterminate"]');
2321
});
2422
});

e2e/components/slide-toggle/slide-toggle.e2e.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import {browser, element, by, Key} from 'protractor';
2-
import {E2EUtils} from '../../utils.e2e';
2+
import {expectToExist} from '../../util/asserts';
33

44
describe('slide-toggle', () => {
5-
const utils = new E2EUtils();
65
const getInput = () => element(by.css('#normal-slide-toggle input'));
76
const getNormalToggle = () => element(by.css('#normal-slide-toggle'));
87

98
beforeEach(() => browser.get('slide-toggle'));
109

1110
it('should render a slide-toggle', () => {
12-
utils.expectToExist('md-slide-toggle');
11+
expectToExist('md-slide-toggle');
1312
});
1413

1514
it('should change the checked state on click', () => {

0 commit comments

Comments
 (0)