client side unit test for multi-check

This commit is contained in:
Carlos 2017-10-13 16:43:11 +02:00
parent 91b9c0bcf9
commit c1ea17a377
1 changed files with 59 additions and 1 deletions

View File

@ -85,7 +85,7 @@ describe('Component vnMultiCheck', () => {
expect(controller._models[1].checked).toBeTruthy();
});
describe('when id is all or any', () => {
describe('when id is any', () => {
it('should set element checked property based on controller._checkAll', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'any'};
@ -108,5 +108,63 @@ describe('Component vnMultiCheck', () => {
expect(controller._models[0].checked).toBeFalsy();
});
});
describe('when id is all', () => {
it('should set element checked property based on controller._checkAll property', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller.models = [
{name: 'name'}
];
expect(controller._models[0].checked).not.toBeDefined();
controller._checkAll = 1;
controller.switchChecks();
expect(controller._models[0].checked).toBeTruthy();
controller._checkAll = 0;
controller.switchChecks();
expect(controller._models[0].checked).toBeFalsy();
controller._checkAll = 2;
controller.switchChecks();
expect(controller._models[0].checked).toBeFalsy();
});
});
});
describe('$onChanges()', () => {
it('should set controller.type to empty object and checkAll to zero', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller._checkAll = 1;
controller.$onChanges();
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(0);
});
});
describe('$doCheck()', () => {
it('should set controller.type to empty object and checkAll based on controller.type.id', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller._checkAll = 0;
controller.$doCheck();
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(1);
controller.type = {id: 'any'};
controller.$doCheck();
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(0);
controller.type = {id: 'any other id name'};
controller.$doCheck();
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(2);
});
});
});