|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Sign PSBT E2E Tests', () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + // Navigate to test environment home page |
| 6 | + // The playwright config has webServer configured to start vite on localhost:5173 |
| 7 | + await page.goto('http://localhost:5173/#/test'); |
| 8 | + await page.waitForLoadState('networkidle'); |
| 9 | + }); |
| 10 | + |
| 11 | + test('Sign PSBT link should be accessible from home page', async ({ page }) => { |
| 12 | + // Navigate directly to the sign-psbt page instead of finding the link |
| 13 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 14 | + await page.waitForURL('**/sign-psbt'); |
| 15 | + expect(page.url()).toContain('sign-psbt'); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should render Sign PSBT form correctly', async ({ page }) => { |
| 19 | + // Navigate directly to sign-psbt page |
| 20 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 21 | + await page.waitForLoadState('networkidle'); |
| 22 | + |
| 23 | + // Check that the form heading is visible |
| 24 | + const heading = page.locator('h4:has-text("Sign Unsigned PSBT")'); |
| 25 | + await expect(heading).toBeVisible(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('Sign PSBT form should render all required fields', async ({ page }) => { |
| 29 | + // Navigate directly to sign-psbt page |
| 30 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 31 | + await page.waitForLoadState('networkidle'); |
| 32 | + |
| 33 | + // Check for all form fields using more specific selectors |
| 34 | + await expect(page.locator('label:has-text("Coin")')).toBeVisible(); |
| 35 | + await expect(page.locator('label:has-text("Unsigned PSBT")')).toBeVisible(); |
| 36 | + await expect(page.locator('label:has-text("User Key")')).toBeVisible(); |
| 37 | + await expect(page.locator('button:has-text("Sign PSBT")')).toBeVisible(); |
| 38 | + // Cancel is rendered as a Link component |
| 39 | + await expect(page.locator('a:has-text("Cancel")')).toBeVisible(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('Sign PSBT form should show optional recipient fields', async ({ page }) => { |
| 43 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 44 | + await page.waitForLoadState('networkidle'); |
| 45 | + |
| 46 | + // Check optional fields using more specific selectors |
| 47 | + await expect(page.locator('label:has-text("Recipient Address")')).toBeVisible(); |
| 48 | + await expect(page.locator('label:has-text("Fee Rate")')).toBeVisible(); |
| 49 | + }); |
| 50 | + |
| 51 | + test('Passphrase field should be hidden initially', async ({ page }) => { |
| 52 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 53 | + await page.waitForLoadState('networkidle'); |
| 54 | + |
| 55 | + // Passphrase should not be visible when no userKey is entered |
| 56 | + const passphraseLabel = page.locator('text=Wallet Passphrase'); |
| 57 | + await expect(passphraseLabel).not.toBeVisible(); |
| 58 | + }); |
| 59 | + |
| 60 | + test('Coin selector should have UTXO options', async ({ page }) => { |
| 61 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 62 | + await page.waitForLoadState('networkidle'); |
| 63 | + |
| 64 | + // Find the coin selector |
| 65 | + const coinSelect = page.locator('[name="coin"]'); |
| 66 | + await expect(coinSelect).toBeVisible(); |
| 67 | + |
| 68 | + // Check for expected coin options (option elements exist in DOM) |
| 69 | + const tbtcOption = coinSelect.locator('option:has-text("TBTC")'); |
| 70 | + const btcOption = coinSelect.locator('option:has-text("BTC")'); |
| 71 | + |
| 72 | + // Options exist in DOM but may be hidden, so check they're attached |
| 73 | + expect(await tbtcOption.count()).toBeGreaterThan(0); |
| 74 | + expect(await btcOption.count()).toBeGreaterThan(0); |
| 75 | + }); |
| 76 | + |
| 77 | + test('Form should accept PSBT and user key input', async ({ page }) => { |
| 78 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 79 | + await page.waitForLoadState('networkidle'); |
| 80 | + |
| 81 | + // Fill in the form |
| 82 | + const coinSelect = page.locator('[name="coin"]'); |
| 83 | + await coinSelect.selectOption('tbtc'); |
| 84 | + |
| 85 | + const psbtTextarea = page.locator('[name="psbt"]'); |
| 86 | + await psbtTextarea.fill('70736274ff010000'); |
| 87 | + |
| 88 | + const userKeyTextarea = page.locator('[name="userKey"]'); |
| 89 | + await userKeyTextarea.fill('tprvAA2oWoHxCkMDMedFAEgCAJEdSYq5vTTPZp9VuCFJnNxYQhGJxp7JGZoAZiXNkFsLXQtqeQFZefFxvTFSzz2kDCzKe3tKo8GJqQ4pA3mbMK'); |
| 90 | + |
| 91 | + // Verify values are set |
| 92 | + const psbtValue = await psbtTextarea.inputValue(); |
| 93 | + expect(psbtValue).toBe('70736274ff010000'); |
| 94 | + }); |
| 95 | + |
| 96 | + test('Passphrase field should show when encrypted key is entered', async ({ page }) => { |
| 97 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 98 | + await page.waitForLoadState('networkidle'); |
| 99 | + |
| 100 | + const userKeyTextarea = page.locator('[name="userKey"]'); |
| 101 | + |
| 102 | + // Enter an encrypted key (JSON format, not starting with xprv/tprv) |
| 103 | + const encryptedKey = '{"iv":"abc123"}'; |
| 104 | + await userKeyTextarea.fill(encryptedKey); |
| 105 | + |
| 106 | + // Passphrase field should now be visible |
| 107 | + const passphraseField = page.locator('[name="walletPassphrase"]'); |
| 108 | + await expect(passphraseField).toBeVisible(); |
| 109 | + }); |
| 110 | + |
| 111 | + test('Sign button should be enabled initially', async ({ page }) => { |
| 112 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 113 | + await page.waitForLoadState('networkidle'); |
| 114 | + |
| 115 | + // Get the sign button |
| 116 | + const signButton = page.locator('button:has-text("Sign PSBT")'); |
| 117 | + await expect(signButton).toBeVisible(); |
| 118 | + |
| 119 | + // Button should be enabled initially |
| 120 | + const isDisabled = await signButton.isDisabled(); |
| 121 | + expect(isDisabled).toBe(false); |
| 122 | + }); |
| 123 | + |
| 124 | + test('Cancel button should navigate back to home', async ({ page }) => { |
| 125 | + await page.goto('http://localhost:5173/#/test/sign-psbt'); |
| 126 | + await page.waitForLoadState('networkidle'); |
| 127 | + |
| 128 | + // Cancel is rendered as a Link component, not a button |
| 129 | + const cancelLink = page.locator('a:has-text("Cancel")'); |
| 130 | + await expect(cancelLink).toBeVisible(); |
| 131 | + |
| 132 | + // Click cancel and wait for navigation |
| 133 | + await cancelLink.click(); |
| 134 | + await page.waitForLoadState('networkidle'); |
| 135 | + |
| 136 | + // Verify we navigated away from sign-psbt |
| 137 | + expect(page.url()).not.toContain('sign-psbt'); |
| 138 | + }); |
| 139 | +}); |
0 commit comments