From 38f52af49afaf33bd51086b42f3afe37258ce8f4 Mon Sep 17 00:00:00 2001 From: Bryan Tong Date: Sat, 23 Nov 2013 04:43:39 -0700 Subject: [PATCH] Fixed tests and upgraded karma config. Now uses Phantomjs to test against --- angular-pagination.spec.js | 85 ++++++++++++++++++++++++++----------- karma.conf.js | 87 +++++++++----------------------------- 2 files changed, 79 insertions(+), 93 deletions(-) mode change 100644 => 100755 angular-pagination.spec.js mode change 100644 => 100755 karma.conf.js diff --git a/angular-pagination.spec.js b/angular-pagination.spec.js old mode 100644 new mode 100755 index c3c55c8..1a7d389 --- a/angular-pagination.spec.js +++ b/angular-pagination.spec.js @@ -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) }) }) diff --git a/karma.conf.js b/karma.conf.js old mode 100644 new mode 100755 index 408b328..57c917a --- a/karma.conf.js +++ b/karma.conf.js @@ -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 + }) +} \ No newline at end of file