2017-10-13 14:26:47 +00:00
|
|
|
import './multi-check.js';
|
|
|
|
|
|
|
|
describe('Component vnMultiCheck', () => {
|
|
|
|
let $componentController;
|
2017-10-17 12:24:40 +00:00
|
|
|
let controller;
|
2017-10-13 14:26:47 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('client');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(_$componentController_ => {
|
|
|
|
$componentController = _$componentController_;
|
2017-10-17 12:24:40 +00:00
|
|
|
controller = $componentController('vnMultiCheck', {});
|
2017-10-13 14:26:47 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('models()', () => {
|
|
|
|
it(`should set controller _models property with the argument received`, () => {
|
|
|
|
let argument = 'I am the model';
|
|
|
|
controller.models = argument;
|
|
|
|
|
|
|
|
expect(controller._models).toEqual(argument);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkAll()', () => {
|
|
|
|
it(`should set controller _checkAll property with the argument received then call switchChecks()`, () => {
|
|
|
|
let argument = 'I am the model';
|
|
|
|
spyOn(controller, 'switchChecks');
|
|
|
|
controller.checkAll = argument;
|
|
|
|
|
|
|
|
expect(controller._checkAll).toEqual(argument);
|
|
|
|
expect(controller.switchChecks).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('switchChecks()', () => {
|
2017-10-19 10:31:55 +00:00
|
|
|
/* it(`should set checked property inside each existing elemenet when begings with no-`, () => {
|
2017-10-13 14:26:47 +00:00
|
|
|
controller.type = {id: 'no-name'};
|
|
|
|
controller.models = [
|
|
|
|
{name: 'name'},
|
|
|
|
{name: null}
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller._models[0].checked).not.toBeDefined();
|
|
|
|
expect(controller._models[1].checked).not.toBeDefined();
|
|
|
|
controller._checkAll = 1;
|
|
|
|
controller.switchChecks();
|
|
|
|
|
|
|
|
expect(controller._models[0].checked).toBeFalsy();
|
|
|
|
expect(controller._models[1].checked).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set checked property inside each existing elemenet when begings with equal-`, () => {
|
|
|
|
controller.type = {id: 'equal-name', name: 'name'};
|
|
|
|
controller.models = [
|
|
|
|
{name: null},
|
|
|
|
{name: 'name'}
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller._models[0].checked).not.toBeDefined();
|
|
|
|
expect(controller._models[1].checked).not.toBeDefined();
|
|
|
|
controller._checkAll = 1;
|
|
|
|
controller.switchChecks();
|
|
|
|
|
|
|
|
expect(controller._models[0].checked).toBeFalsy();
|
|
|
|
expect(controller._models[1].checked).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set checked property inside each existing elemenet when begings with anything but any, all, no- or equal-`, () => {
|
|
|
|
controller.type = {id: 'name'};
|
|
|
|
controller.models = [
|
|
|
|
{name: null},
|
|
|
|
{name: 'name'}
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller._models[0].checked).not.toBeDefined();
|
|
|
|
expect(controller._models[1].checked).not.toBeDefined();
|
|
|
|
controller._checkAll = 1;
|
|
|
|
controller.switchChecks();
|
|
|
|
|
|
|
|
expect(controller._models[0].checked).toBeFalsy();
|
|
|
|
expect(controller._models[1].checked).toBeTruthy();
|
|
|
|
});
|
2017-10-19 10:31:55 +00:00
|
|
|
*/
|
2017-10-13 14:43:11 +00:00
|
|
|
describe('when id is any', () => {
|
2017-10-13 14:26:47 +00:00
|
|
|
it('should set element checked property based on controller._checkAll', () => {
|
|
|
|
controller.type = {id: 'any'};
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2017-10-13 14:43:11 +00:00
|
|
|
|
|
|
|
describe('when id is all', () => {
|
|
|
|
it('should set element checked property based on controller._checkAll property', () => {
|
|
|
|
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', () => {
|
|
|
|
controller.type = {id: 'all'};
|
|
|
|
controller._checkAll = 1;
|
|
|
|
controller.$onChanges();
|
|
|
|
|
|
|
|
expect(controller.type).toEqual({});
|
|
|
|
expect(controller._checkAll).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-19 10:31:55 +00:00
|
|
|
/* describe('$doCheck()', () => {
|
2017-10-13 14:43:11 +00:00
|
|
|
it('should set controller.type to empty object and checkAll based on controller.type.id', () => {
|
|
|
|
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);
|
|
|
|
});
|
2017-10-19 10:31:55 +00:00
|
|
|
}); */
|
2017-10-13 14:26:47 +00:00
|
|
|
});
|