Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect Wallet Interaction #7

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading