Skip to content

Commit

Permalink
Fixed tests and upgraded karma config. Now uses Phantomjs to test aga…
Browse files Browse the repository at this point in the history
…inst
  • Loading branch information
nullivex committed Nov 23, 2013
1 parent 10ab63d commit 38f52af
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 93 deletions.
85 changes: 60 additions & 25 deletions angular-pagination.spec.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,33 +1,68 @@
'use strict'
describe('Angular Pagination', function(){
var pagination
/* global expect: false */
"use strict";
describe("Angular Pagination", function(){
var pg
// load the app
beforeEach(module('angular-pagination'))
beforeEach(module("pagination"))
// get service
beforeEach(inject(function(Pagination){
pagination = Pagination.getNew()
pg = new Pagination()
}))
it('should paginate', function(){
pagination.numPages = 2
expect(pagination.page).toBe(0)
pagination.nextPage()
expect(pagination.page).toBe(1)
pagination.prevPage()
expect(pagination.page).toBe(0)
it("should have page values that match defaults", function(){
expect(pg.pages).toBe(0)
expect(pg.page).toBe(1)
expect(pg.start).toBe(0)
expect(pg.limit).toBe(10)
})
it('should not paginate outside min and max page', function(){
pagination.numPages = 2
pagination.page = 0
pagination.prevPage()
expect(pagination.page).toBe(0)
pagination.page = 1
pagination.nextPage()
expect(pagination.page).toBe(1)
it("should have correct values after setting new params",function(){
pg.set({start: 40, limit: 20, total: 120})
expect(pg.pages).toBe(6)
expect(pg.page).toBe(3)
expect(pg.start).toBe(40)
expect(pg.limit).toBe(20)
})
it('should jump to a given page id', function(){
pagination.numPages = 3
expect(pagination.page).toBe(0)
pagination.toPageId(2)
expect(pagination.page).toBe(2)
it("should have correct values using first/prev/next/last",function(){
pg.set({start: 40, limit: 20, total: 120})
expect(pg.pages).toBe(6)
expect(pg.limit).toBe(20)
pg.set({start: pg.previous()})
expect(pg.page).toBe(2)
expect(pg.start).toBe(20)
pg.set({start: pg.next()})
expect(pg.page).toBe(3)
expect(pg.start).toBe(40)
pg.set({start: pg.first()})
expect(pg.page).toBe(1)
expect(pg.start).toBe(0)
pg.set({start: pg.last()})
expect(pg.page).toBe(6)
expect(pg.start).toBe(100)
pg.set({start: pg.forPage(2)})
expect(pg.page).toBe(2)
expect(pg.start).toBe(20)
})
it("should not paginate outside min and max page", function(){
//set non defaults and confirm
pg.set({start: 40, limit: 20, total: 120})
expect(pg.pages).toBe(6)
expect(pg.limit).toBe(20)
//set page way above max and make sure we didnt bleed over
pg.set({start: pg.forPage(20)})
expect(pg.page).toBe(6)
expect(pg.start).toBe(100)
//set page way below min and make sure we didnt bleed under
pg.set({start: pg.forPage(-50)})
expect(pg.page).toBe(1)
expect(pg.start).toBe(0)
//make sure previous doesnt go below 0
pg.set({start: pg.first()})
pg.set({start: pg.previous()})
expect(pg.page).toBe(1)
expect(pg.start).toBe(0)
//make sure next doesnt go above max
pg.set({start: pg.last()})
pg.set({start: pg.next()})
expect(pg.page).toBe(6)
expect(pg.start).toBe(100)
})
})
87 changes: 19 additions & 68 deletions karma.conf.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,69 +1,20 @@
// Karma configuration
// Generated on Thu Jun 06 2013 10:51:45 GMT+0100 (BST)


// base path, that will be used to resolve files and exclude
basePath = '';


// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'http://code.angularjs.org/1.0.7/angular.js',
'http://code.angularjs.org/1.0.7/angular-mocks.js',
'angular-pagination.js',
'angular-pagination.spec.js'
];


// list of files to exclude
exclude = [

];


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress'];


// web server port
port = 9876;


// cli runner port
runnerPort = 9100;


// enable / disable colors in the output (reporters and logs)
colors = true;


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;


// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['Chrome'];


// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;
module.exports = function(config){
config.set({
basePath: "",
frameworks: ["jasmine"],
files: [
"http://code.angularjs.org/1.2.2/angular.js",
"http://code.angularjs.org/1.2.2/angular-mocks.js",
"*.spec.js",
"angular-pagination.js"
],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["PhantomJS"],
captureTimeout: 60000,
singleRun: false
})
}

0 comments on commit 38f52af

Please sign in to comment.