-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create cypress command namespacing util (#9150)
- Loading branch information
1 parent
6c62785
commit 78956d0
Showing
14 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
chore: | ||
- Create cypress command namespacing util ([#9150](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9150)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* Initializes a command namespace on the cy object | ||
* | ||
* Ex usage: | ||
* initCommandNamespace(cy, 'osd'); // initializes osd namespace (only needed once per ns) | ||
* cy.osd.add('myNewCommand', (myArg) => ...); // register command to namespace | ||
* cy.osd.myNewCommand('someArg'); // executes command | ||
* | ||
*/ | ||
export default function initCommandNamespace(cy, namespace) { | ||
/** | ||
* this proxy is responsible for intercepting access to properties | ||
* it's what allows us to dynamically define properties at runtime like cy.osd.myNewCommand | ||
*/ | ||
cy[namespace] = new Proxy( | ||
{ | ||
// register a new namespaced command with cypress (ex. osd:myNewCommand) | ||
add(commandName, callback) { | ||
Cypress.Commands.add(namespaceCommand(commandName), callback); | ||
}, | ||
}, | ||
{ | ||
get(target, property) { | ||
if (target[property]) { | ||
// return reserved property (add method) | ||
return target[property]; | ||
} | ||
|
||
// return the mapped namespace command (ex. myNewCommand returns the osd:myNewCommand command) | ||
return cy[namespaceCommand(property)]; | ||
}, | ||
} | ||
); | ||
|
||
function namespaceCommand(commandName) { | ||
return `${namespace}:${commandName}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters