Skip to content

Commit

Permalink
fix(CP): ES-156 Added unit test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-krishsenthilraj committed Apr 10, 2019
1 parent affa3ca commit 315e380
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
30 changes: 29 additions & 1 deletion assets/js/test-unit/theme/common/faceted-search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ describe('FacetedSearch', () => {
'<input name="min_price" value="0">' +
'<input name="max_price" value="100">' +
'</form>' +
'<form id="facet-range-form-with-other-facets">' +
'<input name="brand" value="item1">' +
'<input name="brand" value="item2">' +
'<input name="min_price" value="0">' +
'<input name="max_price" value="50">' +
'</form>' +
'</div>' +
'</div>';

Expand Down Expand Up @@ -216,13 +222,35 @@ describe('FacetedSearch', () => {
expect(urlUtils.goToUrl).not.toHaveBeenCalled();
});

it('should prevent default event', function() {
it('should prevent default event', () => {
hooks.emit(eventName, event);

expect(event.preventDefault).toHaveBeenCalled();
});
});

describe('when price range form is submitted with other facets selected', () => {
let event;
let eventName;

beforeEach(() => {
eventName = 'facetedSearch-range-submitted';
event = {
currentTarget: '#facet-range-form-with-other-facets',
preventDefault: jasmine.createSpy('preventDefault'),
};

spyOn(urlUtils, 'goToUrl');
spyOn(facetedSearch.priceRangeValidator, 'areAll').and.returnValue(true);
});

it('send `min_price` and `max_price` query params if form is valid', () => {
hooks.emit(eventName, event);

expect(urlUtils.goToUrl).toHaveBeenCalledWith('/context.html?brand=item1&brand=item2&min_price=0&max_price=50');
});
});

describe('when sort filter is submitted', () => {
let event;
let eventName;
Expand Down
20 changes: 20 additions & 0 deletions assets/js/test-unit/theme/common/url-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,25 @@ describe('Url Utilities', () => {

expect(queryString).toEqual(expectedQueryString);
});

it('should parse the input query params from the input array and return the query string object', () => {
const queryInput = [
'brand[]=38',
'brand[]=39',
'brand[]=40',
'search_query=',
'min_price=15',
'max_price=40',
];
const expectedResult = {
'brand[]': ['38', '39', '40'],
max_price: '40',
min_price: '15',
search_query: '',
};
const queryStringObj = urlUtil.parseQueryParams(queryInput);

expect(queryStringObj).toEqual(expectedResult);
});
});
});

0 comments on commit 315e380

Please sign in to comment.