Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor URL parameter creation in price filter test
Browse files Browse the repository at this point in the history
This commit refactors the `getPriceFilterQuery` method in `price-filter.page.ts` to use the built-in URLSearchParams API for constructing URL parameters.

Previously, the method was manually creating a string representation of URL parameters. Now, it leverages the URLSearchParams API to improve readability and handle potential edge cases better.

The new approach appends 'min_price' and 'max_price' as URL parameters if they are not null. The `toString()` function is then called on the URLSearchParams object to return a string that can be used in a URL.
imanish003 committed Jul 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9ab033b commit 8c3efcb
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/e2e-pw/tests/price-filter/price-filter.page.ts
Original file line number Diff line number Diff line change
@@ -161,14 +161,17 @@ class PriceFilterPage {
minPrice: number | null,
maxPrice: number | null
) {
let result = '';
if ( minPrice ) {
result += `min_price=${ minPrice }`;
const params = new URLSearchParams();

if ( minPrice !== null ) {
params.append( 'min_price', minPrice.toString() );
}
if ( maxPrice ) {
result += `&max_price=${ maxPrice }`;

if ( maxPrice !== null ) {
params.append( 'max_price', maxPrice.toString() );
}
return result;

return params.toString();
}
}

0 comments on commit 8c3efcb

Please sign in to comment.