Skip to content

Commit 6c06940

Browse files
Use Navigation.goBack instead of navigate after agent deletion
After deleting an agent, the app was pushing a new Agents list screen onto the navigation stack instead of popping back to the existing one. This caused the back button to return to the stale Edit Agent page. Co-authored-by: Nicolás Bonet <NicolasBonet@users.noreply.github.com>
1 parent a7ce524 commit 6c06940

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/libs/actions/Agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function deleteAgent(accountID: number) {
282282
];
283283

284284
write(WRITE_COMMANDS.DELETE_AGENT, {agentAccountID: accountID}, {optimisticData, successData, failureData});
285-
Navigation.navigate(ROUTES.SETTINGS_AGENTS);
285+
Navigation.goBack(ROUTES.SETTINGS_AGENTS);
286286
}
287287

288288
export {

tests/unit/AgentActionTest.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import ONYXKEYS from '@src/ONYXKEYS';
88
import type {AnyOnyxUpdate} from '@src/types/onyx/Request';
99

1010
jest.mock('@libs/API');
11-
jest.mock('@libs/Navigation/Navigation', () => ({navigate: jest.fn()}));
11+
jest.mock('@libs/Navigation/Navigation', () => ({navigate: jest.fn(), goBack: jest.fn()}));
1212

1313
const mockWrite = jest.mocked(write);
14-
const mockNavigate = jest.mocked(Navigation.navigate);
14+
const mockGoBack = jest.mocked(Navigation.goBack);
1515

1616
function getWriteOptions(): {optimisticData: AnyOnyxUpdate[]; successData: AnyOnyxUpdate[]; failureData: AnyOnyxUpdate[]} {
1717
const options = mockWrite.mock.calls.at(0)?.at(2);
@@ -386,10 +386,10 @@ describe('deleteAgent', () => {
386386
expect((promptUpdate?.value as Record<string, unknown>)?.errors).toBeTruthy();
387387
});
388388

389-
it('calls Navigation.navigate after issuing the write', () => {
389+
it('calls Navigation.goBack after issuing the write', () => {
390390
deleteAgent(TEST_ACCOUNT_ID);
391391

392-
expect(mockNavigate).toHaveBeenCalledTimes(1);
392+
expect(mockGoBack).toHaveBeenCalledTimes(1);
393393
});
394394
});
395395

0 commit comments

Comments
 (0)