Differential D19604 Diff 58919 cashtab/src/components/SignVerifyMsg/__tests__/SignVerifyMsg.test.tsx
Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/SignVerifyMsg/__tests__/SignVerifyMsg.test.tsx
| Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | it('Notification is rendered upon successfully signing a message', async () => { | ||||
| ); | ); | ||||
| // Insert message to be signed | // Insert message to be signed | ||||
| await user.type( | await user.type( | ||||
| screen.getByPlaceholderText('Enter message to sign'), | screen.getByPlaceholderText('Enter message to sign'), | ||||
| 'test message', | 'test message', | ||||
| ); | ); | ||||
| // Click the Sign button (the Switch is also found by this identifier, btn is at index 0 here) | // Click the Sign button (SegmentedControl has "✍️ Sign" segment; use exact match for submit button) | ||||
| await user.click(screen.getAllByRole('button', { name: /Sign/ })[0]); | await user.click(screen.getByRole('button', { name: /^Sign$/ })); | ||||
| expect(await screen.findByText('Message Signed')).toBeInTheDocument(); | expect(await screen.findByText('Message Signed')).toBeInTheDocument(); | ||||
| expect( | expect( | ||||
| screen.getByText( | screen.getByText( | ||||
| 'H15QdmXfPFzMX+nDsoIGL51Nq3jkX/3RGmhwe87fIs9fLpvdHEflw+K9935GTU30Ids8J8Cdn1fV4uRJfUwYM8w=', | 'H15QdmXfPFzMX+nDsoIGL51Nq3jkX/3RGmhwe87fIs9fLpvdHEflw+K9935GTU30Ids8J8Cdn1fV4uRJfUwYM8w=', | ||||
| ), | ), | ||||
| ).toBeInTheDocument(); | ).toBeInTheDocument(); | ||||
| Show All 13 Lines | it('Notification is rendered upon successfully verifying a message', async () => { | ||||
| // Wait for the app to load | // Wait for the app to load | ||||
| await waitFor(() => | await waitFor(() => | ||||
| expect( | expect( | ||||
| screen.queryByTitle('Cashtab Loading'), | screen.queryByTitle('Cashtab Loading'), | ||||
| ).not.toBeInTheDocument(), | ).not.toBeInTheDocument(), | ||||
| ); | ); | ||||
| // Click the switch to show verify forms | // Click the Verify segment to show verify forms (SegmentedControl replaced Switch) | ||||
| await user.click(screen.getByTitle('Toggle Sign Verify')); | await user.click(screen.getByRole('button', { name: '✅ Verify' })); | ||||
| // Insert message to be signed | // Insert message to be signed | ||||
| await user.type( | await user.type( | ||||
| await screen.findByPlaceholderText('Enter message to verify'), | await screen.findByPlaceholderText('Enter message to verify'), | ||||
| 'test message', | 'test message', | ||||
| ); | ); | ||||
| // Input the address | // Input the address | ||||
| await user.type( | await user.type( | ||||
| screen.getByPlaceholderText('Enter address of signature to verify'), | screen.getByPlaceholderText('Enter address of signature to verify'), | ||||
| 'ecash:qq3spmxfh9ct0v3vkxncwk4sr2ld9vkhgvlu32e43c', | 'ecash:qq3spmxfh9ct0v3vkxncwk4sr2ld9vkhgvlu32e43c', | ||||
| ); | ); | ||||
| // Insert signature in Signature textarea of Verify collapse | // Insert signature in Signature textarea of Verify collapse | ||||
| await user.type( | await user.type( | ||||
| screen.getByPlaceholderText('Enter signature to verify'), | screen.getByPlaceholderText('Enter signature to verify'), | ||||
| 'H6Rde63iJ93n/I7gUac/xheY3mL1eAt2uIR54fgre6O3Om8ogWe+DASNQGDDBkNY43JIGwAIPq9lmMJjeykYFNQ=', | 'H6Rde63iJ93n/I7gUac/xheY3mL1eAt2uIR54fgre6O3Om8ogWe+DASNQGDDBkNY43JIGwAIPq9lmMJjeykYFNQ=', | ||||
| ); | ); | ||||
| // Click the Verify button | // Click the Verify submit button (SegmentedControl segment is [0], submit button is [1]) | ||||
| // react testing library also finds the switch with this, button is at index 0 | await user.click(screen.getAllByRole('button', { name: /Verify/ })[1]); | ||||
| await user.click(screen.getAllByRole('button', { name: /Verify/ })[0]); | |||||
| expect( | expect( | ||||
| screen.getByText( | screen.getByText( | ||||
| 'Signature verified. Message "test message" was signed by ecash:qq3spmxfh9ct0v3vkxncwk4sr2ld9vkhgvlu32e43c', | 'Signature verified. Message "test message" was signed by ecash:qq3spmxfh9ct0v3vkxncwk4sr2ld9vkhgvlu32e43c', | ||||
| ), | ), | ||||
| ).toBeInTheDocument(); | ).toBeInTheDocument(); | ||||
| }); | }); | ||||
| it('Notification is rendered upon signature verification error', async () => { | it('Notification is rendered upon signature verification error', async () => { | ||||
| Show All 11 Lines | it('Notification is rendered upon signature verification error', async () => { | ||||
| // Wait for the app to load | // Wait for the app to load | ||||
| await waitFor(() => | await waitFor(() => | ||||
| expect( | expect( | ||||
| screen.queryByTitle('Cashtab Loading'), | screen.queryByTitle('Cashtab Loading'), | ||||
| ).not.toBeInTheDocument(), | ).not.toBeInTheDocument(), | ||||
| ); | ); | ||||
| // Click the switch to show verify forms | // Click the Verify segment to show verify forms (SegmentedControl replaced Switch) | ||||
| await user.click(screen.getByTitle('Toggle Sign Verify')); | await user.click(screen.getByRole('button', { name: '✅ Verify' })); | ||||
| // Insert message to be signed | // Insert message to be signed | ||||
| await user.type( | await user.type( | ||||
| screen.getByPlaceholderText('Enter message to verify'), | screen.getByPlaceholderText('Enter message to verify'), | ||||
| 'NOT THE RIGHT MESSAGE', | 'NOT THE RIGHT MESSAGE', | ||||
| ); | ); | ||||
| // Input the address | // Input the address | ||||
| await user.type( | await user.type( | ||||
| screen.getByPlaceholderText('Enter address of signature to verify'), | screen.getByPlaceholderText('Enter address of signature to verify'), | ||||
| 'ecash:qq3spmxfh9ct0v3vkxncwk4sr2ld9vkhgvlu32e43c', | 'ecash:qq3spmxfh9ct0v3vkxncwk4sr2ld9vkhgvlu32e43c', | ||||
| ); | ); | ||||
| // Insert signature in Signature textarea of Verify collapse | // Insert signature in Signature textarea of Verify collapse | ||||
| await user.type( | await user.type( | ||||
| screen.getByPlaceholderText('Enter signature to verify'), | screen.getByPlaceholderText('Enter signature to verify'), | ||||
| 'H6Rde63iJ93n/I7gUac/xheY3mL1eAt2uIR54fgre6O3Om8ogWe+DASNQGDDBkNY43JIGwAIPq9lmMJjeykYFNQ=', | 'H6Rde63iJ93n/I7gUac/xheY3mL1eAt2uIR54fgre6O3Om8ogWe+DASNQGDDBkNY43JIGwAIPq9lmMJjeykYFNQ=', | ||||
| ); | ); | ||||
| // Click the Verify button | // Click the Verify submit button (SegmentedControl segment is [0], submit button is [1]) | ||||
| // react testing library also finds the switch with this, button is at index 0 | await user.click(screen.getAllByRole('button', { name: /Verify/ })[1]); | ||||
| await user.click(screen.getAllByRole('button', { name: /Verify/ })[0]); | |||||
| expect( | expect( | ||||
| screen.getByText('Signature does not match address and message'), | screen.getByText('Signature does not match address and message'), | ||||
| ).toBeInTheDocument(); | ).toBeInTheDocument(); | ||||
| }); | }); | ||||
| it('Does not show length error for signatureToVerify field when exceeding CASHTAB_MESSAGE_MAX_LENGTH', async () => { | it('Does not show length error for signatureToVerify field when exceeding CASHTAB_MESSAGE_MAX_LENGTH', async () => { | ||||
| // Mock the app with context at the SignVerifyMsg screen | // Mock the app with context at the SignVerifyMsg screen | ||||
| const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
| Show All 9 Lines | it('Does not show length error for signatureToVerify field when exceeding CASHTAB_MESSAGE_MAX_LENGTH', async () => { | ||||
| // Wait for the app to load | // Wait for the app to load | ||||
| await waitFor(() => | await waitFor(() => | ||||
| expect( | expect( | ||||
| screen.queryByTitle('Cashtab Loading'), | screen.queryByTitle('Cashtab Loading'), | ||||
| ).not.toBeInTheDocument(), | ).not.toBeInTheDocument(), | ||||
| ); | ); | ||||
| // Click the switch to show verify forms | // Click the Verify segment to show verify forms (SegmentedControl replaced Switch) | ||||
| await user.click(screen.getByTitle('Toggle Sign Verify')); | await user.click(screen.getByRole('button', { name: '✅ Verify' })); | ||||
| // Insert a valid message | // Insert a valid message | ||||
| await user.type( | await user.type( | ||||
| await screen.findByPlaceholderText('Enter message to verify'), | await screen.findByPlaceholderText('Enter message to verify'), | ||||
| 'test message', | 'test message', | ||||
| ); | ); | ||||
| // Input a valid address | // Input a valid address | ||||
| Show All 24 Lines | |||||