-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for ma-boolean-column and ma-checkbox-field directives
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/javascripts/test/unit/Crud/column/maBooleanColumnSpec.js
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,59 @@ | ||
/*global angular,inject,describe,it,expect,beforeEach*/ | ||
describe('directive: ma-boolean-column', function () { | ||
'use strict'; | ||
|
||
var directive = require('../../../../ng-admin/Crud/column/maBooleanColumn'); | ||
var BooleanField = require('admin-config/lib/Field/BooleanField'); | ||
|
||
angular.module('testapp_BooleanColumn', []).directive('maBooleanColumn', directive); | ||
|
||
var $compile, | ||
scope, | ||
directiveUsage = '<ma-boolean-column field="field" value="value"></ma-boolean-column>'; | ||
|
||
beforeEach(angular.mock.module('testapp_BooleanColumn')); | ||
|
||
beforeEach(inject(function (_$compile_, _$rootScope_) { | ||
$compile = _$compile_; | ||
scope = _$rootScope_; | ||
})); | ||
|
||
it("should contain a span tag", function () { | ||
scope.field = new BooleanField(); | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].nodeName).toBe('SPAN'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-ok when value is true", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = true; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-ok'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-remove when value is false", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = false; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-remove'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-ok when value is truthy", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = 1; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-ok'); | ||
}); | ||
|
||
it("should contain a span tag with classes glyphicon and glyphicon-remove when value is falsy", function () { | ||
scope.field = new BooleanField(); | ||
scope.value = 0; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].className).toBe('glyphicon glyphicon-remove'); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
src/javascripts/test/unit/Crud/field/maCheckboxFieldSpec.js
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,44 @@ | ||
/*global angular,inject,describe,it,expect,beforeEach*/ | ||
describe('directive: checkbox-field', function () { | ||
'use strict'; | ||
|
||
var directive = require('../../../../ng-admin/Crud/field/maCheckboxField'); | ||
var Field = require('admin-config/lib/Field/Field'); | ||
angular.module('testapp_CheckboxField', []).directive('maCheckboxField', directive); | ||
|
||
var $compile, | ||
scope, | ||
directiveUsage = '<ma-checkbox-field field="field" value="value"></ma-checkbox-field>'; | ||
|
||
beforeEach(angular.mock.module('testapp_CheckboxField')); | ||
|
||
beforeEach(inject(function (_$compile_, _$rootScope_) { | ||
$compile = _$compile_; | ||
scope = _$rootScope_; | ||
})); | ||
|
||
it("should contain an input tag", function () { | ||
scope.field = new Field(); | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].nodeName).toBe('INPUT'); | ||
}); | ||
|
||
it("should use the checkbox type", function () { | ||
scope.field = new Field(); | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.children()[0].type).toBe('checkbox'); | ||
}); | ||
|
||
it("should be checked according to the bounded value", function () { | ||
scope.field = new Field(); | ||
scope.value = true; | ||
var element = $compile(directiveUsage)(scope); | ||
scope.$digest(); | ||
expect(element.find('input').attr('checked')).toBeTruthy(); | ||
scope.value = false; | ||
scope.$digest(); | ||
expect(element.find('input').attr('checked')).toBeFalsy(); | ||
}); | ||
}); |