From 58f903b2941f65613d2ef1d803d306423ed26158 Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 8 May 2018 11:01:30 +0200 Subject: [PATCH] test para el refactor de culticheck Tarea #284 --- .../multi-check/multi-check.spec.js | 132 +----------------- 1 file changed, 6 insertions(+), 126 deletions(-) diff --git a/client/core/src/components/multi-check/multi-check.spec.js b/client/core/src/components/multi-check/multi-check.spec.js index a221e3cc7..b0d6f8cf9 100644 --- a/client/core/src/components/multi-check/multi-check.spec.js +++ b/client/core/src/components/multi-check/multi-check.spec.js @@ -13,16 +13,7 @@ describe('Component vnMultiCheck', () => { controller = $componentController('vnMultiCheck', {}); })); - 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()', () => { + describe('checkAll() setter', () => { it(`should set controller _checkAll property with the argument received then call switchChecks()`, () => { let argument = 'I am the model'; spyOn(controller, 'switchChecks'); @@ -35,129 +26,18 @@ describe('Component vnMultiCheck', () => { describe('switchChecks()', () => { it(`should set checked property inside each existing elemenet when id begings with no-`, () => { - controller.type = {id: 'no-name'}; - controller.models = [ + controller.data = [ {name: 'name'}, {name: null} ]; - expect(controller._models[0].checked).not.toBeDefined(); - expect(controller._models[1].checked).not.toBeDefined(); + expect(controller.data[0].checked).not.toBeDefined(); + expect(controller.data[1].checked).not.toBeDefined(); controller._checkAll = 1; controller.switchChecks(); - expect(controller._models[0].checked).toBeTruthy(); - expect(controller._models[1].checked).toBeTruthy(); - }); - - it(`should set checked property inside each existing elemenet when id 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).toBeTruthy(); - 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).toBeTruthy(); - expect(controller._models[1].checked).toBeTruthy(); - }); - - describe('when id is any', () => { - 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(); - }); - }); - - 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); - }); - }); - - describe('type setter', () => { - it('should set controller.type to empty object and checkAll based on controller.type.id', () => { - let value = {id: 'all'}; - controller._checkAll = 0; - controller.type = value; - - expect(controller.type).toEqual({}); - expect(controller._checkAll).toEqual(1); - value = {id: 'any'}; - controller.type = value; - - expect(controller.type).toEqual({}); - expect(controller._checkAll).toEqual(0); - value = {id: 'any other id name'}; - controller.type = value; - - expect(controller.type).toEqual({}); - expect(controller._checkAll).toEqual(2); + expect(controller.data[0].checked).toBeTruthy(); + expect(controller.data[1].checked).toBeTruthy(); }); }); });