Autocomplete client side unit test for findItems
This commit is contained in:
parent
720cf89204
commit
86fdb010ae
|
@ -204,6 +204,7 @@ class Autocomplete extends Component {
|
||||||
this.getItems();
|
this.getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getItems() {
|
getItems() {
|
||||||
let filter = {};
|
let filter = {};
|
||||||
|
|
||||||
|
@ -233,6 +234,7 @@ class Autocomplete extends Component {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
this.findMore = this.url && this.maxRow;
|
this.findMore = this.url && this.maxRow;
|
||||||
this.mouseFocus = false;
|
this.mouseFocus = false;
|
||||||
|
|
|
@ -153,4 +153,48 @@ describe('Component vnAutocomplete', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('findItem()', () => {
|
||||||
|
it(`should return items array if the controller does not provide a url and nither it has items`, () => {
|
||||||
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
||||||
|
controller.items = ['Batman', 'Bruce Wayne'];
|
||||||
|
controller.findItems('some search value');
|
||||||
|
|
||||||
|
expect(controller.items.length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should perform a query with the search value if the finding flag is false`, () => {
|
||||||
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
||||||
|
controller.items = ['Batman', 'Bruce Wayne'];
|
||||||
|
controller.findItems('Gotham');
|
||||||
|
|
||||||
|
expect(controller.items.length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should perform a query with the search value if the finding flag is false`, () => {
|
||||||
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
|
||||||
|
let search = 'The Joker';
|
||||||
|
let json = JSON.stringify({where: {name: {regexp: search}}});
|
||||||
|
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
|
||||||
|
$httpBackend.expectGET(`test.com?filter=${json}`);
|
||||||
|
controller.findItems(search);
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.items[0]).toEqual({id: 3, name: 'The Joker'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should perform a query with the search value if the finding flag is false`, () => {
|
||||||
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
|
||||||
|
let search = 'The Joker';
|
||||||
|
let json = JSON.stringify({where: {name: {regexp: search}}});
|
||||||
|
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
|
||||||
|
$httpBackend.expectGET(`test.com?filter=${json}`);
|
||||||
|
controller.findItems(search);
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.items[0]).toEqual({id: 3, name: 'The Joker'});
|
||||||
|
});
|
||||||
|
|
||||||
|
// siguiente test el de Multiple!
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue