Skip to content

Commit

Permalink
Merge pull request PrestaShop#22209 from boubkerbribri/fix-sort
Browse files Browse the repository at this point in the history
Backport fix on UI sort tests
  • Loading branch information
SimonGrn authored Dec 3, 2020
2 parents e2e5983 + 659cba6 commit bf85c2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ describe('Sort and pagination cart rules', async () => {
},
{
args: {
testIdentifier: 'sortByDateAsc', sortBy: 'date', sortDirection: 'up',
testIdentifier: 'sortByDateAsc', sortBy: 'date', sortDirection: 'up', isDate: true,
},
},
{
args: {
testIdentifier: 'sortByDateDesc', sortBy: 'date', sortDirection: 'down',
testIdentifier: 'sortByDateDesc', sortBy: 'date', sortDirection: 'down', isDate: true,
},
},
{
Expand All @@ -200,7 +200,7 @@ describe('Sort and pagination cart rules', async () => {
sortedTable = await sortedTable.map(text => parseFloat(text));
}

const expectedResult = await cartRulesPage.sortArray(nonSortedTable, test.args.isFloat);
const expectedResult = await cartRulesPage.sortArray(nonSortedTable, test.args.isFloat, test.args.isDate);

if (test.args.sortDirection === 'up') {
await expect(sortedTable).to.deep.equal(expectedResult);
Expand Down
7 changes: 6 additions & 1 deletion tests/UI/pages/commonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,15 @@ module.exports = class CommonPage {
* @param isFloat
* @return {Promise<*>}
*/
async sortArray(arrayToSort, isFloat = false) {
async sortArray(arrayToSort, isFloat = false, isDate = false) {
if (isFloat) {
return arrayToSort.sort((a, b) => a - b);
}

if (isDate) {
return arrayToSort.sort((a, b) => new Date(a) - new Date(b));
}

return arrayToSort.sort((a, b) => a.localeCompare(b));
}

Expand Down

0 comments on commit bf85c2e

Please sign in to comment.