salix/front/core/components/check/check.spec.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-02-19 06:05:39 +00:00
describe('Component vnCheck', () => {
2019-02-19 06:04:56 +00:00
let controller;
let $element;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
2019-02-19 06:04:56 +00:00
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-check></vn-check`)($rootScope);
controller = $element.controller('vnCheck');
}));
afterEach(() => {
$element.remove();
});
describe('model() setter', () => {
it(`should set model value`, () => {
controller.model = true;
expect(controller.model).toEqual(true);
});
it(`should set model value to null if current model value is false and is a triple-state checkbox`, () => {
controller._model = false;
controller.tripleState = true;
controller.model = true;
expect(controller.model).toEqual(null);
});
});
describe('field() setter', () => {
it(`should set model value`, () => {
controller.field = true;
expect(controller.field).toEqual(true);
});
it(`should set model value and convert numerical values to boolean values`, () => {
controller.field = 1;
expect(controller.field).toEqual(true);
});
});
describe('isIntermediate() getter', () => {
it(`should return true if intermediate property is truthy`, () => {
controller.intermediate = true;
let result = controller.isIntermediate;
expect(result).toEqual(true);
});
it(`should return true if is a triple-state checkbox and has null or undefined value`, () => {
controller.tripleState = true;
controller.model = null;
let result = controller.isIntermediate;
expect(result).toEqual(true);
});
});
});