61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import './index';
|
|
|
|
describe('vnItemDescriptor', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
const item = {
|
|
id: 1,
|
|
itemType: {
|
|
warehouseFk: 1
|
|
},
|
|
isPhotoRequested: true
|
|
};
|
|
const stock = {
|
|
visible: 1,
|
|
available: 5
|
|
};
|
|
|
|
beforeEach(ngModule('item'));
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
|
$httpBackend = _$httpBackend_;
|
|
$httpBackend.whenRoute('GET', `Items/${item.id}/getVisibleAvailable`).respond(stock);
|
|
|
|
controller = $componentController('vnItemDescriptor', {$element: null});
|
|
}));
|
|
|
|
describe('loadData()', () => {
|
|
it(`should perform a get query to store the item data into the controller`, () => {
|
|
$httpBackend.expectGET(`Items/${item.id}/getCard`).respond(item);
|
|
controller.id = item.id;
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.item).toEqual(item);
|
|
});
|
|
});
|
|
|
|
describe('updateStock()', () => {
|
|
it(`should perform a get query to store the item data into the controller`, () => {
|
|
$httpBackend.expectGET(`Items/${item.id}/getCard`).respond(item);
|
|
controller.id = item.id;
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.item).toEqual(item);
|
|
});
|
|
});
|
|
|
|
describe('onUploadResponse()', () => {
|
|
it(`should change isPhotoRequested when a new photo is uploaded`, () => {
|
|
$httpBackend.expectPATCH(`Items/${item.id}`).respond();
|
|
controller.$rootScope = {imagePath: () => {}};
|
|
controller.$.photo = {setAttribute: () => {}};
|
|
controller.item = item;
|
|
controller.onUploadResponse();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.item.isPhotoRequested).toEqual(false);
|
|
});
|
|
});
|
|
});
|