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