From fa7391145231b926e5c0b9f09f03349487b11053 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 18 Jun 2020 12:43:33 +0200 Subject: [PATCH] Added tests --- modules/zone/front/events/index.js | 12 ++- modules/zone/front/events/index.spec.js | 103 ++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 modules/zone/front/events/index.spec.js diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index d965d18924..66822bfc1e 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -6,12 +6,20 @@ class Controller extends Section { super($element, $); this.vnWeekDays = vnWeekDays; this.editMode = 'include'; + } - this.path = `Zones/${this.$params.id}/events`; - this.exclusionsPath = `Zones/${this.$params.id}/exclusions`; + $onInit() { this.refresh(); } + get path() { + return `Zones/${this.$params.id}/events`; + } + + get exclusionsPath() { + return `Zones/${this.$params.id}/exclusions`; + } + refresh() { let data = {}; this.$q.all([ diff --git a/modules/zone/front/events/index.spec.js b/modules/zone/front/events/index.spec.js new file mode 100644 index 0000000000..5f4347f312 --- /dev/null +++ b/modules/zone/front/events/index.spec.js @@ -0,0 +1,103 @@ +import './index'; + +describe('component vnZoneEvents', () => { + let $scope; + let controller; + let $httpBackend; + let $httpParamSerializer; + + beforeEach(ngModule('zone')); + + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; + $scope = $rootScope.$new(); + const $element = angular.element(``); + controller = $componentController('vnZoneEvents', {$element, $scope}); + controller.$params = {id: 1}; + })); + + describe('refresh()', () => { + it('should set the zone and then call both getSummary() and getWarehouses()', () => { + $httpBackend.expectGET(`Zones/1/events`).respond({id: 1}); + $httpBackend.expectGET(`Zones/1/exclusions`).respond({id: 1}); + controller.refresh(); + $httpBackend.flush(); + + const data = controller.$.data; + + expect(data.events).toBeDefined(); + expect(data.exclusions).toBeDefined(); + }); + }); + + describe('onSelection()', () => { + it('should call the edit() method', () => { + jest.spyOn(controller, 'edit').mockReturnThis(); + + const weekday = {}; + const days = []; + const type = 'EventType'; + const events = [{name: 'Event'}]; + const exclusions = []; + controller.editMode = 'include'; + controller.onSelection(days, type, weekday, events, exclusions); + + expect(controller.edit).toHaveBeenCalledWith({name: 'Event'}); + }); + + it('should call the create() method', () => { + jest.spyOn(controller, 'create').mockReturnThis(); + + const weekday = {dated: new Date()}; + const days = [weekday]; + const type = 'EventType'; + const events = []; + const exclusions = []; + controller.editMode = 'include'; + controller.onSelection(days, type, weekday, events, exclusions); + + expect(controller.create).toHaveBeenCalledWith(type, days, weekday); + }); + + it('should call the exclusionDelete() method', () => { + jest.spyOn(controller, 'exclusionDelete').mockReturnThis(); + + const weekday = {}; + const days = []; + const type = 'EventType'; + const events = []; + const exclusions = [{id: 1}]; + controller.editMode = 'delete'; + controller.onSelection(days, type, weekday, events, exclusions); + + expect(controller.exclusionDelete).toHaveBeenCalledWith(exclusions); + }); + + it('should call the exclusionCreate() method', () => { + jest.spyOn(controller, 'exclusionCreate').mockReturnThis(); + + const weekday = {}; + const days = [{dated: new Date()}]; + const type = 'EventType'; + const events = []; + const exclusions = []; + controller.editMode = 'delete'; + controller.onSelection(days, type, weekday, events, exclusions); + + expect(controller.exclusionCreate).toHaveBeenCalledWith(days); + }); + }); + + describe('onDeleteResponse()', () => { + it('', () => { }); + }); + + describe('exclusionCreate()', () => { + it('', () => { }); + }); + + describe('exclusionDelete()', () => { + it('', () => { }); + }); +});