65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
describe('Component vnCheck', () => {
|
|
let controller;
|
|
let $element;
|
|
|
|
beforeEach(ngModule('vnCore'));
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|