diff --git a/client/client/src/summary/index.spec.js b/client/client/src/summary/index.spec.js new file mode 100644 index 0000000000..99c20e37d0 --- /dev/null +++ b/client/client/src/summary/index.spec.js @@ -0,0 +1,53 @@ +import './index'; + +describe('Client', () => { + describe('Component vnClientSummary', () => { + let $componentController; + let controller; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = $componentController('vnClientSummary'); + controller.client = {id: 101}; + })); + + describe('$onChanges()', () => { + it('should perform a GET query and define summary property', () => { + let res = {name: 'Superman', classifications: []}; + $httpBackend.when('GET', `/client/api/Clients/101/summary`).respond(200, res); + $httpBackend.expect('GET', `/client/api/Clients/101/summary`); + controller.$onChanges(); + $httpBackend.flush(); + + expect(controller.summary).toBeDefined(); + expect(controller.summary.name).toEqual('Superman'); + expect(controller.grade).toBeUndefined(); + }); + + it('should perform a GET query and define summary and grade property', () => { + let res = { + name: 'Superman', + classifications: [{insurances: [ + {id: 1, grade: 1} + ]}] + }; + $httpBackend.when('GET', `/client/api/Clients/101/summary`).respond(200, res); + $httpBackend.expect('GET', `/client/api/Clients/101/summary`); + controller.$onChanges(); + $httpBackend.flush(); + + expect(controller.summary).toBeDefined(); + expect(controller.summary.name).toEqual('Superman'); + expect(controller.grade).toBeDefined(); + expect(controller.grade).toEqual(1); + }); + }); + }); +});