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

43 lines
1.5 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Item', () => {
describe('Component summary', () => {
let controller;
let $httpBackend;
2020-03-17 13:43:46 +00:00
let $scope;
beforeEach(ngModule('item'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
2020-03-17 13:43:46 +00:00
$scope = $rootScope.$new();
const $element = angular.element('<vn-item-summary></vn-item-summary>');
controller = $componentController('vnItemSummary', {$element, $scope});
controller.item = {id: 1};
2023-02-16 06:32:44 +00:00
controller.card = {};
}));
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.expect('GET', `Items/1/getSummary`).respond(200, data);
2023-02-16 06:32:44 +00:00
$httpBackend.expect('GET', `ItemConfigs/findOne`).respond({});
$httpBackend.expect('GET', `Warehouses/findOne`).respond({});
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', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getSummary');
controller.$onChanges();
expect(controller.getSummary).toHaveBeenCalledWith();
});
});
});
});