43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
|
import './index.js';
|
||
|
|
||
|
describe('Item', () => {
|
||
|
describe('Component summary', () => {
|
||
|
let controller;
|
||
|
let $httpBackend;
|
||
|
let $scope;
|
||
|
|
||
|
beforeEach(ngModule('item'));
|
||
|
|
||
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
$scope = $rootScope.$new();
|
||
|
const $element = angular.element('<vn-item-summary></vn-item-summary>');
|
||
|
controller = $componentController('vnItemSummary', {$element, $scope});
|
||
|
controller.item = {id: 1};
|
||
|
controller.card = {};
|
||
|
}));
|
||
|
|
||
|
describe('getSummary()', () => {
|
||
|
it('should perform a query to set summary', () => {
|
||
|
let data = {id: 1, name: 'Gem of mind'};
|
||
|
$httpBackend.expect('GET', `Items/1/getSummary`).respond(200, data);
|
||
|
$httpBackend.expect('GET', `ItemConfigs/findOne`).respond({});
|
||
|
$httpBackend.expect('GET', `Warehouses/findOne`).respond({});
|
||
|
controller.getSummary();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(controller.summary).toEqual(data);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('$onChanges()', () => {
|
||
|
it('should call getSummary when item.id is defined', () => {
|
||
|
jest.spyOn(controller, 'getSummary');
|
||
|
controller.$onChanges();
|
||
|
|
||
|
expect(controller.getSummary).toHaveBeenCalledWith();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|