Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 1ba1407

Browse files
filipesilvawardbell
authored andcommitted
fix(quickref-cookbook): fix date test to work in any timezone
closes #1062
1 parent adb4093 commit 1ba1407

File tree

1 file changed

+19
-17
lines changed
  • public/docs/_examples/cb-a1-a2-quick-reference

1 file changed

+19
-17
lines changed

public/docs/_examples/cb-a1-a2-quick-reference/e2e-spec.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,40 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
77
it('should display no poster images after bootstrap', function () {
88
testImagesAreDisplayed(false);
99
});
10-
10+
1111
it('should display proper movie data', function () {
1212
// We check only a few samples
1313
var expectedSamples = [
1414
{row: 0, column: 0, element: 'img', attr: 'src', value: 'images/hero.png', contains: true},
1515
{row: 0, column: 2, value: 'Celeritas'},
16-
{row: 1, column: 3, value: 'Dec 17, 2015'},
16+
{row: 1, column: 3, matches: /Dec 1[678], 2015/}, // absorb timezone dif; we care about date format
1717
{row: 1, column: 5, value: '$14.95'},
1818
{row: 2, column: 4, value: 'PG-13'},
1919
{row: 2, column: 7, value: '100%'},
2020
{row: 2, column: 0, element: 'img', attr: 'src', value: 'images/ng-logo.png', contains: true},
2121
];
22-
22+
2323
// Go through the samples
2424
var movieRows = getMovieRows();
2525
for (var i = 0; i < expectedSamples.length; i++) {
2626
var sample = expectedSamples[i];
2727
var tableCell = movieRows.get(sample.row)
2828
.all(by.tagName('td')).get(sample.column);
2929
// Check the cell or its nested element
30-
var elementToCheck = sample.element
30+
var elementToCheck = sample.element
3131
? tableCell.element(by.tagName(sample.element))
3232
: tableCell;
33-
33+
3434
// Check element attribute or text
3535
var valueToCheck = sample.attr
3636
? elementToCheck.getAttribute(sample.attr)
3737
: elementToCheck.getText();
3838

39-
// Test for equals/contains
39+
// Test for equals/contains/match
4040
if (sample.contains) {
4141
expect(valueToCheck).toContain(sample.value);
42+
} else if (sample.matches) {
43+
expect(valueToCheck).toMatch(sample.matches);
4244
} else {
4345
expect(valueToCheck).toEqual(sample.value);
4446
}
@@ -48,53 +50,53 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
4850
it('should display images after Show Poster', function () {
4951
testPosterButtonClick("Show Poster", true);
5052
});
51-
53+
5254
it('should hide images after Hide Poster', function () {
5355
testPosterButtonClick("Hide Poster", false);
5456
});
55-
57+
5658
it('should display no movie when no favorite hero is specified', function () {
5759
testFavoriteHero(null, "Please enter your favorite hero.");
5860
});
5961

6062
it('should display no movie for Magneta', function () {
6163
testFavoriteHero("Magneta", "No movie, sorry!");
6264
});
63-
65+
6466
it('should display a movie for Mr. Nice', function () {
6567
testFavoriteHero("Mr. Nice", "Excellent choice!");
6668
});
67-
69+
6870
function testImagesAreDisplayed(isDisplayed) {
6971
var expectedMovieCount = 3;
70-
72+
7173
var movieRows = getMovieRows();
7274
expect(movieRows.count()).toBe(expectedMovieCount);
7375
for (var i = 0; i < expectedMovieCount; i++) {
7476
var movieImage = movieRows.get(i).element(by.css('td > img'));
7577
expect(movieImage.isDisplayed()).toBe(isDisplayed);
7678
}
7779
}
78-
80+
7981
function testPosterButtonClick(expectedButtonText, isDisplayed) {
8082
var posterButton = element(by.css('movie-list tr > th > button'));
8183
expect(posterButton.getText()).toBe(expectedButtonText);
82-
84+
8385
posterButton.click().then(function () {
8486
testImagesAreDisplayed(isDisplayed);
8587
})
8688
}
87-
89+
8890
function getMovieRows() {
8991
return element.all(by.css('movie-list tbody > tr'));
9092
}
91-
93+
9294
function testFavoriteHero(heroName, expectedLabel) {
93-
var movieListComp = element(by.tagName('movie-list'));
95+
var movieListComp = element(by.tagName('movie-list'));
9496
var heroInput = movieListComp.element(by.tagName('input'));
9597
var favoriteHeroLabel = movieListComp.element(by.tagName('h3'));
9698
var resultLabel = movieListComp.element(by.css('span > p'));
97-
99+
98100
heroInput.clear().then(function () {
99101
sendKeys(heroInput, heroName || '').then(function () {
100102
expect(resultLabel.getText()).toBe(expectedLabel);

0 commit comments

Comments
 (0)