Thanks to visit codestin.com
Credit goes to github.com

Skip to content

REF: Prompt Modal with useReducer and tests#8622

Open
marcosrdz wants to merge 6 commits into
masterfrom
promptreducer
Open

REF: Prompt Modal with useReducer and tests#8622
marcosrdz wants to merge 6 commits into
masterfrom
promptreducer

Conversation

@marcosrdz

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors PromptPasswordConfirmationSheet to use a useReducer-based state model and introduces unit tests to cover key UI flows and reducer behavior.

Changes:

  • Refactor PromptPasswordConfirmationSheet state management from multiple useState calls to a dedicated reducer (PromptPasswordConfirmationSheet.reducer.ts).
  • Add unit tests covering modal flows (enter/create password, fake storage) and reducer behavior.
  • Adjust the navigation stack options for the prompt sheet (notably removing the header title).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
screen/PromptPasswordConfirmationSheet.tsx Refactors state handling to useReducer, extracts shake logic, and adds an alert path for password mismatch.
screen/PromptPasswordConfirmationSheet.reducer.ts New reducer module defining state/actions and resettable initial state.
tests/unit/PromptPasswordConfirmationSheet.test.tsx New UI-oriented unit tests for the sheet, including navigation/storage/haptics mocks.
tests/unit/prompt-password-confirmation-reducer.test.ts New unit tests validating reducer transitions and initial state behavior.
navigation/PromptPasswordConfirmationStack.tsx Updates stack screen options; currently removes the localized title.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +136 to +139
if (isCreateFlow && password && confirmPassword && password !== confirmPassword) {
failWithShake();
presentAlert({ message: loc.settings.passwords_do_not_match });
return;
Comment on lines 19 to 20
options={navigationStyle({
title: loc.settings.password,
presentation: 'formSheet',
Comment thread tests/unit/PromptPasswordConfirmationSheet.test.tsx Outdated
Comment on lines +208 to +211

it('rejects CREATE_FAKE_STORAGE when password is already in use', async () => {
setRoute({ modalType: MODAL_TYPES.CREATE_FAKE_STORAGE, returnTo: 'PlausibleDeniability' });
mockIsPasswordInUse.mockResolvedValue(true);

@GladosBlueWallet GladosBlueWallet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sheet's state machine is much less fragile now, and the tests cover the actual transitions instead of worshipping a mock altar. The shake/error paths remain intact, the create/encrypt flows are cleaner, and the reducer makes the whole thing less haunted. Another small miracle: the code now remembers what state it is in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants