unit test for autocomplete - tested filterSearch functionality
This commit is contained in:
parent
83965b20ee
commit
2bb87dc195
|
@ -120,8 +120,8 @@ describe('Component vnAutocomplete', () => {
|
||||||
|
|
||||||
it(`should perform a query if the item id isn't present in the controller.items property`, () => {
|
it(`should perform a query if the item id isn't present in the controller.items property`, () => {
|
||||||
controller.url = 'test.com';
|
controller.url = 'test.com';
|
||||||
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond();
|
$httpBackend.whenGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`).respond();
|
||||||
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
|
$httpBackend.expectGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`);
|
||||||
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
|
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
|
||||||
controller.field = 3;
|
controller.field = 3;
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
@ -136,8 +136,8 @@ describe('Component vnAutocomplete', () => {
|
||||||
|
|
||||||
it(`should set field performing a query as the item id isn't present in the controller.items property`, () => {
|
it(`should set field performing a query as the item id isn't present in the controller.items property`, () => {
|
||||||
controller.url = 'test.com';
|
controller.url = 'test.com';
|
||||||
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond();
|
$httpBackend.whenGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`).respond();
|
||||||
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
|
$httpBackend.expectGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`);
|
||||||
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
|
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
|
||||||
controller.field = 3;
|
controller.field = 3;
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
@ -150,9 +150,23 @@ describe('Component vnAutocomplete', () => {
|
||||||
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
||||||
controller.url = 'test.com';
|
controller.url = 'test.com';
|
||||||
let search = 'The Joker';
|
let search = 'The Joker';
|
||||||
let json = JSON.stringify({where: {name: {regexp: search}}});
|
let json = JSON.stringify({where: {name: {regexp: search}}, order: controller.order});
|
||||||
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
|
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
|
||||||
$httpBackend.expectGET(`test.com?filter=${json}`);
|
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
|
||||||
|
controller.findItems(search);
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.items[0]).toEqual({id: 3, name: 'The Joker'});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should perform a search and store the result in controller items with filterSearch`, () => {
|
||||||
|
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
|
||||||
|
controller.url = 'test.com';
|
||||||
|
let search = 'The Joker';
|
||||||
|
controller.filterSearch = "{where: {surname: {regexp: 'search'}}}";
|
||||||
|
let json = JSON.stringify({where: {surname: {regexp: search}}, order: controller.order});
|
||||||
|
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
|
||||||
|
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
|
||||||
controller.findItems(search);
|
controller.findItems(search);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
@ -163,9 +177,9 @@ describe('Component vnAutocomplete', () => {
|
||||||
controller.url = 'test.com';
|
controller.url = 'test.com';
|
||||||
let search = 'Joker';
|
let search = 'Joker';
|
||||||
controller.multiple = true;
|
controller.multiple = true;
|
||||||
let json = JSON.stringify({where: {name: {regexp: search}}});
|
let json = JSON.stringify({where: {name: {regexp: search}}, order: controller.order});
|
||||||
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}, {id: 4, name: 'Joker'}]);
|
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}, {id: 4, name: 'Joker'}]);
|
||||||
$httpBackend.expectGET(`test.com?filter=${json}`);
|
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
|
||||||
controller.findItems(search);
|
controller.findItems(search);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
@ -184,8 +198,8 @@ describe('Component vnAutocomplete', () => {
|
||||||
describe('getItems()', () => {
|
describe('getItems()', () => {
|
||||||
it(`should perfom a query to fill the items without filter`, () => {
|
it(`should perfom a query to fill the items without filter`, () => {
|
||||||
controller.url = 'test.com';
|
controller.url = 'test.com';
|
||||||
$httpBackend.whenGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
|
$httpBackend.whenGET(`${controller.url}?filter={"skip":0,"limit":10,"order":"name ASC"}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
|
||||||
$httpBackend.expectGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`);
|
$httpBackend.expectGET(`${controller.url}?filter={"skip":0,"limit":10,"order":"name ASC"}`);
|
||||||
controller.getItems();
|
controller.getItems();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue