From a97db1178de99fa388162e36a6572b972628ea55 Mon Sep 17 00:00:00 2001 From: maciek Date: Fri, 4 Aug 2023 16:11:44 +0200 Subject: [PATCH] feat: new connect wallet modal - clean up some int test, fix lint errors --- .../src/integration/wallet-vega.cy.ts | 110 ------------------ .../src/lib/commands/vega-wallet-connect.ts | 2 +- libs/cypress/src/lib/mock-rest.ts | 35 +++++- .../connect-dialog/connect-dialog.spec.tsx | 9 +- 4 files changed, 36 insertions(+), 120 deletions(-) diff --git a/apps/trading-e2e/src/integration/wallet-vega.cy.ts b/apps/trading-e2e/src/integration/wallet-vega.cy.ts index 18de0c40e..fb6851e1f 100644 --- a/apps/trading-e2e/src/integration/wallet-vega.cy.ts +++ b/apps/trading-e2e/src/integration/wallet-vega.cy.ts @@ -5,118 +5,8 @@ import { const connectVegaBtn = 'connect-vega-wallet'; const manageVegaBtn = 'manage-vega-wallet'; -const form = 'rest-connector-form'; const dialogContent = 'dialog-content'; -describe( - 'connect hosted wallet', - { tags: '@smoke', testIsolation: true }, - () => { - beforeEach(() => { - // Using portfolio page as it requires vega wallet connection - cy.visit('/#/portfolio'); - cy.mockTradingPage(); - cy.mockSubscription(); - cy.setOnBoardingViewed(); - cy.get('[data-testid="pathname-/portfolio"]').should('exist'); - }); - - it('can connect', () => { - // 0002-WCON-002 - // 0002-WCON-003 - // 0002-WCON-039 - // 0002-WCON-017 - // 0002-WCON-018 - // 0002-WCON-019 - - // Mock authentication - cy.intercept( - 'POST', - 'https://wallet.testnet.vega.xyz/api/v1/auth/token', - { - body: { - token: 'test-token', - }, - } - ); - // Mock getting keys from wallet - cy.intercept('GET', 'https://wallet.testnet.vega.xyz/api/v1/keys', { - body: { - keys: [ - { - algorithm: { - name: 'algo', - version: 1, - }, - index: 0, - meta: [], - pub: 'HOSTED_PUBKEY', - tainted: false, - }, - ], - }, - }); - cy.getByTestId(connectVegaBtn).click(); - cy.contains( - 'Choose wallet app to connect, or to change port or server URL enter a custom wallet location first' - ); - cy.contains('Connect Vega wallet'); - cy.contains('Hosted Fairground wallet'); - - cy.getByTestId('connectors-list') - .find('[data-testid="connector-rest"]') - .click(); - cy.getByTestId(form).find('#wallet').click().type('user'); - cy.getByTestId(form).find('#passphrase').click().type('pass'); - cy.getByTestId('rest-connector-form').find('button[type=submit]').click(); - cy.getByTestId(manageVegaBtn).should('exist'); - cy.getByTestId('manage-vega-wallet').click(); - cy.getByTestId('keypair-list').should('exist'); - }); - - it('doesnt connect with invalid credentials', () => { - // 0002-WCON-020 - - // Mock incorrect username/password - cy.intercept( - 'POST', - 'https://wallet.testnet.vega.xyz/api/v1/auth/token', - { - body: { - error: 'No wallet', - }, - statusCode: 403, // 403 forbidden invalid crednetials - } - ); - cy.getByTestId(connectVegaBtn).click(); - cy.getByTestId('connectors-list') - .find('[data-testid="connector-rest"]') - .click(); - cy.getByTestId(form).find('#wallet').click().type('invalid name'); - cy.getByTestId(form).find('#passphrase').click().type('invalid password'); - cy.getByTestId('rest-connector-form').find('button[type=submit]').click(); - cy.getByTestId('form-error').should('have.text', 'Invalid credentials'); - }); - - it('doesnt connect with empty fields', () => { - cy.getByTestId(connectVegaBtn).click(); - cy.getByTestId('connectors-list') - .find('[data-testid="connector-rest"]') - .click(); - - cy.getByTestId('rest-connector-form').find('button[type=submit]').click(); - cy.getByTestId(form) - .find('#wallet') - .next('[data-testid="input-error-text"]') - .should('have.text', 'Required'); - cy.getByTestId(form) - .find('#passphrase') - .next('[data-testid="input-error-text"]') - .should('have.text', 'Required'); - }); - } -); - describe('connect vega wallet', { tags: '@smoke', testIsolation: true }, () => { beforeEach(() => { // Using portfolio page as it requires vega wallet connection diff --git a/libs/cypress/src/lib/commands/vega-wallet-connect.ts b/libs/cypress/src/lib/commands/vega-wallet-connect.ts index 3335b7fae..dba138df2 100644 --- a/libs/cypress/src/lib/commands/vega-wallet-connect.ts +++ b/libs/cypress/src/lib/commands/vega-wallet-connect.ts @@ -29,7 +29,7 @@ export const mockConnectWallet = () => { export const mockConnectWalletWithUserError = () => { cy.mockWallet((req) => { - aliasWalletConnectWithUserError(req); + aliasWalletConnectWithUserError(req, Cypress.env('VEGA_WALLET_API_TOKEN')); }); }; diff --git a/libs/cypress/src/lib/mock-rest.ts b/libs/cypress/src/lib/mock-rest.ts index 5da0287c6..359a37a48 100644 --- a/libs/cypress/src/lib/mock-rest.ts +++ b/libs/cypress/src/lib/mock-rest.ts @@ -62,10 +62,27 @@ export const aliasWalletConnectQuery = ( }, }); } + if (hasMethod(req, 'client.get_chain_id')) { + req.reply({ + statusCode: 200, + headers: { + 'Access-Control-Expose-Headers': 'Authorization', + Authorization: `VWT ${token}`, + }, + body: { + jsonrpc: '2.0', + result: { + chainID: 'test-id', + }, + id: '1', + }, + }); + } }; export const aliasWalletConnectWithUserError = ( - req: CyHttpMessages.IncomingHttpRequest + req: CyHttpMessages.IncomingHttpRequest, + token: string ) => { if (hasMethod(req, 'client.connect_wallet')) { req.alias = 'client.connect_wallet'; @@ -82,4 +99,20 @@ export const aliasWalletConnectWithUserError = ( }, }); } + if (hasMethod(req, 'client.get_chain_id')) { + req.reply({ + statusCode: 200, + headers: { + 'Access-Control-Expose-Headers': 'Authorization', + Authorization: `VWT ${token}`, + }, + body: { + jsonrpc: '2.0', + result: { + chainID: 'test-id', + }, + id: '1', + }, + }); + } }; diff --git a/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx b/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx index 1038fa31d..381d570b0 100644 --- a/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx +++ b/libs/wallet/src/connect-dialog/connect-dialog.spec.tsx @@ -1,10 +1,4 @@ -import { - act, - fireEvent, - render, - screen, - waitFor, -} from '@testing-library/react'; +import { act, fireEvent, render, screen } from '@testing-library/react'; import type { MockedResponse } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing'; import { VegaWalletProvider } from '../provider'; @@ -30,7 +24,6 @@ import { delayedReject, delayedResolve, } from '../test-helpers'; -import { useIsDesktopWalletRunning } from '../use-is-desktop-wallet-running'; const mockUpdateDialogOpen = jest.fn(); const mockCloseVegaDialog = jest.fn();