Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(midway): rxPaginate page objects, with tests.
- Loading branch information
Showing
6 changed files
with
217 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,4 @@ | |
</tr> | ||
</tfoot> | ||
</table> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,52 @@ | ||
var demoPage = require('../../../utils/demo.page.js'); | ||
var rxPaginatePage = require('../rxPaginate.page.js').rxPaginate; | ||
var pagination = require('../rxPaginate.page.js').rxPaginate; | ||
var expect = require('chai').use(require('chai-as-promised')).expect; | ||
|
||
// Add midway tests to run | ||
describe('rxPaginate', function () { | ||
var ptor = rxPaginatePage.driver; | ||
|
||
it('beforeAll', function () { | ||
before(function () { | ||
demoPage.go(); | ||
var ptor = protractor.getInstance(); | ||
pagination = pagination.initialize(ptor.findElement(protractor.By.css('div.rx-paginate'))); | ||
}); | ||
|
||
// it.skip('should show element', function () { | ||
// // will fail b/c there is no element being added in component.html | ||
// expect(rxPaginatePage.rxPaginateElement.isDisplayed()).toEqual(true); | ||
// }); | ||
}); | ||
it('should jump forward to page 7 using pagination', function () { | ||
pagination.jumpToPage(7); | ||
expect(pagination.getCurrentPageNumber()).to.eventually.equal(7); | ||
}); | ||
|
||
it('should jump backward to page 2 using pagination', function () { | ||
pagination.jumpToPage(2); | ||
expect(pagination.getCurrentPageNumber()).to.eventually.equal(2); | ||
}); | ||
|
||
it('should navigate forward one page at a time', function () { | ||
pagination.nextPage(); | ||
expect(pagination.getCurrentPageNumber()).to.eventually.equal(3); | ||
}); | ||
|
||
it('should navigate backwards one page at a time', function () { | ||
pagination.previousPage(); | ||
pagination.previousPage(); | ||
expect(pagination.getCurrentPageNumber()).to.eventually.equal(1); | ||
}); | ||
|
||
it('should navigate to the last page', function () { | ||
var firstPage; | ||
pagination.getCurrentPageNumber().then(function (page) { | ||
firstPage = page; | ||
}); | ||
|
||
pagination.lastPage(); | ||
pagination.getCurrentPageNumber().then(function (page) { | ||
expect(page).to.be.above(firstPage); | ||
}); | ||
}); | ||
|
||
it('should navigate to the first page', function () { | ||
pagination.firstPage(); | ||
expect(pagination.getCurrentPageNumber()).to.eventually.equal(1); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,160 @@ | ||
/*jshint node:true*/ | ||
var Page = require('astrolabe').Page; | ||
var exceptions = require('exceptions'); | ||
var _ = require('lodash'); | ||
|
||
exports.rxPaginate = Page.create({ | ||
// Elements | ||
rxPaginateElement: { | ||
get: function () { | ||
return this.findElement(this.by.id('rxPaginateElement')); | ||
var page = { | ||
|
||
lnkCurrentPage: { | ||
get: function () { return this.rxPaginate.findElement(this.by.css('.pagination .active a')); } | ||
}, | ||
|
||
tblPagination: { | ||
get: function () { return this.rxPaginate.findElements(this.by.css('.pagination li a')); } | ||
}, | ||
|
||
jumpToPage: { | ||
value: function (pageNumber) { | ||
var page = this; | ||
if (pageNumber < 1) { | ||
page.NoSuchPageException.thro('Page number must be >= 1'); | ||
} | ||
|
||
return this.getPageNumbers().then(function (pageNumbers) { | ||
var pageIndex = _.indexOf(pageNumbers, pageNumber); | ||
if (pageIndex === -1) { | ||
// The page is not on the current page numbers list. | ||
// Let's navigate around and try again. | ||
if (_.min(pageNumbers) > pageNumber) { | ||
// The lowest available page is still too big. | ||
page.jumpToLowestAvailablePage(); | ||
// Try again. | ||
page.jumpToPage(pageNumber); | ||
} else { | ||
return page.getCurrentPageNumber().then(function (currentPage) { | ||
if (_.last(pageNumbers) == currentPage) { | ||
// We are at the last page, and we still need to go higher. | ||
var message = pageNumber + ' exceeds max page of ' + _.last(pageNumbers); | ||
page.NoSuchPageException.thro(message); | ||
} else { | ||
page.jumpToHighestAvailablePage(); | ||
// Try again. | ||
page.jumpToPage(pageNumber); | ||
} | ||
}); | ||
} | ||
} else { | ||
// Our target page is somewhere in the available pages list. | ||
return page.tblPagination.then(function (pagination) { | ||
// pageIndex + 2 will offset the ["First", "Prev"] links. | ||
return pagination[pageIndex + 2].then(function (page) { | ||
page.click(); | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
firstPage: { | ||
value: function () { | ||
return this.tblPagination.then(function (pages) { | ||
return pages[0].then(function (firstPage) { | ||
firstPage.click(); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
previousPage: { | ||
value: function () { | ||
return this.tblPagination.then(function (pages) { | ||
return pages[1].then(function (previousPage) { | ||
previousPage.click(); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
nextPage: { | ||
value: function () { | ||
return this.tblPagination.then(function (pages) { | ||
return pages[pages.length - 2].then(function (nextPage) { | ||
nextPage.click(); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
lastPage: { | ||
value: function () { | ||
return this.tblPagination.then(function (pages) { | ||
return _.last(pages).then(function (lastPage) { | ||
lastPage.click(); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
getCurrentPageNumber: { | ||
value: function () { | ||
return this.lnkCurrentPage.then(function (currentPage) { | ||
return currentPage.getText().then(function (text) { | ||
return parseInt(text, 10); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
getPageNumbers: { | ||
value: function () { | ||
// Return a list of page numbers available to paginate to. | ||
var pages = []; | ||
var css = 'a[ng-click$="pageNumber = n"]'; | ||
return this.driver.findElements(this.by.css(css)).then(function (pageNumbers) { | ||
_.forEach(pageNumbers, function (pageNumber) { | ||
return pageNumber.then(function (number) { | ||
return number.getText().then(function (n) { | ||
pages.push(parseInt(n, 10)); | ||
}); | ||
}); | ||
}); | ||
return pages; | ||
}); | ||
} | ||
}, | ||
|
||
jumpToLowestAvailablePage: { | ||
value: function () { | ||
return this.tblPagination.then(function (pagination) { | ||
return pagination[2].then(function (lowestLink) { | ||
lowestLink.click(); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
jumpToHighestAvailablePage: { | ||
value: function () { | ||
return this.tblPagination.then(function (pagination) { | ||
return pagination[pagination.length - 3].then(function (highestLink) { | ||
highestLink.click(); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
NoSuchPageException: { | ||
get: function () { return new exceptions.Exception('No such page'); } | ||
} | ||
|
||
}; | ||
|
||
exports.rxPaginate = { | ||
initialize: function (rxPaginationElement) { | ||
page.rxPaginate = { | ||
get: function () { return rxPaginationElement; } | ||
}; | ||
return Page.create(page); | ||
} | ||
}); | ||
}; |