2018-09-05 11:47:15 +00:00
|
|
|
import './index.js';
|
2019-10-18 07:53:30 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-09-05 11:47:15 +00:00
|
|
|
|
|
|
|
describe('Claim', () => {
|
|
|
|
describe('Component summary', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2020-03-16 10:58:14 +00:00
|
|
|
let $scope;
|
2018-09-05 11:47:15 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('claim'));
|
2018-09-05 11:47:15 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
2020-03-16 10:58:14 +00:00
|
|
|
$scope = $rootScope.$new();
|
2018-09-05 11:47:15 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-16 10:58:14 +00:00
|
|
|
const $element = angular.element('<vn-claim-summary></vn-claim-summary>');
|
|
|
|
controller = $componentController('vnClaimSummary', {$element, $scope});
|
2020-03-17 10:17:50 +00:00
|
|
|
controller.claim = {id: 1};
|
2019-10-18 07:53:30 +00:00
|
|
|
controller.$.model = crudModel;
|
2018-09-05 11:47:15 +00:00
|
|
|
}));
|
|
|
|
|
2022-02-28 11:40:44 +00:00
|
|
|
describe('loadData()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should perform a query to set summary', () => {
|
2022-02-28 11:40:44 +00:00
|
|
|
$httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24);
|
|
|
|
controller.loadData();
|
2018-09-05 11:47:15 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.summary).toEqual(24);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-02-28 11:40:44 +00:00
|
|
|
describe('changeState()', () => {
|
2022-03-02 10:07:35 +00:00
|
|
|
it('should make an HTTP post query, then call the showSuccess()', () => {
|
2022-02-28 11:40:44 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
|
|
|
|
|
|
|
const expectedParams = {id: 1, claimStateFk: 1};
|
|
|
|
$httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24);
|
|
|
|
$httpBackend.expect('PATCH', `Claims/updateClaim/1`, expectedParams).respond(200);
|
|
|
|
controller.changeState(1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-05 11:47:15 +00:00
|
|
|
describe('$onChanges()', () => {
|
2022-03-02 10:07:35 +00:00
|
|
|
it('should call loadData when $onChanges is called', () => {
|
2022-02-28 11:40:44 +00:00
|
|
|
jest.spyOn(controller, 'loadData');
|
2020-03-16 10:58:14 +00:00
|
|
|
|
2018-09-05 11:47:15 +00:00
|
|
|
controller.$onChanges();
|
|
|
|
|
2022-02-28 11:40:44 +00:00
|
|
|
expect(controller.loadData).toHaveBeenCalledWith();
|
2018-09-05 11:47:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|