Skip to content

Commit

Permalink
CPS-356: Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
deb1990 committed Mar 2, 2021
1 parent 62e674e commit f260db3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
44 changes: 32 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions tests/backstop_data/engine_scripts/puppet/mouse-events-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const Utility = require('./utility.js');

module.exports = async (page, scenario, viewport, dontWait) => {
module.exports = async (options) => {
const actions = [
{ name: 'hoverSelector', execute: hoverSelectorAction },
{ name: 'hoverSelectors', execute: hoverSelectorAction },
Expand All @@ -11,20 +11,21 @@ module.exports = async (page, scenario, viewport, dontWait) => {
];

for (const action of actions) {
const scenarioHasAction = !!scenario[action.name];
const scenarioHasAction = !!options.scenario[action.name];

scenarioHasAction && await action.execute(page, scenario, viewport, dontWait);
scenarioHasAction && await action.execute(options);
}
};

/**
* Action handler for hover event
*
* @param {object} page pupettter engine object
* @param {object} scenario object of each scenario
* @param {object} viewport viewport configurations
* @param {object} options options
* @param {object} options.page pupettter engine object
* @param {object} options.scenario object of each scenario
* @param {object} options.viewport viewport configurations
*/
async function hoverSelectorAction (page, scenario, viewport) {
async function hoverSelectorAction ({ page, scenario, viewport }) {
const hoverSelectors = scenario.hoverSelectors || [scenario.hoverSelector];
const utility = new Utility(page, scenario, viewport);

Expand All @@ -40,12 +41,13 @@ async function hoverSelectorAction (page, scenario, viewport) {
/**
* Action handler for click event
*
* @param {object} page pupettter engine object
* @param {object} scenario object of each scenario
* @param {object} viewport viewport configurations
* @param {boolean} dontWait whether to apply additional wait
* @param {object} options options
* @param {object} options.page pupettter engine object
* @param {object} options.scenario object of each scenario
* @param {object} options.viewport viewport configurations
* @param {boolean} options.wait whether to apply additional wait
*/
async function clickSelectorAction (page, scenario, viewport, dontWait) {
async function clickSelectorAction ({ page, scenario, viewport, wait = 1000 }) {
const clickSelectors = scenario.clickSelectors || [scenario.clickSelector];
const utility = new Utility(page, scenario, viewport);

Expand All @@ -60,8 +62,6 @@ async function clickSelectorAction (page, scenario, viewport, dontWait) {
await utility.waitForUIModalLoad();
}

if (!dontWait) {
await page.waitFor(1000);
}
await page.waitFor(wait);
}
}
6 changes: 5 additions & 1 deletion tests/backstop_data/engine_scripts/puppet/on-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module.exports = async (page, scenario, vp) => {

await utility.waitForAngular();

await mouseEventsHelper(page, scenario, null, true);
await mouseEventsHelper({
page,
scenario,
wait: 0
});

if (scenario.isUIBPopover) {
// Clone the popover to a new element so that it doesn't get lost
Expand Down
20 changes: 2 additions & 18 deletions tests/backstop_data/engine_scripts/puppet/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ module.exports = class CrmPage {

// remove drupal/civicrm error logging, which creates difference
await this.removeElements('#console');

await this.closeSystemErrorNotification();
// remove system error notification
await this.removeElements('#crm-notification-container a[title="close"]');
}

/**
Expand Down Expand Up @@ -210,22 +210,6 @@ module.exports = class CrmPage {
}
}

/**
* Waits for the System Error Notification to close.
*/
async closeSystemErrorNotification () {
try {
const isSystemErrorNotificationVisible = await this.isElementVisible('#crm-notification-container a[title="close"]');

if (isSystemErrorNotificationVisible) {
await this.engine.click('#crm-notification-container a[title="close"]');
await this.engine.waitFor(1000);
}
} catch (e) {
console.log('System Error Notification not found');
}
}

/**
* @param {string} selector - the css selector for the element to wait
*/
Expand Down

0 comments on commit f260db3

Please sign in to comment.