refactor(examples/e2e_test): Ts'ifying examples/e2_test

Translate AtScript in examples/e2e_test to TypeScript.

Closes #2294
This commit is contained in:
Ian Riley 2015-05-29 14:33:54 -07:00 committed by Tobias Bosch
parent 40150379ae
commit 5035a42287
21 changed files with 115 additions and 80 deletions

View File

@ -0,0 +1,5 @@
library examples.e2e_test.hello_world.hello_world_spec;
main() {
}

View File

@ -1,7 +1,8 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
describe('hello world', function () {
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
afterEach(testUtil.verifyNoBrowserErrors);
describe('hello world', function() {
afterEach(verifyNoBrowserErrors);
describe('static reflection', function() {
var URL = 'examples/src/hello_world/index.html';
@ -9,14 +10,14 @@ describe('hello world', function () {
it('should greet', function() {
browser.get(URL);
expect(getComponentText('hello-app', '.greeting')).toBe('hello world!');
expect(getComponentText('hello-app', '.greeting')).toEqual('hello world!');
});
it('should change greeting', function() {
browser.get(URL);
clickComponentButton('hello-app', '.changeButton');
expect(getComponentText('hello-app', '.greeting')).toBe('howdy world!');
expect(getComponentText('hello-app', '.greeting')).toEqual('howdy world!');
});
});
@ -26,23 +27,25 @@ describe('hello world', function () {
it('should greet', function() {
browser.get(URL);
expect(getComponentText('hello-app', '.greeting')).toBe('hello world!');
expect(getComponentText('hello-app', '.greeting')).toEqual('hello world!');
});
it('should change greeting', function() {
browser.get(URL);
clickComponentButton('hello-app', '.changeButton');
expect(getComponentText('hello-app', '.greeting')).toBe('howdy world!');
expect(getComponentText('hello-app', '.greeting')).toEqual('howdy world!');
});
});
});
function getComponentText(selector, innerSelector) {
return browser.executeScript('return document.querySelector("'+selector+'").querySelector("'+innerSelector+'").textContent');
return browser.executeScript('return document.querySelector("' + selector + '").querySelector("' +
innerSelector + '").textContent');
}
function clickComponentButton(selector, innerSelector) {
return browser.executeScript('return document.querySelector("'+selector+'").querySelector("'+innerSelector+'").click()');
return browser.executeScript('return document.querySelector("' + selector + '").querySelector("' +
innerSelector + '").click()');
}

View File

@ -0,0 +1,5 @@
library examples.e2e_test.key_events.key_events_spec;
main() {
}

View File

@ -1,53 +1,52 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
describe('key_events', function () {
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('key_events', function() {
var URL = 'examples/src/key_events/index.html';
afterEach(testUtil.verifyNoBrowserErrors);
beforeEach(() => {
browser.get(URL);
});
afterEach(verifyNoBrowserErrors);
beforeEach(() => { browser.get(URL); });
it('should display correct key names', function() {
var firstArea = element.all(by.css('.sample-area')).get(0);
expect(firstArea.getText()).toBe('(none)');
expect(firstArea.getText()).toEqual('(none)');
// testing different key categories:
firstArea.sendKeys(protractor.Key.ENTER);
expect(firstArea.getText()).toBe('enter');
expect(firstArea.getText()).toEqual('enter');
firstArea.sendKeys(protractor.Key.SHIFT, protractor.Key.ENTER);
expect(firstArea.getText()).toBe('shift.enter');
expect(firstArea.getText()).toEqual('shift.enter');
firstArea.sendKeys(protractor.Key.CONTROL, protractor.Key.SHIFT, protractor.Key.ENTER);
expect(firstArea.getText()).toBe('control.shift.enter');
expect(firstArea.getText()).toEqual('control.shift.enter');
firstArea.sendKeys(' ');
expect(firstArea.getText()).toBe('space');
expect(firstArea.getText()).toEqual('space');
// It would not work with a letter which position depends on the keyboard layout (ie AZERTY vs
// QWERTY), see https://code.google.com/p/chromedriver/issues/detail?id=553
firstArea.sendKeys('u');
expect(firstArea.getText()).toBe('u');
expect(firstArea.getText()).toEqual('u');
firstArea.sendKeys(protractor.Key.CONTROL, 'b');
expect(firstArea.getText()).toBe('control.b');
expect(firstArea.getText()).toEqual('control.b');
firstArea.sendKeys(protractor.Key.F1);
expect(firstArea.getText()).toBe('f1');
expect(firstArea.getText()).toEqual('f1');
firstArea.sendKeys(protractor.Key.ALT, protractor.Key.F1);
expect(firstArea.getText()).toBe('alt.f1');
expect(firstArea.getText()).toEqual('alt.f1');
firstArea.sendKeys(protractor.Key.CONTROL, protractor.Key.F1);
expect(firstArea.getText()).toBe('control.f1');
expect(firstArea.getText()).toEqual('control.f1');
// There is an issue with protractor.Key.NUMPAD0 (and other NUMPADx):
// chromedriver does not correctly set the location property on the event to
// specify that the key is on the numeric keypad (event.location = 3)
// so the following test fails:
// firstArea.sendKeys(protractor.Key.NUMPAD0);
// expect(firstArea.getText()).toBe('0');
// expect(firstArea.getText()).toEqual('0');
});
it('should correctly react to the specified key', function() {

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.button_spec;
main() {}

View File

@ -1,10 +1,10 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-button', function () {
describe('md-button', function() {
var url = 'examples/src/material/button/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
afterEach(verifyNoBrowserErrors);
// Buttons are broken right now, see https://github.com/angular/angular/issues/1602
});

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.checkbox_spec;
main() {}

View File

@ -1,18 +0,0 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
describe('md-checkbox', function () {
var url = 'examples/src/material/checkbox/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
it('should toggle a checkbox', function() {
var checkbox = element.all(by.css('md-checkbox')).first();
checkbox.click();
expect(checkbox.getAttribute('aria-checked')).toBe('true');
checkbox.click();
expect(checkbox.getAttribute('aria-checked')).toBe('false');
});
});

View File

@ -0,0 +1,18 @@
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-checkbox', function() {
var url = 'examples/src/material/checkbox/index.html';
beforeEach(() => { browser.get(url); });
afterEach(verifyNoBrowserErrors);
it('should toggle a checkbox', function() {
var checkbox = element.all(by.css('md-checkbox')).first();
checkbox.click();
expect(checkbox.getAttribute('aria-checked')).toEqual('true');
checkbox.click();
expect(checkbox.getAttribute('aria-checked')).toEqual('false');
});
});

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.dialog_spec;
main() {}

View File

@ -1,19 +1,19 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-dialog', function () {
describe('md-dialog', function() {
var url = 'examples/src/material/dialog/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
afterEach(verifyNoBrowserErrors);
it('should open a dialog', function() {
var openButton = element(by.id('open'));
openButton.click();
expect(element(by.css('.md-dialog')).isPresent()).toBe(true);
expect(element(by.css('.md-dialog')).isPresent()).toEqual(true);
var dialog = element(by.css('.md-dialog'));
dialog.sendKeys(protractor.Key.ESCAPE);
expect(element(by.css('.md-dialog')).isPresent()).toBe(false);
expect(element(by.css('.md-dialog')).isPresent()).toEqual(false);
});
});

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.grid_list_spec;
main() {}

View File

@ -1,10 +1,10 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-grid-list', function () {
describe('md-grid-list', function() {
var url = 'examples/src/material/grid_list/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
afterEach(verifyNoBrowserErrors);
it('should set tiles into different positions', () => {
var tiles = element.all(by.css('md-grid-list#complex md-grid-tile'));

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.input_spec;
main() {}

View File

@ -1,17 +1,16 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-input', function () {
describe('md-input', function() {
var url = 'examples/src/material/input/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
afterEach(verifyNoBrowserErrors);
it('should enter a value to the input', () => {
var input = element.all(by.css('md-input-container input')).first();
input.sendKeys('Hello');
expect(input.getAttribute('value')).toBe('Hello');
expect(input.getAttribute('value')).toEqual('Hello');
});
});

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.progress_linear_spec;
main() {}

View File

@ -1,10 +1,10 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-progress-linear', function () {
describe('md-progress-linear', function() {
var url = 'examples/src/material/progress-linear/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
afterEach(verifyNoBrowserErrors);
it('should increment and decrement progress', function() {
var progressBar = element.all(by.css('md-progress-linear')).first();

View File

@ -0,0 +1,3 @@
library examples.e2e_test.material.radio_spec;
main() {}

View File

@ -1,10 +1,10 @@
var testUtil = require('angular2/src/test_lib/e2e_util');
import {verifyNoBrowserErrors} from 'angular2/src/test_lib/e2e_util';
describe('md-radio-button', function () {
describe('md-radio-button', function() {
var url = 'examples/src/material/radio/index.html';
beforeEach(() => { browser.get(url); });
afterEach(testUtil.verifyNoBrowserErrors);
afterEach(verifyNoBrowserErrors);
it('should check one radio button and then check another', () => {
var standaloneRadios = element.all(by.css('[name="element"]'));
@ -12,10 +12,10 @@ describe('md-radio-button', function () {
var lastRadio = standaloneRadios.last();
firstRadio.click();
expect(firstRadio.getAttribute('aria-checked')).toBe('true');
expect(firstRadio.getAttribute('aria-checked')).toEqual('true');
lastRadio.click();
expect(firstRadio.getAttribute('aria-checked')).toBe('false');
expect(lastRadio.getAttribute('aria-checked')).toBe('true');
expect(firstRadio.getAttribute('aria-checked')).toEqual('false');
expect(lastRadio.getAttribute('aria-checked')).toEqual('true');
});
});

View File

@ -0,0 +1,5 @@
library examples.e2e_test.sourcemap.sourcemap_spec;
main() {
}

View File

@ -1,7 +1,9 @@
import * as testUtil from 'angular2/src/test_lib/e2e_util';
var fs = require('fs');
var sourceMap = require('source-map');
describe('sourcemaps', function () {
describe('sourcemaps', function() {
var URL = 'examples/src/sourcemap/index.html';
it('should map sources', function() {
@ -27,23 +29,19 @@ describe('sourcemaps', function () {
expect(errorColumn).not.toBeNull();
var sourceMapData = fs.readFileSync(
'dist/js/prod/es5/examples/src/sourcemap/index.js.map');
var sourceMapData = fs.readFileSync('dist/js/prod/es5/examples/src/sourcemap/index.js.map');
var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
var originalPosition = decoder.originalPositionFor({
line: errorLine,
column: errorColumn
});
var originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});
var finalMapData = fs.readFileSync(
'dist/js/prod/es6/examples/src/sourcemap/index.es6.map');
var finalMapData = fs.readFileSync('dist/js/prod/es6/examples/src/sourcemap/index.es6.map');
var finalDecoder = new sourceMap.SourceMapConsumer(JSON.parse(finalMapData));
var finalPosition = finalDecoder.originalPositionFor(originalPosition);
var sourceCodeLines = fs.readFileSync('modules/examples/src/sourcemap/index.ts',
{encoding: 'UTF-8'}).split('\n');
var sourceCodeLines =
fs.readFileSync('modules/examples/src/sourcemap/index.ts', {encoding: 'UTF-8'})
.split('\n');
expect(sourceCodeLines[finalPosition.line - 1])
.toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
});