Skip to content

Commit

Permalink
Added tests for ma-boolean-column and ma-checkbox-field directives
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Sep 25, 2015
1 parent 76141ac commit 442bbd9
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/javascripts/test/unit/Crud/column/maBooleanColumnSpec.js
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 src/javascripts/test/unit/Crud/field/maCheckboxFieldSpec.js
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();
});
});

0 comments on commit 442bbd9

Please sign in to comment.