Skip to content

Commit e7ba26d

Browse files
Merge pull request #396 from abhishek-lambda/AT-281
refactor x3
2 parents de73574 + 21be4b4 commit e7ba26d

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

accessibility/scanner/index.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,37 @@ const commandsToOverride = [
1313
const commandsToWrap = ['visit', 'click', 'type', 'request', 'dblclick', 'rightclick', 'clear', 'check', 'uncheck', 'select', 'trigger', 'selectFile', 'scrollIntoView', 'scroll', 'scrollTo', 'blur', 'focus', 'go', 'reload', 'submit', 'viewport', 'origin'];
1414

1515
const performNewLambdaScan = (originalFn, Subject, stateType, ...args) => {
16-
let customChainingCypressCommands = cy.wrap(null).processAccessibilityReport();
17-
const updateSub = (args, stateType, newSubject) => {
18-
return stateType !== 'parent' ? [newSubject, ...args.slice(1)] : args;
19-
}
20-
const runCustomizedLambdaChainingCommand = () => {
16+
let cycustomChaining = cy.wrap(null).processAccessibilityReport();
17+
const updateSubj = (args, stateType, newSubject) =>
18+
stateType === 'parent' ? args : [newSubject, ...args.slice(1)];
19+
20+
const runCustomizedChainingCommand = () => {
2121
if (!Subject) {
22-
let origSubject1, origSubject2, cyCommandSubject = null;
23-
if ((origSubject2 = (origSubject1 = cy).subject) !== null && origSubject2 !== void 0) {
24-
cyCommandSubject = origSubject2.call(origSubject1);
22+
let cypressCommandSubject = null;
23+
const subjectFn = cy && cy.subject;
24+
if (subjectFn !== null && subjectFn !== void 0) {
25+
cypressCommandSubject = subjectFn.call(cy);
2526
}
26-
customChainingCypressCommands.then(() => cyCommandSubject).then(() => { originalFn(...args); });
27+
cycustomChaining
28+
.then(() => cypressCommandSubject)
29+
.then(() => {
30+
originalFn(...args);
31+
});
2732
} else {
28-
let origChain1, origChain2, timeoutObj, cyCommandChain = null, setDelay = null;
29-
if ((timeoutObj = args.find(arg => arg !== null && arg !== void 0 ? arg.timeout : null)) !== null && timeoutObj !== void 0) {
30-
setDelay = timeoutObj.timeout;
33+
let cypressCommandChain = null, setTimeout = null;
34+
// Extract timeout value if present
35+
const timeoutArg = args.find(arg => arg !== null && arg !== void 0 ? arg.timeout : null);
36+
if (timeoutArg !== null && timeoutArg !== void 0) {
37+
setTimeout = timeoutArg.timeout;
3138
}
32-
if ((origChain1 = (origChain2 = cy).subjectChain) !== null && origChain1 !== void 0) {
33-
cyCommandChain = origChain1.call(origChain2);
39+
const subjectChainFn = cy && cy.subjectChain;
40+
if (subjectChainFn !== null && subjectChainFn !== void 0) {
41+
cypressCommandChain = subjectChainFn.call(cy);
3442
}
35-
customChainingCypressCommands.performScanSubjectQuery(cyCommandChain, setDelay)
36-
.then({ timeout: 30000 }, (newSubject) => originalFn(...updateSub(args, stateType, newSubject)));
43+
cycustomChaining.performScanSubjectQuery(cypressCommandChain, setTimeout).then({timeout: 30000}, (newSubject) => originalFn(...updateSubj(args, stateType, newSubject)));
3744
}
3845
}
39-
runCustomizedLambdaChainingCommand();
46+
runCustomizedChainingCommand();
4047
}
4148

4249
Cypress.Commands.add('processAccessibilityReport', () => {

0 commit comments

Comments
 (0)