Skip to content

Commit

Permalink
fix: bug with go back action in send flow, #4355
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo authored and kyranjamie committed Nov 1, 2023
1 parent cc5908b commit 92aa04c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/app/features/edit-nonce-drawer/edit-nonce-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export function EditNonceDrawer() {

useOnMount(() => setLoadedNextNonce(values.nonce));

const onGoBack = useCallback(
() => navigate('..' + search, { replace: true }),
[navigate, search]
);
const onGoBack = useCallback(() => {
if (search) {
return navigate('..' + search, { replace: true });
}
navigate(-1);
}, [navigate, search]);

const onBlur = useCallback(() => validateField('nonce'), [validateField]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function useRecipientSelectFields() {

const onClickLabelAction = useCallback(() => {
setSelectedRecipientField(RecipientFieldType.Address);
navigate(RouteUrls.SendCryptoAssetFormRecipientAccounts);
navigate(RouteUrls.SendCryptoAssetFormRecipientAccounts, { replace: true });
}, [navigate]);

// Formik does not provide a field reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function StacksSendFormConfirmation() {
<ModalHeader
hideActions
defaultClose
onGoBack={() => navigate('../', { relative: 'path' })}
onGoBack={() => navigate('../', { relative: 'path', replace: true })}
title="Review"
/>
);
Expand Down
5 changes: 5 additions & 0 deletions tests/page-object-models/send.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ export class SendPage {
async goBack() {
await this.page.getByTestId(SharedComponentsSelectors.ModalHeaderBackBtn).click();
}

async goBackSelectStx() {
await this.goBack();
await this.selectStxAndGoToSendForm();
}
}
16 changes: 10 additions & 6 deletions tests/specs/send/send-stx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ test.describe('send stx', () => {
sPage = sendPage;
});

test.afterEach(async () => {
await sPage.page.getByTestId('modal-header-back-button').click();
await sPage.selectStxAndGoToSendForm();
});

test('that send max button sets available balance minus fee', async () => {
await sPage.amountInput.fill('.0001');
await sPage.amountInput.clear();
await sPage.amountInput.blur();
await sPage.sendMaxButton.click();
await sPage.amountInput.blur();
test.expect(await sPage.amountInput.inputValue()).toBeTruthy();
await sPage.goBackSelectStx();
});

test('that empty memo on preview matches default empty value', async () => {
Expand All @@ -52,6 +48,7 @@ test.describe('send stx', () => {
.getByTestId(SharedComponentsSelectors.InfoCardRowValue)
.innerText();
test.expect(confirmationMemo).toEqual(emptyMemoPreviewValue);
await sPage.goBack();
});

test('that asset value, recipient, memo and fees on preview match input', async () => {
Expand Down Expand Up @@ -84,9 +81,13 @@ test.describe('send stx', () => {
.getByTestId(SharedComponentsSelectors.InfoCardRowValue)
.innerText();
test.expect(confirmationMemo2).toEqual(memo);
await sPage.goBack();
});

test.describe('send form validation', () => {
test.afterEach(async () => {
await sPage.goBackSelectStx();
});
test('that the amount must be a number', async () => {
await sPage.amountInput.fill('aaaaaa');
await sPage.amountInput.blur();
Expand Down Expand Up @@ -128,7 +129,6 @@ test.describe('send stx', () => {
await sPage.previewSendTxButton.click();
const errorMsg = await sPage.formInputErrorLabel.innerText();
test.expect(errorMsg).toContain(FormErrorMessages.SameAddress);
await sPage.goBack();
});

test('that valid addresses are accepted', async () => {
Expand All @@ -141,6 +141,10 @@ test.describe('send stx', () => {
});

test.describe('send form preview', () => {
test.afterEach(async () => {
await sPage.goBack();
await sPage.goBackSelectStx();
});
test('that it shows preview of tx details to be confirmed', async () => {
await sPage.amountInput.fill('0.000001');
await sPage.recipientInput.fill(TEST_TESTNET_ACCOUNT_2_STX_ADDRESS);
Expand Down

0 comments on commit 92aa04c

Please sign in to comment.