completed task #144 tem tags bugs
This commit is contained in:
parent
33f19949d8
commit
701e6f9976
|
@ -18,7 +18,7 @@ describe('Item', () => {
|
|||
controller = $componentController('vnItemNiche', {$state: $state});
|
||||
}));
|
||||
|
||||
describe('add / remove niche()', () => {
|
||||
describe('add / remove niche', () => {
|
||||
it('should add one empty niche into controller niches collection and call _setIconAdd()', () => {
|
||||
controller.niches = [];
|
||||
spyOn(controller, '_setIconAdd').and.callThrough();
|
||||
|
@ -72,7 +72,7 @@ describe('Item', () => {
|
|||
it('should perform a GET query to receive the item niches', () => {
|
||||
let res = [{id: 1, warehouseFk: 1, code: '1111'}];
|
||||
|
||||
$httpBackend.when('GET', `/item/api/ItemNiches?filter={"where":{},"include":{"relation":"warehouse"}}`).respond(res);
|
||||
$httpBackend.whenGET(`/item/api/ItemNiches?filter={"where":{},"include":{"relation":"warehouse"}}`).respond(res);
|
||||
$httpBackend.expectGET(`/item/api/ItemNiches?filter={"where":{},"include":{"relation":"warehouse"}}`);
|
||||
controller.getNiches();
|
||||
$httpBackend.flush();
|
||||
|
@ -84,7 +84,7 @@ describe('Item', () => {
|
|||
{id: 2, warehouseFk: 2, name: 'warehouse two'}
|
||||
];
|
||||
|
||||
$httpBackend.when('GET', `/item/api/Warehouses`).respond(res);
|
||||
$httpBackend.whenGET(`/item/api/Warehouses`).respond(res);
|
||||
$httpBackend.expectGET(`/item/api/Warehouses`);
|
||||
controller.getWarehouses();
|
||||
$httpBackend.flush();
|
||||
|
@ -93,6 +93,7 @@ describe('Item', () => {
|
|||
|
||||
describe('submit()', () => {
|
||||
it("should return an error message 'The niche must be unique' when the niche code isnt unique", () => {
|
||||
controller.$scope.form = {};
|
||||
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||
controller.niches = [
|
||||
{warehouseFk: 1, code: 123454, itemFk: 1, id: 1},
|
||||
|
@ -105,17 +106,19 @@ describe('Item', () => {
|
|||
});
|
||||
|
||||
it("should perfom a query to delete niches", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.oldNiches = {1: {id: 1, warehouseFk: 1, code: '1111'}};
|
||||
controller.niches = [];
|
||||
controller.removedNiches = [1];
|
||||
|
||||
$httpBackend.when('GET', `/item/api/ItemNiches?filter={"where":{},"include":{"relation":"warehouse"}}`).respond([]);
|
||||
$httpBackend.whenGET(`/item/api/ItemNiches?filter={"where":{},"include":{"relation":"warehouse"}}`).respond([]);
|
||||
$httpBackend.expectPOST(`/item/api/ItemNiches/crudItemNiches`).respond('ok!');
|
||||
controller.submit();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it("should perfom a query to update niches", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.niches = [{id: 1, warehouseFk: 1, code: '2222'}];
|
||||
controller.oldNiches = {1: {id: 1, warehouseFk: 1, code: '1111'}};
|
||||
|
||||
|
@ -126,6 +129,7 @@ describe('Item', () => {
|
|||
});
|
||||
|
||||
it("should perfom a query to create new niche", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.niches = [{warehouseFk: 1, code: 1111, itemFk: 1}];
|
||||
|
||||
$httpBackend.whenGET(`/item/api/ItemNiches?filter={"where":{},"include":{"relation":"warehouse"}}`).respond([]);
|
||||
|
@ -135,6 +139,7 @@ describe('Item', () => {
|
|||
});
|
||||
|
||||
it("should return a message 'No changes to save' when there are no changes to apply", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||
controller.oldNiches = [
|
||||
{warehouseFk: 1, code: 1, itemFk: 1, id: 1},
|
||||
|
|
|
@ -64,7 +64,7 @@ class ItemTags {
|
|||
});
|
||||
}
|
||||
|
||||
_getItemtags() {
|
||||
_getItemTags() {
|
||||
let filter = {
|
||||
where: {itemFk: this.params.id},
|
||||
order: "priority ASC",
|
||||
|
@ -118,7 +118,7 @@ class ItemTags {
|
|||
|
||||
if (canSubmit) {
|
||||
return this.$http.post(`/item/api/ItemTags/crudItemTags`, tagsObj).then(() => {
|
||||
this._getItemtags();
|
||||
this._getItemTags();
|
||||
this._unsetDirtyForm();
|
||||
});
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class ItemTags {
|
|||
}
|
||||
|
||||
$onInit() {
|
||||
this._getItemtags();
|
||||
this._getItemTags();
|
||||
}
|
||||
}
|
||||
ItemTags.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
import './item-tags.js';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component vnItemTags', () => {
|
||||
let $componentController;
|
||||
let $state;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('item');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$state = _$state_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
controller = $componentController('vnItemTags', {$state: $state});
|
||||
}));
|
||||
|
||||
describe('add / remove tags', () => {
|
||||
it('should add one empty tag into controller tags collection and call _setIconAdd()', () => {
|
||||
controller.itemTags = [];
|
||||
spyOn(controller, '_setIconAdd').and.callThrough();
|
||||
controller.addItemTag();
|
||||
|
||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||
expect(controller.itemTags.length).toEqual(1);
|
||||
expect(controller.itemTags[0].id).toBe(undefined);
|
||||
expect(controller.itemTags[0].showAddIcon).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should remove a tag that occupies the position in the index given and call _setIconAdd()', () => {
|
||||
let index = 2;
|
||||
controller.itemTags = [
|
||||
{id: 1, typeFk: 1, value: '1111', showAddIcon: false},
|
||||
{id: 2, typeFk: 2, value: '2222', showAddIcon: false},
|
||||
{id: 3, typeFk: 3, value: '3333', showAddIcon: true}
|
||||
];
|
||||
|
||||
spyOn(controller, '_setIconAdd').and.callThrough();
|
||||
|
||||
controller.removeItemTag(index);
|
||||
|
||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||
expect(controller.itemTags.length).toEqual(2);
|
||||
expect(controller.itemTags[0].showAddIcon).toBeFalsy();
|
||||
expect(controller.itemTags[1].showAddIcon).toBeTruthy();
|
||||
expect(controller.itemTags[index]).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_equalItemTags()', () => {
|
||||
it('should return true if two tags are equals independent of control attributes', () => {
|
||||
let tag1 = {id: 1, typeFk: 1, value: '1111', showAddIcon: true};
|
||||
let tag2 = {id: 1, typeFk: 1, value: '1111', showAddIcon: false};
|
||||
let equals = controller._equalItemTags(tag2, tag1);
|
||||
|
||||
expect(equals).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false if two tags aint equal independent of control attributes', () => {
|
||||
let tag1 = {id: 1, typeFk: 1, value: '1111', showAddIcon: true};
|
||||
let tag2 = {id: 1, typeFk: 1, value: '2222', showAddIcon: true};
|
||||
let equals = controller._equalItemTags(tag2, tag1);
|
||||
|
||||
expect(equals).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('get itemTags', () => {
|
||||
it('should perform a GET query to receive the item tags', () => {
|
||||
let res = [{id: 1, typeFk: 1, value: '1111'}];
|
||||
|
||||
$httpBackend.whenGET(`/item/api/ItemTags?filter={"where":{},"order":"priority ASC","include":{"relation":"tag"}}`).respond(res);
|
||||
$httpBackend.expectGET(`/item/api/ItemTags?filter={"where":{},"order":"priority ASC","include":{"relation":"tag"}}`);
|
||||
controller._getItemTags();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('submit()', () => {
|
||||
it("should return an error message 'The tag must be unique' when the tag value isnt unique", () => {
|
||||
controller.$scope.form = [];
|
||||
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||
controller.itemTags = [
|
||||
{typeFk: 1, value: 123454, itemFk: 1, id: 1},
|
||||
{typeFk: 1, value: 123454, itemFk: 1}
|
||||
];
|
||||
controller.oldItemTags = {1: {typeFk: 1, id: 1, value: 123454, itemFk: 1}};
|
||||
controller.submit();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The tag must be unique');
|
||||
});
|
||||
|
||||
it("should perfom a query to delete tags", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.oldItemTags = {1: {id: 1, typeFk: 1, value: '1111'}};
|
||||
controller.itemTags = [];
|
||||
controller.removedItemTags = [1];
|
||||
|
||||
$httpBackend.whenGET(`/item/api/ItemTags?filter={"where":{},"order":"priority ASC","include":{"relation":"tag"}}`).respond([]);
|
||||
$httpBackend.expectPOST(`/item/api/ItemTags/crudItemTags`).respond('ok!');
|
||||
controller.submit();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it("should perfom a query to update tags", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.itemTags = [{id: 1, typeFk: 1, value: '2222'}];
|
||||
controller.oldItemTags = {1: {id: 1, typeFk: 1, value: '1111'}};
|
||||
|
||||
$httpBackend.whenGET(`/item/api/ItemTags?filter={"where":{},"order":"priority ASC","include":{"relation":"tag"}}`).respond([]);
|
||||
$httpBackend.expectPOST(`/item/api/ItemTags/crudItemTags`).respond('ok!');
|
||||
controller.submit();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it("should perfom a query to create new tag", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.itemTags = [{typeFk: 1, value: 1111, itemFk: 1}];
|
||||
|
||||
$httpBackend.whenGET(`/item/api/ItemTags?filter={"where":{},"order":"priority ASC","include":{"relation":"tag"}}`).respond([]);
|
||||
$httpBackend.expectPOST(`/item/api/ItemTags/crudItemTags`).respond('ok!');
|
||||
controller.submit();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it("should return a message 'No changes to save' when there are no changes to apply", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||
controller.oldItemTags = [
|
||||
{typeFk: 1, value: 1, itemFk: 1, id: 1},
|
||||
{typeFk: 2, value: 2, itemFk: 1, id: 2}
|
||||
];
|
||||
controller.itemTags = [];
|
||||
controller.submit();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue