client summary front test

This commit is contained in:
Joan Sanchez 2018-08-09 15:10:45 +02:00
parent 337b4114f0
commit e587aebc70
1 changed files with 53 additions and 0 deletions

View File

@ -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);
});
});
});
});