Skip to content

Commit

Permalink
Disconnect Wallet Interaction (#7)
Browse files Browse the repository at this point in the history
* chore: removing call to acceptAccess function

* feature: adding intereaction for disconnecting with wallet

* remve the default arg
  • Loading branch information
rabi-siddique authored Mar 1, 2024
1 parent 7fd9158 commit afdc0a4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
8 changes: 7 additions & 1 deletion commands/keplr.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ const keplr = {
extensionVersion,
};
},

async disconnectWalletFromDapp() {
await playwright.waitAndClickByText(
'Disconnect All',
playwright.keplrPermissionWindow()
);
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');
});
16 changes: 10 additions & 6 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ describe('Keplr', () => {

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

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 afdc0a4

Please sign in to comment.