salix/modules/item/front/summary/index.spec.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Item', () => {
describe('Component summary', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('item'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnItemSummary');
controller.item = {id: 1};
}));
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
2018-09-25 07:28:55 +00:00
let data = {id: 1, name: 'Gem of mind'};
$httpBackend.when('GET', `/item/api/Items/1/getSummary`).respond(200, data);
$httpBackend.expect('GET', `/item/api/Items/1/getSummary`);
controller.getSummary();
$httpBackend.flush();
2018-09-25 07:28:55 +00:00
expect(controller.summary).toEqual(data);
});
});
describe('$onChanges()', () => {
it('should call getSummary when item.id is defined', () => {
spyOn(controller, 'getSummary');
controller.$onChanges();
expect(controller.getSummary).toHaveBeenCalledWith();
});
});
});
});