item tag unit tests
This commit is contained in:
parent
f354a420bc
commit
b23617fcfb
|
@ -20,19 +20,19 @@ describe('Item', () => {
|
|||
|
||||
describe('add / remove tags', () => {
|
||||
it('should add one empty tag into controller tags collection and call _setIconAdd()', () => {
|
||||
controller.itemTags = [];
|
||||
controller.instancedItemTags = [];
|
||||
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();
|
||||
expect(controller.instancedItemTags.length).toEqual(1);
|
||||
expect(controller.instancedItemTags[0].id).toBe(undefined);
|
||||
expect(controller.instancedItemTags[0].showAddIcon).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should remove a tag that occupies the position in the index given and call _setIconAdd()', () => {
|
||||
let index = 2;
|
||||
controller.itemTags = [
|
||||
controller.instancedItemTags = [
|
||||
{id: 1, typeFk: 1, value: '1111', showAddIcon: false},
|
||||
{id: 2, typeFk: 2, value: '2222', showAddIcon: false},
|
||||
{id: 3, typeFk: 3, value: '3333', showAddIcon: true}
|
||||
|
@ -43,10 +43,10 @@ describe('Item', () => {
|
|||
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);
|
||||
expect(controller.instancedItemTags.length).toEqual(2);
|
||||
expect(controller.instancedItemTags[0].showAddIcon).toBeFalsy();
|
||||
expect(controller.instancedItemTags[1].showAddIcon).toBeTruthy();
|
||||
expect(controller.instancedItemTags[index]).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -83,7 +83,7 @@ describe('Item', () => {
|
|||
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 = [
|
||||
controller.instancedItemTags = [
|
||||
{typeFk: 1, value: 123454, itemFk: 1, id: 1},
|
||||
{typeFk: 1, value: 123454, itemFk: 1}
|
||||
];
|
||||
|
@ -96,7 +96,7 @@ describe('Item', () => {
|
|||
it("should perfom a query to delete tags", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.oldItemTags = {1: {id: 1, typeFk: 1, value: '1111'}};
|
||||
controller.itemTags = [];
|
||||
controller.instancedItemTags = [];
|
||||
controller.removedItemTags = [1];
|
||||
|
||||
$httpBackend.whenGET(`/item/api/ItemTags?filter={"where":{},"order":"priority ASC","include":{"relation":"tag"}}`).respond([]);
|
||||
|
@ -107,7 +107,7 @@ describe('Item', () => {
|
|||
|
||||
it("should perfom a query to update tags", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.itemTags = [{id: 1, typeFk: 1, value: '2222'}];
|
||||
controller.instancedItemTags = [{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([]);
|
||||
|
@ -118,7 +118,7 @@ describe('Item', () => {
|
|||
|
||||
it("should perfom a query to create new tag", () => {
|
||||
controller.$scope.form = {$setPristine: () => {}};
|
||||
controller.itemTags = [{typeFk: 1, value: 1111, itemFk: 1}];
|
||||
controller.instancedItemTags = [{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!');
|
||||
|
@ -133,7 +133,7 @@ describe('Item', () => {
|
|||
{typeFk: 1, value: 1, itemFk: 1, id: 1},
|
||||
{typeFk: 2, value: 2, itemFk: 1, id: 2}
|
||||
];
|
||||
controller.itemTags = [];
|
||||
controller.instancedItemTags = [];
|
||||
controller.submit();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save');
|
||||
|
|
Loading…
Reference in New Issue