fix(quickref-cookbook): fix date test to work in any timezone

closes #1062
This commit is contained in:
Filipe Silva 2016-04-08 02:20:37 +01:00 committed by Ward Bell
parent adb4093af7
commit 1ba1407385
1 changed files with 19 additions and 17 deletions

View File

@ -7,19 +7,19 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
it('should display no poster images after bootstrap', function () { it('should display no poster images after bootstrap', function () {
testImagesAreDisplayed(false); testImagesAreDisplayed(false);
}); });
it('should display proper movie data', function () { it('should display proper movie data', function () {
// We check only a few samples // We check only a few samples
var expectedSamples = [ var expectedSamples = [
{row: 0, column: 0, element: 'img', attr: 'src', value: 'images/hero.png', contains: true}, {row: 0, column: 0, element: 'img', attr: 'src', value: 'images/hero.png', contains: true},
{row: 0, column: 2, value: 'Celeritas'}, {row: 0, column: 2, value: 'Celeritas'},
{row: 1, column: 3, value: 'Dec 17, 2015'}, {row: 1, column: 3, matches: /Dec 1[678], 2015/}, // absorb timezone dif; we care about date format
{row: 1, column: 5, value: '$14.95'}, {row: 1, column: 5, value: '$14.95'},
{row: 2, column: 4, value: 'PG-13'}, {row: 2, column: 4, value: 'PG-13'},
{row: 2, column: 7, value: '100%'}, {row: 2, column: 7, value: '100%'},
{row: 2, column: 0, element: 'img', attr: 'src', value: 'images/ng-logo.png', contains: true}, {row: 2, column: 0, element: 'img', attr: 'src', value: 'images/ng-logo.png', contains: true},
]; ];
// Go through the samples // Go through the samples
var movieRows = getMovieRows(); var movieRows = getMovieRows();
for (var i = 0; i < expectedSamples.length; i++) { for (var i = 0; i < expectedSamples.length; i++) {
@ -27,18 +27,20 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
var tableCell = movieRows.get(sample.row) var tableCell = movieRows.get(sample.row)
.all(by.tagName('td')).get(sample.column); .all(by.tagName('td')).get(sample.column);
// Check the cell or its nested element // Check the cell or its nested element
var elementToCheck = sample.element var elementToCheck = sample.element
? tableCell.element(by.tagName(sample.element)) ? tableCell.element(by.tagName(sample.element))
: tableCell; : tableCell;
// Check element attribute or text // Check element attribute or text
var valueToCheck = sample.attr var valueToCheck = sample.attr
? elementToCheck.getAttribute(sample.attr) ? elementToCheck.getAttribute(sample.attr)
: elementToCheck.getText(); : elementToCheck.getText();
// Test for equals/contains // Test for equals/contains/match
if (sample.contains) { if (sample.contains) {
expect(valueToCheck).toContain(sample.value); expect(valueToCheck).toContain(sample.value);
} else if (sample.matches) {
expect(valueToCheck).toMatch(sample.matches);
} else { } else {
expect(valueToCheck).toEqual(sample.value); expect(valueToCheck).toEqual(sample.value);
} }
@ -48,11 +50,11 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
it('should display images after Show Poster', function () { it('should display images after Show Poster', function () {
testPosterButtonClick("Show Poster", true); testPosterButtonClick("Show Poster", true);
}); });
it('should hide images after Hide Poster', function () { it('should hide images after Hide Poster', function () {
testPosterButtonClick("Hide Poster", false); testPosterButtonClick("Hide Poster", false);
}); });
it('should display no movie when no favorite hero is specified', function () { it('should display no movie when no favorite hero is specified', function () {
testFavoriteHero(null, "Please enter your favorite hero."); testFavoriteHero(null, "Please enter your favorite hero.");
}); });
@ -60,14 +62,14 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
it('should display no movie for Magneta', function () { it('should display no movie for Magneta', function () {
testFavoriteHero("Magneta", "No movie, sorry!"); testFavoriteHero("Magneta", "No movie, sorry!");
}); });
it('should display a movie for Mr. Nice', function () { it('should display a movie for Mr. Nice', function () {
testFavoriteHero("Mr. Nice", "Excellent choice!"); testFavoriteHero("Mr. Nice", "Excellent choice!");
}); });
function testImagesAreDisplayed(isDisplayed) { function testImagesAreDisplayed(isDisplayed) {
var expectedMovieCount = 3; var expectedMovieCount = 3;
var movieRows = getMovieRows(); var movieRows = getMovieRows();
expect(movieRows.count()).toBe(expectedMovieCount); expect(movieRows.count()).toBe(expectedMovieCount);
for (var i = 0; i < expectedMovieCount; i++) { for (var i = 0; i < expectedMovieCount; i++) {
@ -75,26 +77,26 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
expect(movieImage.isDisplayed()).toBe(isDisplayed); expect(movieImage.isDisplayed()).toBe(isDisplayed);
} }
} }
function testPosterButtonClick(expectedButtonText, isDisplayed) { function testPosterButtonClick(expectedButtonText, isDisplayed) {
var posterButton = element(by.css('movie-list tr > th > button')); var posterButton = element(by.css('movie-list tr > th > button'));
expect(posterButton.getText()).toBe(expectedButtonText); expect(posterButton.getText()).toBe(expectedButtonText);
posterButton.click().then(function () { posterButton.click().then(function () {
testImagesAreDisplayed(isDisplayed); testImagesAreDisplayed(isDisplayed);
}) })
} }
function getMovieRows() { function getMovieRows() {
return element.all(by.css('movie-list tbody > tr')); return element.all(by.css('movie-list tbody > tr'));
} }
function testFavoriteHero(heroName, expectedLabel) { function testFavoriteHero(heroName, expectedLabel) {
var movieListComp = element(by.tagName('movie-list')); var movieListComp = element(by.tagName('movie-list'));
var heroInput = movieListComp.element(by.tagName('input')); var heroInput = movieListComp.element(by.tagName('input'));
var favoriteHeroLabel = movieListComp.element(by.tagName('h3')); var favoriteHeroLabel = movieListComp.element(by.tagName('h3'));
var resultLabel = movieListComp.element(by.css('span > p')); var resultLabel = movieListComp.element(by.css('span > p'));
heroInput.clear().then(function () { heroInput.clear().then(function () {
sendKeys(heroInput, heroName || '').then(function () { sendKeys(heroInput, heroName || '').then(function () {
expect(resultLabel.getText()).toBe(expectedLabel); expect(resultLabel.getText()).toBe(expectedLabel);