import './multi-check.js'; import crudModel from 'core/mocks/crud-model'; describe('Component vnMultiCheck', () => { let controller; let $element; beforeEach(angular.mock.module('vnCore', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(angular.mock.inject($componentController => { $element = angular.element(`
`); controller = $componentController('vnMultiCheck', {$element: $element}); controller._model = crudModel; controller._model.data = [ {id: 1, name: 'My item 1'}, {id: 2, name: 'My item 2'}, {id: 3, name: 'My item 3'} ]; })); describe('checked() setter', () => { it(`should set controller _checked property with the argument received then call toggle()`, () => { spyOn(controller, 'toggle'); controller.checked = crudModel; expect(controller._checked).toEqual(crudModel); expect(controller.toggle).toHaveBeenCalledWith(); }); }); describe('toggle()', () => { it(`should set checked property inside each existing element`, () => { const data = controller.model.data; expect(data[0].checked).not.toBeDefined(); expect(data[1].checked).not.toBeDefined(); expect(data[2].checked).not.toBeDefined(); controller._checked = true; controller.checkAll = true; controller.toggle(); expect(data[0].checked).toBeTruthy(); expect(data[1].checked).toBeTruthy(); expect(data[2].checked).toBeTruthy(); }); it(`should unset checked property inside each existing element`, () => { const data = controller.model.data; data[0].checked = true; data[1].checked = true; data[2].checked = true; controller._checked = false; controller.checkAll = false; controller.toggle(); expect(data[0].checked).toBeFalsy(); expect(data[1].checked).toBeFalsy(); expect(data[2].checked).toBeFalsy(); }); }); describe('areAllChecked()', () => { it(`should set return true if all elements are checked`, () => { const data = controller.model.data; data[0].checked = true; data[1].checked = true; data[2].checked = true; expect(controller.areAllChecked()).toBeTruthy(); }); it(`should set return false if not all elements are checked`, () => { const data = controller.model.data; data[0].checked = true; data[1].checked = false; data[2].checked = true; expect(controller.areAllChecked()).toBeFalsy(); }); }); describe('areAllUnchecked()', () => { it(`should set return true if all elements are unchecked`, () => { const data = controller.model.data; data[0].checked = false; data[1].checked = false; data[2].checked = false; expect(controller.areAllUnchecked()).toBeTruthy(); }); it(`should set return false if not all elements are unchecked`, () => { const data = controller.model.data; data[0].checked = false; data[1].checked = true; data[2].checked = false; expect(controller.areAllUnchecked()).toBeFalsy(); }); }); });