Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/public/components/common/table/SortModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,17 @@ export class SortModel extends Observable {
get visualChange$() {
return this._visualChange$;
}

/**
* Reset the sorting state to its defaults
*
* @return {void}
*/
reset() {
this._appliedDirection = this.defaultOrder;
this._appliedOn = null;
this._previewOn = null;
this.notify();
this._visualChange$.notify();
}
}
1 change: 1 addition & 0 deletions lib/public/models/OverviewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class OverviewPageModel extends Observable {
*/
reset() {
this._item$.setCurrent(RemoteData.notAsked());
this._sortModel.reset();
this._pagination.reset();
this._warnings.clear();
}
Expand Down
53 changes: 33 additions & 20 deletions test/public/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,39 @@ exports.waitForNavigation = waitForNavigation;
* @returns {Promise} Whether the element was clickable or not.
*/
module.exports.pressElement = async (page, selector, jsClick = false) => {
await page.waitForFunction(
(sel, isJsClick) => {
const element = document.querySelector(sel);
const maxAttempts = 3;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
await page.waitForFunction(
(sel) => Boolean(document.querySelector(sel)),
{},
selector
);

if (!element) {
return false;
try {
if (jsClick) {
const elementHandle = await page.waitForSelector(selector);
await elementHandle.evaluate((element) => {
element.click();
});
await elementHandle.dispose();
} else {
const elementHandle = await page.waitForSelector(selector, { visible: true });
await elementHandle.click();
await elementHandle.dispose();
}
// Moving the click to outside the function causes it to fail for unknown reasons
if (isJsClick) {
element.click();
return;
} catch (error) {
const errorMessage = String(error?.message ?? '');
const isRetryable = errorMessage.includes('detached from document')
|| errorMessage.includes('Node is detached from document')
|| errorMessage.includes('Node is either not clickable or not an Element')
|| errorMessage.includes('not visible')
|| errorMessage.includes('No node found for selector');

if (!isRetryable || attempt === maxAttempts) {
throw error;
}

return true;
},
{},
selector, jsClick
);

if (!jsClick) {
await page.click(selector);
}
}
};

Expand Down Expand Up @@ -861,15 +874,15 @@ module.exports.testTableSortingByColumn = async (page, columnId) => {

// Sort in ASCENDING manner
await this.pressElement(page, `th#${columnId}`, true);
this.expectColumnValues(page, columnId, [...notOrderData].sort());
await this.expectColumnValues(page, columnId, [...notOrderData].sort());

// Sort in DESCENDING manner
await this.pressElement(page, `th#${columnId}`, true);
this.expectColumnValues(page, columnId, [...notOrderData].sort().reverse());
await this.expectColumnValues(page, columnId, [...notOrderData].sort().reverse());

// Revoke sorting
await this.pressElement(page, `th#${columnId}`, true);
this.expectColumnValues(page, columnId, notOrderData);
await this.expectColumnValues(page, columnId, notOrderData);
};

/**
Expand Down
Loading