2018-08-21 11:13:51 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component summary', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2020-03-17 13:43:46 +00:00
|
|
|
let $scope;
|
2018-08-21 11:13:51 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2018-08-21 11:13:51 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
2018-08-21 11:13:51 +00:00
|
|
|
$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});
|
2018-08-21 11:13:51 +00:00
|
|
|
controller.item = {id: 1};
|
2023-02-16 06:32:44 +00:00
|
|
|
controller.card = {};
|
2018-08-21 11:13:51 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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'};
|
2020-07-23 15:10:07 +00:00
|
|
|
$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({});
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|