Skip to content

Commit

Permalink
feature: adding intereaction for disconnecting with wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Mar 1, 2024
1 parent 26438e7 commit 6e8fd13
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
9 changes: 8 additions & 1 deletion commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ const keplr = {
extensionVersion,
};
},

async disconnectWalletFromDapp() {
await playwright.waitAndClickByText(
'Disconnect All',
playwright.keplrPermissionWindow(),
exact = false,
);
return true;
},
async importWallet(secretWordsOrPrivateKey, password, newAccount) {
await playwright.waitAndClickByText(
newAccount
Expand Down
16 changes: 16 additions & 0 deletions commands/playwright-keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let mainWindow;
let keplrWindow;
let keplrNotificationWindow;
let keplrRegistrationWindow;
let keplrPermissionWindow;
let activeTabName;
let extensionsData = {};
let retries = 0;
Expand All @@ -21,6 +22,7 @@ module.exports = {
activeTabName = undefined;
keplrNotificationWindow = undefined;
keplrRegistrationWindow = undefined;
keplrPermissionWindow = undefined;
retries = 0;
extensionsData = {};
},
Expand Down Expand Up @@ -79,6 +81,20 @@ module.exports = {
return keplrNotificationWindow;
},

keplrPermissionWindow() {
return keplrPermissionWindow;
},

async switchToKeplrPermissionWindow() {
const keplrExtensionData = (await module.exports.getExtensionsData()).keplr;
const browserContext = await browser.contexts()[0];
keplrPermissionWindow = await browserContext.newPage();
await keplrPermissionWindow.goto(
`chrome-extension://${keplrExtensionData.id}/popup.html#/setting/security/permission`,
);
return true;
},

async waitAndClickByText(text, page = keplrWindow, exact = false) {
await module.exports.waitForByText(text, page);
const element = `:is(:text-is("${text}")${exact ? '' : `, :text("${text}")`})`;
Expand Down
2 changes: 2 additions & 0 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ module.exports = (on, config) => {
isCypressWindowActive: playwright.isCypressWindowActive,
switchToExtensionWindow: playwright.switchToKeplrWindow,
switchToExtensionRegistrationWindow: playwright.switchToKeplrRegistrationWindow,
switchToExtensionPermissionWindow: playwright.switchToKeplrPermissionWindow,

// keplr commands
importWallet: keplr.importWallet,
acceptAccess: keplr.acceptAccess,
confirmTransaction: keplr.confirmTransaction,
disconnectWalletFromDapp: keplr.disconnectWalletFromDapp,
setupWallet: async ({
secretWordsOrPrivateKey,
password,
Expand Down
8 changes: 8 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,12 @@ Cypress.Commands.add('switchToExtensionWindow', () => {

Cypress.Commands.add('switchToExtensionRegistrationWindow', () => {
return cy.task('switchToExtensionRegistrationWindow');
});

Cypress.Commands.add('switchToExtensionPermissionWindow', () => {
return cy.task('switchToExtensionPermissionWindow');
});

Cypress.Commands.add('disconnectWalletFromDapp', () => {
return cy.task('disconnectWalletFromDapp');
});
9 changes: 9 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ describe('Keplr', () => {

cy.visit('/');
cy.contains('Connect Wallet').click();
cy.contains('Make an Offer').click();
cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
});
});
});

it(`should disconnect the wallet from all the connected DAPPs`, () => {
cy.switchToExtensionPermissionWindow().then(() => {
cy.disconnectWalletFromDapp().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
});
});

it(`should complete Keplr setup by importing the wallet using private key`, () => {
cy.switchToExtensionRegistrationWindow().then(() => {
cy.setupWallet(
Expand Down

0 comments on commit 6e8fd13

Please sign in to comment.