Updated unit tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-03-25 14:06:13 +01:00
parent c8b6c3f7f3
commit 90b437c7ad
2 changed files with 14 additions and 55 deletions

View File

@ -182,18 +182,6 @@ class Controller extends Section {
this.itemTypes = res.data);
}
/**
* Search by item id filter
* @param {object} event
*/
onSearchById(event) {
const value = this.$.itemId.value;
if (event.key === 'Enter' && value) {
this.itemId = value;
this.$.itemId.value = null;
}
}
/**
* Search by tag value
* @param {object} event
@ -238,20 +226,12 @@ class Controller extends Section {
if (this.typeId)
newFilter.typeFk = this.typeId;
/* if (this.itemId)
newFilter = {'i.id': this.itemId};
if (this.itemName)
newFilter = {'i.name': {like: `%${this.itemName}%`}}; */
newParams = {
orderFk: this.$params.id,
orderBy: this.getOrderBy(),
tags: this.tags,
};
console.log(newFilter);
return model.applyFilter({where: newFilter}, newParams);
}

View File

@ -115,30 +115,6 @@ describe('Order', () => {
});
});
describe('itemId() setter', () => {
it(`should set itemId property and then call updateStateParams() and applyFilters() methods`, () => {
jest.spyOn(controller, 'updateStateParams');
jest.spyOn(controller, 'applyFilters');
controller.itemId = 1;
expect(controller.updateStateParams).toHaveBeenCalledWith();
expect(controller.applyFilters).toHaveBeenCalledWith();
});
});
describe('itemName() setter', () => {
it(`should set itemName property and then call updateStateParams() and applyFilters() methods`, () => {
jest.spyOn(controller, 'updateStateParams');
jest.spyOn(controller, 'applyFilters');
controller.itemName = 'Bow';
expect(controller.updateStateParams).toHaveBeenCalledWith();
expect(controller.applyFilters).toHaveBeenCalledWith();
});
});
describe('tags() setter', () => {
it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => {
jest.spyOn(controller, 'updateStateParams');
@ -173,23 +149,27 @@ describe('Order', () => {
});
});
describe('onSearchById()', () => {
it(`should not filter by id if the event key code doesn't equals to 'Enter'`, () => {
describe('onSearch()', () => {
it(`should apply a filter by item id an then call the applyFilters method`, () => {
jest.spyOn(controller, 'applyFilters');
controller.$.itemId.value = 1;
controller.onSearchById({key: 'Tab'});
const itemId = 1;
controller.onSearch({search: itemId});
expect(controller.applyFilters).not.toHaveBeenCalledWith();
expect(controller.applyFilters).toHaveBeenCalledWith({
'i.id': itemId
});
});
it(`should filter by id if the event key code equals to 'Enter' an then call applyFilters()`, () => {
it(`should apply a filter by item name an then call the applyFilters method`, () => {
jest.spyOn(controller, 'applyFilters');
controller.$.itemId.value = 1;
controller.onSearchById({key: 'Enter'});
const itemName = 'Bow';
controller.onSearch({search: itemName});
expect(controller.applyFilters).toHaveBeenCalledWith();
expect(controller.applyFilters).toHaveBeenCalledWith({
'i.name': {like: `%${itemName}%`}
});
});
});
@ -239,7 +219,6 @@ describe('Order', () => {
controller._categoryId = 2;
controller._typeId = 4;
controller._itemId = 1;
controller._tags = [
{tagFk: 11, value: 'Precission', tagSelection: {name: 'Category'}}
];
@ -247,7 +226,7 @@ describe('Order', () => {
value: 'Precission',
tagFk: 11, tagSelection: {name: 'Category'}}
]);
let result = {categoryId: 2, typeId: 4, itemId: 1, tags: tags};
let result = {categoryId: 2, typeId: 4, tags: tags};
controller.updateStateParams();
expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result);