|
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +/*eslint max-nested-callbacks: 0*/ |
| 7 | +define([ |
| 8 | + 'Magento_Ui/js/grid/url-filter-applier' |
| 9 | +], function (UrlFilterApplier) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + describe('Magento_Ui/js/grid/url-filter-applier', function () { |
| 13 | + var urlFilterApplierObj, |
| 14 | + filterComponentMock = { |
| 15 | + setData: jasmine.createSpy(), |
| 16 | + apply: jasmine.createSpy() |
| 17 | + }; |
| 18 | + |
| 19 | + beforeEach(function () { |
| 20 | + urlFilterApplierObj = new UrlFilterApplier({}); |
| 21 | + urlFilterApplierObj.filterComponent = jasmine.createSpy().and.returnValue(filterComponentMock); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('"getFilterParam" method', function () { |
| 25 | + it('return object from url with a simple filters parameter', function () { |
| 26 | + var urlSearch = '?filters[name]=test'; |
| 27 | + |
| 28 | + expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({'name': 'test'}); |
| 29 | + }); |
| 30 | + it('return object from url with multiple filters parameter', function () { |
| 31 | + var urlSearch = '?filters[name]=test&filters[qty]=1'; |
| 32 | + |
| 33 | + expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({ |
| 34 | + 'name': 'test', |
| 35 | + 'qty': '1' |
| 36 | + }); |
| 37 | + }); |
| 38 | + it('return object from url with multiple filters parameter and another parameter', function () { |
| 39 | + var urlSearch = '?filters[name]=test&filters[qty]=1&anotherparam=1'; |
| 40 | + |
| 41 | + expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({ |
| 42 | + 'name': 'test', |
| 43 | + 'qty': '1' |
| 44 | + }); |
| 45 | + }); |
| 46 | + it('return object from url with another parameter', function () { |
| 47 | + var urlSearch = '?anotherparam=1'; |
| 48 | + |
| 49 | + expect(urlFilterApplierObj.getFilterParam(urlSearch)).toEqual({}); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('"apply" method', function () { |
| 54 | + it('applies url filter on filter component', function () { |
| 55 | + urlFilterApplierObj.searchString = '?filters[name]=test&filters[qty]=1'; |
| 56 | + urlFilterApplierObj.apply(); |
| 57 | + expect(urlFilterApplierObj.filterComponent().setData).toHaveBeenCalledWith({ |
| 58 | + 'name': 'test', |
| 59 | + 'qty': '1' |
| 60 | + }, false); |
| 61 | + expect(urlFilterApplierObj.filterComponent().apply).toHaveBeenCalled(); |
| 62 | + }); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments