-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve open API and add tests, ref leather-io/issues#5800
- Loading branch information
1 parent
6b9566a
commit e16c9d6
Showing
4 changed files
with
117 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types'; | ||
import * as yup from 'yup'; | ||
|
||
const rpcOpenWalletParamsSchema = yup.object().shape({ | ||
url: yup.string(), | ||
}); | ||
|
||
type OpenWalletRequestParams = yup.InferType<typeof rpcOpenWalletParamsSchema>; | ||
|
||
export type OpenWalletRequest = RpcRequest<'openWallet', OpenWalletRequestParams>; | ||
|
||
type OpenWalletResponse = RpcResponse<Response>; | ||
|
||
export type OpenWallet = DefineRpcMethod<OpenWalletRequest, OpenWalletResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { BrowserContext, Page } from '@playwright/test'; | ||
import { TEST_PASSWORD } from '@tests/mocks/constants'; | ||
import { HomePageSelectors } from '@tests/selectors/home.selectors'; | ||
|
||
import { test } from '../../fixtures/fixtures'; | ||
|
||
const successResponse = { | ||
jsonrpc: '2.0', | ||
result: { | ||
message: 'Success', | ||
}, | ||
}; | ||
|
||
async function interceptRequestPopup(context: BrowserContext) { | ||
return context.waitForEvent('page'); | ||
} | ||
|
||
async function assertWalletHomeOpens(popup: Page) { | ||
await popup.getByTestId(HomePageSelectors.HomePageContainer).waitFor(); | ||
// await page.getByTestId(HomePageSelectors.HomePageContainer).waitFor(); | ||
const button = popup.getByTestId(HomePageSelectors.FundAccountBtn); | ||
await test.expect(button).toBeVisible(); | ||
// await button.click(); | ||
} | ||
async function initiateOpen(page: Page) { | ||
return page.evaluate(async () => (window as any).LeatherProvider?.request('open')); | ||
} | ||
|
||
test.describe('Rpc: Open', () => { | ||
test.beforeEach(async ({ extensionId, globalPage, onboardingPage }) => { | ||
await globalPage.setupAndUseApiCalls(extensionId); | ||
|
||
await onboardingPage.signInWithTestAccount(extensionId); | ||
}); | ||
|
||
test('the wallet opens successfully', async ({ page, context }) => { | ||
await page.goto('localhost:3000'); | ||
const openPromise = await initiateOpen(page); | ||
|
||
const popup = await interceptRequestPopup(context); | ||
await assertWalletHomeOpens(popup); | ||
|
||
const result = await openPromise; | ||
if (!result) throw new Error('Expected result'); | ||
const { id, ...payloadWithoutId } = result; | ||
|
||
await test.expect(payloadWithoutId).toEqual(successResponse); | ||
}); | ||
|
||
test('the promise rejects when user closes the popup window', async ({ page, context }) => { | ||
await page.goto('localhost:3000'); | ||
const openPromise = initiateOpen(page); | ||
const popup = await interceptRequestPopup(context); | ||
await popup.close(); | ||
await test.expect(openPromise).rejects.toThrow(); | ||
Check failure on line 55 in tests/specs/rpc-open/open.spec.ts GitHub Actions / Shard 5 of 10[chromium] › specs/rpc-open/open.spec.ts:50:3 › Rpc: Open › the promise rejects when user closes the popup window
Check failure on line 55 in tests/specs/rpc-open/open.spec.ts GitHub Actions / Shard 5 of 10[chromium] › specs/rpc-open/open.spec.ts:50:3 › Rpc: Open › the promise rejects when user closes the popup window
Check failure on line 55 in tests/specs/rpc-open/open.spec.ts GitHub Actions / Shard 5 of 10[chromium] › specs/rpc-open/open.spec.ts:50:3 › Rpc: Open › the promise rejects when user closes the popup window
|
||
}); | ||
|
||
test('it forces user to unlock wallet when wallet is locked', async ({ | ||
homePage, | ||
page, | ||
context, | ||
}) => { | ||
await homePage.lock(); | ||
await page.goto('localhost:3000'); | ||
const openPromise = initiateOpen(page); | ||
const popup = await interceptRequestPopup(context); | ||
await popup.getByRole('textbox').fill(TEST_PASSWORD); | ||
await popup.getByRole('button', { name: 'Continue' }).click(); | ||
await assertWalletHomeOpens(popup); | ||
await test.expect(openPromise).resolves.toMatchObject(successResponse); | ||
}); | ||
}); |