2018-08-21 11:13:51 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component summary', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2018-08-21 11:13:51 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
2018-08-21 11:13:51 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
controller = $componentController('vnItemSummary');
|
|
|
|
controller.item = {id: 1};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('getSummary()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should perform a query to set summary', () => {
|
2018-09-25 07:28:55 +00:00
|
|
|
let data = {id: 1, name: 'Gem of mind'};
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Items/1/getSummary`).respond(200, data);
|
|
|
|
$httpBackend.expect('GET', `Items/1/getSummary`);
|
2018-08-21 11:13:51 +00:00
|
|
|
controller.getSummary();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2018-09-25 07:28:55 +00:00
|
|
|
expect(controller.summary).toEqual(data);
|
2018-08-21 11:13:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('$onChanges()', () => {
|
2018-12-22 10:59:26 +00:00
|
|
|
it('should call getSummary when item.id is defined', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getSummary');
|
2018-08-21 11:13:51 +00:00
|
|
|
controller.$onChanges();
|
|
|
|
|
|
|
|
expect(controller.getSummary).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|