Skip to content

Commit 6d80203

Browse files
devversionjelbourn
authored andcommitted
test: set up e2e test for mdc-based input
Sets up e2e tests for the MDC-based input. These weren't copied in the initial MDC-based version of input and form-field.
1 parent a63bfc5 commit 6d80203

File tree

9 files changed

+132
-1
lines changed

9 files changed

+132
-1
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
/src/e2e-app/mdc-card/** @mmalerba
231231
/src/e2e-app/mdc-checkbox/** @mmalerba
232232
/src/e2e-app/mdc-chips/** @mmalerba
233+
/src/e2e-app/mdc-input/** @devversion
233234
/src/e2e-app/mdc-menu/** @crisbeto
234235
/src/e2e-app/mdc-progress-bar/** @crisbeto
235236
/src/e2e-app/mdc-radio/** @mmalerba

src/e2e-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ng_module(
3636
"//src/material-experimental/mdc-card",
3737
"//src/material-experimental/mdc-checkbox",
3838
"//src/material-experimental/mdc-chips",
39+
"//src/material-experimental/mdc-input",
3940
"//src/material-experimental/mdc-menu",
4041
"//src/material-experimental/mdc-progress-bar",
4142
"//src/material-experimental/mdc-radio",

src/e2e-app/devserver-configure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require.config({
3636
'@material/tab-bar': '@material/tab-bar/dist/mdc.tabBar',
3737
'@material/tab-indicator': '@material/tab-indicator/dist/mdc.tabIndicator',
3838
'@material/tab-scroller': '@material/tab-scroller/dist/mdc.tabScroller',
39-
'@material/text-field': '@material/textfield/dist/mdc.textField',
39+
'@material/textfield': '@material/textfield/dist/mdc.textfield',
4040
'@material/top-app-bar': '@material/top-app-bar/dist/mdc.topAppBar',
4141
}
4242
});

src/e2e-app/e2e-app/e2e-app-layout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<a mat-list-item [routerLink]="['mdc-card']">MDC Card</a>
2828
<a mat-list-item [routerLink]="['mdc-checkbox']">MDC Checkbox</a>
2929
<a mat-list-item [routerLink]="['mdc-chips']">MDC Chips</a>
30+
<a mat-list-item [routerLink]="['mdc-input']">MDC Input</a>
3031
<a mat-list-item [routerLink]="['mdc-menu']">MDC Menu</a>
3132
<a mat-list-item [routerLink]="['mdc-radio']">MDC Radio</a>
3233
<a mat-list-item [routerLink]="['mdc-slide-toggle']">MDC Slide Toggle</a>

src/e2e-app/e2e-app/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {MdcButtonE2e} from '../mdc-button/mdc-button-e2e';
1515
import {MdcCardE2e} from '../mdc-card/mdc-card-e2e';
1616
import {MdcCheckboxE2e} from '../mdc-checkbox/mdc-checkbox-e2e';
1717
import {MdcChipsE2e} from '../mdc-chips/mdc-chips-e2e';
18+
import {MdcInputE2E} from '../mdc-input/mdc-input-e2e';
1819
import {MdcMenuE2e} from '../mdc-menu/mdc-menu-e2e';
1920
import {MdcRadioE2e} from '../mdc-radio/mdc-radio-e2e';
2021
import {MdcSlideToggleE2e} from '../mdc-slide-toggle/mdc-slide-toggle-e2e';
@@ -50,6 +51,7 @@ export const E2E_APP_ROUTES: Routes = [
5051
{path: 'mdc-card', component: MdcCardE2e},
5152
{path: 'mdc-checkbox', component: MdcCheckboxE2e},
5253
{path: 'mdc-chips', component: MdcChipsE2e},
54+
{path: 'mdc-input', component: MdcInputE2E},
5355
{path: 'mdc-menu', component: MdcMenuE2e},
5456
{path: 'mdc-radio', component: MdcRadioE2e},
5557
{path: 'mdc-slide-toggle', component: MdcSlideToggleE2e},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {MatFormFieldModule} from '@angular/material-experimental/mdc-form-field';
11+
import {MatInputModule} from '@angular/material-experimental/mdc-input';
12+
import {MdcInputE2E} from './mdc-input-e2e';
13+
14+
@NgModule({
15+
imports: [MatFormFieldModule, MatInputModule],
16+
declarations: [MdcInputE2E],
17+
})
18+
export class MdcInputE2eModule {
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<section>
2+
<p>
3+
<mat-form-field>
4+
<mat-label>Enter some text</mat-label>
5+
<input matInput type="text" id="text-input">
6+
</mat-form-field>
7+
</p>
8+
<p>
9+
<mat-form-field>
10+
<mat-label>Enter a number</mat-label>
11+
<input matInput type="number" id="number-input">
12+
</mat-form-field>
13+
</p>
14+
<p>
15+
<mat-form-field>
16+
<mat-label>Enter some text</mat-label>
17+
<textarea matInput id="text-area"></textarea>
18+
</mat-form-field>
19+
</p>
20+
<p>
21+
<mat-form-field>
22+
<mat-label>Enter some text</mat-label>
23+
<textarea matInput cdkTextareaAutosize cdkAutosizeMaxRows="10" id="autosize-text-area">
24+
</textarea>
25+
</mat-form-field>
26+
</p>
27+
</section>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'mdc-input-e2e',
5+
templateUrl: 'mdc-input-e2e.html',
6+
})
7+
export class MdcInputE2E {}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {browser, by, element} from 'protractor';
2+
3+
describe('input', () => {
4+
5+
beforeEach(async () => await browser.get('/mdc-input'));
6+
7+
describe('text input', () => {
8+
9+
it('should update input value when user types', async () => {
10+
const input = element(by.id('text-input'));
11+
await input.sendKeys('abc123');
12+
expect(await input.getAttribute('value')).toBe('abc123');
13+
});
14+
});
15+
16+
describe('number input', () => {
17+
18+
it('should update input value when user types', async () => {
19+
const input = element(by.id('number-input'));
20+
await input.sendKeys('abc123');
21+
expect(await input.getAttribute('value')).toBe('123');
22+
});
23+
24+
it('should increment when increment button clicked', async () => {
25+
const input = element(by.id('number-input'));
26+
await input.click();
27+
28+
const size = await input.getSize();
29+
30+
await browser.actions()
31+
.mouseMove(input, {x: size.width - 5, y: 5})
32+
.perform();
33+
// Workaround: https://github.com/angular/protractor/issues/4578
34+
await browser.actions().click().perform();
35+
36+
expect(await input.getAttribute('value')).toBe('1');
37+
38+
await browser.actions()
39+
.mouseMove(input, {x: size.width - 5, y: size.height - 5})
40+
.perform();
41+
// Workaround: https://github.com/angular/protractor/issues/4578
42+
await browser.actions().click().perform();
43+
44+
expect(await input.getAttribute('value')).toBe('0');
45+
});
46+
});
47+
48+
describe('textarea', () => {
49+
50+
it('should update input value when user types', async () => {
51+
const input = element(by.id('text-area'));
52+
await input.sendKeys('abc123');
53+
expect(await input.getAttribute('value')).toBe('abc123');
54+
});
55+
});
56+
57+
describe('autosize-textarea', () => {
58+
59+
it('should resize correctly', async () => {
60+
const input = element(by.id('autosize-text-area'));
61+
await input.sendKeys('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
62+
});
63+
64+
it('should enfore max rows', async () => {
65+
const input = element(by.id('autosize-text-area'));
66+
await input.sendKeys(
67+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
68+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
69+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
70+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
71+
});
72+
});
73+
});

0 commit comments

Comments
 (0)