-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
168 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
basePath: '', | ||
plugins: [ | ||
'karma-phantomjs-launcher', | ||
'karma-jasmine', | ||
'karma-ng-html2js-preprocessor' | ||
], | ||
frameworks: ['jasmine'], | ||
files: [ | ||
'node_modules/moment/moment.js', | ||
'node_modules/angular/angular.js', | ||
'node_modules/angular-mocks/angular-mocks.js', | ||
'src/js/*.js', | ||
'src/templates/*.html', | ||
'tests/**/*.js', | ||
], | ||
preprocessors: { | ||
"src/templates/*.html": ["ng-html2js"] | ||
}, | ||
ngHtml2JsPreprocessor: { | ||
stripPrefix: "src/templates/", | ||
moduleName: "ngFlatDatepicker", | ||
}, | ||
exclude: [], | ||
reporters: ['progress'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
browsers: ['PhantomJS'], | ||
}) | ||
} |
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,5 +1,4 @@ | ||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
|
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,5 +1,4 @@ | ||
(function(){ | ||
|
||
'use strict'; | ||
|
||
/** | ||
|
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*globals expect inject angular moment*/ | ||
|
||
describe('datepicker', function() { | ||
var $compile; | ||
var $rootScope; | ||
var $scope; | ||
var datepickerHtml; | ||
|
||
var input; | ||
var datepickerElement; | ||
var datepicker; | ||
var datepickerContainer; | ||
|
||
beforeEach(module('ngFlatDatepicker')); | ||
beforeEach(inject(function(_$compile_, _$rootScope_) { | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
$scope = $rootScope.$new(); | ||
datepickerHtml = '<div id="testContainer"><input ng-model="date" ng-flat-datepicker datepicker-config="datepickerConfig"> </input></div>' | ||
})); | ||
|
||
it("compiles it's directive", function() { | ||
//given | ||
$scope.datepickerConfig = {}; | ||
datepickerHtml = '<div id="testContainer"><input ng-model="date" ng-flat-datepicker datepicker-config="datepickerConfig"> </input></div>'; | ||
//when | ||
var node = $compile(datepickerHtml)($scope); | ||
$rootScope.$digest(); | ||
//then | ||
expect(node.children().hasClass('ng-flat-datepicker-wrapper')).toBe(true); | ||
}); | ||
|
||
it("compiles it's directive with a date set", function() { | ||
//given | ||
$rootScope.date = '02.05.1900'; | ||
$rootScope.datepickerConfig = { | ||
dateFormat: 'DD.MM.YYYY' | ||
} | ||
|
||
//when | ||
compileDatepickerAndPrepareTest(); | ||
|
||
//then | ||
expect(datepickerContainer.children().hasClass('ng-flat-datepicker-wrapper')).toBe(true); | ||
}); | ||
it("opens on input click", function() { | ||
//given | ||
compileDatepickerAndPrepareTest(); | ||
expect(datepicker.hasClass('ng-hide')).toBe(true); | ||
expect(datepicker.scope().pickerDisplayed).toBe(false); | ||
|
||
//when | ||
input.triggerHandler('click'); | ||
|
||
//then | ||
expect(datepicker.scope().pickerDisplayed).toBe(true); | ||
expect(datepicker.hasClass('ng-hide')).toBe(false); | ||
expect(datepicker.scope().currentWeeks.length > 0).toBe(true); | ||
}); | ||
it("updates the datepicker on model update", function() { | ||
//given | ||
$scope.date = '02.05.2000'; | ||
$scope.datepickerConfig = { | ||
dateFormat: 'DD.MM.YYYY' | ||
}; | ||
compileDatepickerAndPrepareTest(); | ||
|
||
//when | ||
$scope.date = '03.07.2000'; | ||
$rootScope.$digest(); | ||
input.triggerHandler('click'); | ||
$rootScope.$digest(); | ||
|
||
expect(datepicker.scope().calendarCursor.format('LLL')).toBe(moment.utc(new Date('2000-07-03')).format('LLL')); | ||
var selectedDateNode = angular.element(datepickerElement.getElementsByClassName('isSelected')); | ||
expect(selectedDateNode.html()).toBe('03'); | ||
}); | ||
|
||
it("updates the model on date select", function() { | ||
//given | ||
$scope.date = '2000-05-02'; | ||
$scope.datepickerConfig = { | ||
dateFormat: 'YYYY-MM-DD' | ||
}; | ||
compileDatepickerAndPrepareTest(); | ||
|
||
//when | ||
input.triggerHandler('click'); | ||
var dayNode = angular.element(datepickerElement.getElementsByClassName('day-item')[20]); | ||
var dayNodeDay = dayNode.html(); | ||
dayNode.triggerHandler('click'); | ||
$rootScope.$digest(); | ||
|
||
//then | ||
expect($scope.date).toBe('2000-05-'+dayNodeDay); | ||
}); | ||
|
||
function compileDatepickerAndPrepareTest(){ | ||
datepickerContainer = $compile(datepickerHtml)($scope); | ||
$rootScope.$digest(); | ||
|
||
input = datepickerContainer.find('input'); | ||
datepickerElement = datepickerContainer[0].getElementsByClassName('ng-flat-datepicker')[0]; | ||
datepicker = angular.element(datepickerElement); | ||
} | ||
}); |