Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Mar 28, 2024
2 parents 017cdac + a50014e commit fc7fc9d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
43 changes: 25 additions & 18 deletions commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const keplr = {
password,
newAccount,
walletName,
selectedChains,
) {
await module.exports.goToRegistration();
await playwright.waitAndClickByText(
Expand Down Expand Up @@ -158,7 +159,7 @@ const keplr = {
await playwright.keplrWindow(),
);

await module.exports.handleSelectChain();
await module.exports.handleSelectChain(selectedChains);

await playwright.waitForByText(
onboardingElements.phraseAccountCreated,
Expand All @@ -167,20 +168,22 @@ const keplr = {

return true;
},
async handleSelectChain() {
const chainNameExists = await playwright.waitForAndCheckElementExistence(
onboardingElements.chainNameSelector,
);

if (chainNameExists) {
async handleSelectChain(selectedChains) {
for (const chain of selectedChains) {
await playwright.waitAndClickByText(
onboardingElements.chainName,
playwright.keplrWindow(),
);
await playwright.waitAndClick(
onboardingElements.submitChainButton,
chain,
playwright.keplrWindow(),
true,
);
}

await playwright.waitAndClick(
onboardingElements.submitChainButton,
playwright.keplrWindow(),
);

// eslint-disable-next-line no-unused-vars
for (const _ of selectedChains) {
const importButtonExists =
await playwright.waitForAndCheckElementExistence(
onboardingElements.importButtonSelector,
Expand All @@ -191,12 +194,9 @@ const keplr = {
onboardingElements.importButtonSelector,
playwright.keplrWindow(),
);
} else {
break;
}
} else {
await playwright.waitAndClick(
onboardingElements.submitChainButton,
playwright.keplrWindow(),
);
}
},
async importWalletWithPhrase(secretWords) {
Expand Down Expand Up @@ -291,7 +291,13 @@ const keplr = {

async initialSetup(
playwrightInstance,
{ secretWordsOrPrivateKey, password, newAccount, walletName },
{
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
selectedChains,
},
) {
if (playwrightInstance) {
await playwright.init(playwrightInstance);
Expand All @@ -307,6 +313,7 @@ const keplr = {
password,
newAccount,
walletName,
selectedChains,
);
await playwright.switchToCypressWindow();
},
Expand Down
4 changes: 0 additions & 4 deletions pages/keplr/first-time-flow-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ const phraseAccountCreated = 'Account Created!';
const finishButton = 'button[type="button"]';
const textAreaSelector = 'textbox';
const submitPhraseButton = 'button[type="submit"]';
const chainName = 'Agoric local';
const chainNameSelector = 'text=Agoric local';
const importButtonSelector = 'button:has-text("Import")';

module.exports.onboardingElements = {
existingWalletButton,
createWalletButton,
importRecoveryPhraseButton,
useRecoveryPhraseButton,
chainNameSelector,
importButtonSelector,
phraseCount24,
phrasePrivateKey,
Expand All @@ -37,5 +34,4 @@ module.exports.onboardingElements = {
finishButton,
textAreaSelector,
submitPhraseButton,
chainName,
};
20 changes: 20 additions & 0 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { exec, execSync } = require('child_process');
const helpers = require('../helpers');
const playwright = require('../commands/playwright-keplr');
const keplr = require('../commands/keplr');
Expand Down Expand Up @@ -50,6 +51,23 @@ module.exports = (on, config) => {
console.warn('\u001B[33m', 'WARNING:', message, '\u001B[0m');
return true;
},
info(message) {
console.log('\u001B[36m', 'INFO:', message, '\u001B[0m');
return true;
},

async execute(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject({ error, stdout, stderr });
} else {
resolve({ stdout, stderr });
}
});
});
},

// playwright commands for Keplr
initPlaywright: playwright.init,
assignWindows: playwright.assignWindows,
Expand Down Expand Up @@ -77,12 +95,14 @@ module.exports = (on, config) => {
password,
newAccount,
walletName,
selectedChains,
}) => {
await keplr.initialSetup(null, {
secretWordsOrPrivateKey,
password,
newAccount,
walletName,
selectedChains,
});
return true;
},
Expand Down
6 changes: 6 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ Cypress.Commands.add('setupWallet', (args = {}) => {
password = 'Test1234',
newAccount = false,
walletName = 'My Wallet',
selectedChains = [],
} = args;
return cy.task('setupWallet', {
secretWordsOrPrivateKey:
Expand All @@ -426,6 +427,7 @@ Cypress.Commands.add('setupWallet', (args = {}) => {
password,
newAccount,
walletName,
selectedChains,
});
});

Expand Down Expand Up @@ -474,3 +476,7 @@ Cypress.Commands.add('addNewTokensFound', () => {
Cypress.Commands.add('getTokenAmount', tokenName => {
return cy.task('getTokenAmount', { tokenName });
});

Cypress.Commands.add('execute', command => {
return cy.task('execute', command);
});
1 change: 1 addition & 0 deletions support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ declare namespace Cypress {
password?: string;
newAccount?: boolean;
walletName?: string;
selectedChains?: Array<string>;
}): Chainable<Subject>;
}
}
12 changes: 12 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

describe('Keplr', () => {
context('Test commands', () => {
it('Executes a command and verifies stdout and stderr', () => {
const command = 'echo "Hello, stdout!" && echo "Error occurred" >&2';

cy.execute(command).then(({ stdout, stderr, error }) => {
expect(stdout.trim()).to.equal('Hello, stdout!');
expect(stderr.trim()).to.equal('Error occurred');
expect(error).to.be.undefined;
});
});

it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => {
cy.setupWallet().then(setupFinished => {
expect(setupFinished).to.be.true;
Expand Down Expand Up @@ -62,6 +72,7 @@ describe('Keplr', () => {
password: 'Test1234',
newAccount: true,
walletName: 'My Wallet 2',
selectedChains: ['Agoric localhost', 'Secret Network'],
}).then(setupFinished => {
expect(setupFinished).to.be.true;
});
Expand All @@ -71,6 +82,7 @@ describe('Keplr', () => {
privateKey:
'A9C09B6E4AF70DE1F1B621CB1AA66CFD0B4AA977E4C18497C49132DD9E579485',
walletName: 'My wallet 3',
selectedChains: ['Agoric localhost'],
}).then(setupFinished => {
expect(setupFinished).to.be.true;
});
Expand Down

0 comments on commit fc7fc9d

Please sign in to comment.