-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Automated test suite — unit, component #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tuliomir
wants to merge
20
commits into
master
Choose a base branch
from
feat/automated-test-suite-layers-1-3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ecd05ec
feat: add automated test suite PoC — 57 tests across 3 layers
tuliomir 8f9eeb2
fix: make entire test suite pass — fix pre-existing test failures
tuliomir 67c4b44
chore: allow-scripts entry for jest-circus's unrs-resolver
tuliomir 4f4e9d3
fix: align reown.test.js with rejectAll saga's actual yield order
tuliomir bdbf958
test: add slice-refactor safety net + testing guide
tuliomir 49a4e57
chore: address review nits + pin jest-circus
tuliomir ec3b546
docs: annotate review findings that were intentionally not fixed
tuliomir 940f684
fix(ci): regenerate package-lock.json with Node 22
tuliomir 0864921
fix(lint): import jest globals in reducer test files
tuliomir d19358e
chore: address second review pass — lint hygiene + duplicate test
tuliomir 26638c6
test: address third-pass review — strengthen contracts, dedupe helper
tuliomir ee6848a
docs: add AGENTS.md, CLAUDE.md, and writing-tests skill
tuliomir 7a20c5f
docs: refine test docs per QA audit — gotchas first, less filler
tuliomir d5ff9f0
fix(test): address CodeRabbit lint findings on PR #863
tuliomir 86e8352
test: restore nanoContract coverage lost in 8f9eeb2
tuliomir 037b6e8
fix(test): import jest globals in utils + InitWallet tests
tuliomir 1c6dc07
fix(test): address CodeRabbit lint findings on screen tests
tuliomir adeff1a
test: tighten screen test contracts per CodeRabbit nitpicks
tuliomir 1e114e7
fix: address Copilot review on PR #863
tuliomir a5ae036
docs: break circular AGENTS.md ↔ CLAUDE.md pointer
tuliomir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Test helper: mock navigation objects for React Navigation 7. | ||
| * | ||
| * Provides plain mock objects that can be passed as props or returned | ||
| * from `useNavigation()`/`useRoute()` in a `jest.mock(...)` factory at | ||
| * module scope in the consuming test file. | ||
| * | ||
| * Note: this file does NOT call `jest.mock(...)` itself. `jest.mock` is | ||
| * hoisted by Babel only when written at top-level of the test module — | ||
| * wrapping it inside an exported helper would defeat the hoist and run | ||
| * after the modules under test are already imported. | ||
| */ | ||
| import { jest } from '@jest/globals'; | ||
|
|
||
| export function createMockNavigation() { | ||
| return { | ||
| navigate: jest.fn(), | ||
| push: jest.fn(), | ||
| replace: jest.fn(), | ||
| goBack: jest.fn(), | ||
| reset: jest.fn(), | ||
| setOptions: jest.fn(), | ||
| setParams: jest.fn(), | ||
| dispatch: jest.fn(), | ||
| addListener: jest.fn(() => jest.fn()), // returns unsubscribe | ||
| canGoBack: jest.fn(() => true), | ||
| isFocused: jest.fn(() => true), | ||
| getParent: jest.fn(), | ||
| getState: jest.fn(() => ({ | ||
| index: 0, | ||
| routes: [{ name: 'MockRoute', key: 'mock-key' }], | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| export function createMockRoute(params: Record<string, unknown> = {}) { | ||
| return { | ||
| key: 'mock-route-key', | ||
| name: 'MockRoute', | ||
| params, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Test helper: creates a Redux store with optional preloaded state. | ||
| * | ||
| * Uses the real reducer from the app so that dispatched actions | ||
| * produce the same state transitions as production code. | ||
| */ | ||
| import { legacy_createStore as createStore } from 'redux'; | ||
| import { reducer } from '../../src/reducers/reducer'; | ||
|
|
||
| /** | ||
| * Create a Redux store for testing with optional state overrides. | ||
| * | ||
| * @param preloadedState - Partial state merged on top of the reducer's | ||
| * built-in initialState. Pass only the keys you care about. | ||
| */ | ||
| export function createTestStore(preloadedState: Record<string, unknown> = {}) { | ||
| // Dispatching an unknown action returns initialState from the reducer, | ||
| // which we then merge with the caller's overrides. | ||
| const baseState = reducer(undefined, { type: '@@INIT' }); | ||
| return createStore(reducer, { ...baseState, ...preloadedState } as any); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Test helper: renders a React component wrapped in all the providers | ||
| * that the Hathor Wallet app expects (Redux, Navigation). | ||
| * | ||
| * Usage: | ||
| * const { getByText } = renderWithProviders(<MyScreen />, { | ||
| * preloadedState: { isOnline: true }, | ||
| * }); | ||
| */ | ||
| import React from 'react'; | ||
| import { render, RenderOptions } from '@testing-library/react-native'; | ||
| import { Provider } from 'react-redux'; | ||
| import { NavigationContainer } from '@react-navigation/native'; | ||
| import { createTestStore } from './mockStore'; | ||
|
|
||
| interface ExtendedRenderOptions extends Omit<RenderOptions, 'wrapper'> { | ||
| /** Partial Redux state merged on top of initialState. */ | ||
| preloadedState?: Record<string, unknown>; | ||
| /** Supply your own store (e.g. if you need to dispatch in the test). */ | ||
| store?: ReturnType<typeof createTestStore>; | ||
| /** If false, skip wrapping in NavigationContainer (default: true). */ | ||
| withNavigation?: boolean; | ||
| } | ||
|
|
||
| export function renderWithProviders( | ||
| ui: React.ReactElement, | ||
| { | ||
| preloadedState = {}, | ||
| store = createTestStore(preloadedState), | ||
| withNavigation = true, | ||
| ...renderOptions | ||
| }: ExtendedRenderOptions = {}, | ||
| ) { | ||
| function Wrapper({ children }: { children: React.ReactNode }) { | ||
| const content = <Provider store={store}>{children}</Provider>; | ||
| if (withNavigation) { | ||
| return <NavigationContainer>{content}</NavigationContainer>; | ||
| } | ||
| return content; | ||
| } | ||
|
|
||
| return { | ||
| store, | ||
| ...render(ui, { wrapper: Wrapper, ...renderOptions }), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * Unit tests for the Reown pending-requests reducer slice. | ||
| * | ||
| * Covers the slice introduced on this branch: | ||
| * - state.reown.pendingRequests | ||
| * - REOWN_SET_PENDING_REQUESTS action | ||
| * | ||
| * Acts as a safety net for the future RTK-slices refactor by pinning: | ||
| * - Behavior (action -> state) | ||
| * - Initial state shape of state.reown | ||
| * - Action-type literal string | ||
| */ | ||
| import { reducer } from '../../src/reducers/reducer'; | ||
| import { setReownPendingRequests, types } from '../../src/actions'; | ||
|
|
||
| const getInitialState = () => reducer(undefined, { type: '@@INIT' }); | ||
|
|
||
| // ─── Behavior ────────────────────────────────────────────────────────────── | ||
| describe('REOWN_SET_PENDING_REQUESTS', () => { | ||
| it('initial state.reown.pendingRequests is an empty array', () => { | ||
| expect(getInitialState().reown.pendingRequests).toEqual([]); | ||
| }); | ||
|
|
||
| it('replaces pendingRequests with the payload (does not append)', () => { | ||
| let state = reducer(getInitialState(), setReownPendingRequests([{ id: 'a' }])); | ||
| expect(state.reown.pendingRequests).toEqual([{ id: 'a' }]); | ||
|
|
||
| state = reducer(state, setReownPendingRequests([{ id: 'b' }, { id: 'c' }])); | ||
| expect(state.reown.pendingRequests).toEqual([{ id: 'b' }, { id: 'c' }]); | ||
| }); | ||
|
|
||
| it('accepts an empty array (clears pending)', () => { | ||
| let state = reducer(getInitialState(), setReownPendingRequests([{ id: 'a' }])); | ||
| state = reducer(state, setReownPendingRequests([])); | ||
| expect(state.reown.pendingRequests).toEqual([]); | ||
| }); | ||
|
|
||
| it('does not mutate other reown sub-keys', () => { | ||
| const initial = getInitialState(); | ||
| const next = reducer(initial, setReownPendingRequests([{ id: 'a' }])); | ||
| expect(next.reown.sessions).toBe(initial.reown.sessions); | ||
| expect(next.reown.connectionFailed).toBe(initial.reown.connectionFailed); | ||
| expect(next.reown.modal).toBe(initial.reown.modal); | ||
| expect(next.reown.client).toBe(initial.reown.client); | ||
| expect(next.reown.error).toBe(initial.reown.error); | ||
| }); | ||
|
|
||
| it('returns a new state reference (no in-place mutation)', () => { | ||
| const initial = getInitialState(); | ||
| const next = reducer(initial, setReownPendingRequests([{ id: 'a' }])); | ||
| expect(next).not.toBe(initial); | ||
| expect(next.reown).not.toBe(initial.reown); | ||
| }); | ||
| }); | ||
|
|
||
| // ─── Initial-State Shape Contract ────────────────────────────────────────── | ||
| // Pins the keys of state.reown. A future RTK-slices refactor must preserve | ||
| // this shape OR consciously update this snapshot. | ||
| describe('initial state.reown shape contract', () => { | ||
| it('exposes the expected reown keys', () => { | ||
| const reownKeys = Object.keys(getInitialState().reown).sort(); | ||
| expect(reownKeys).toEqual([ | ||
| 'client', | ||
| 'connectionFailed', | ||
| 'createNanoContractCreateTokenTx', | ||
| 'createToken', | ||
| 'error', | ||
| 'forceNavigateToDashboard', | ||
| 'modal', | ||
| 'newNanoContractTransaction', | ||
| 'pendingRequests', | ||
| 'sendTransaction', | ||
| 'sessions', | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| // ─── Action-Type Contract ────────────────────────────────────────────────── | ||
| // Pins the literal `.type` strings; catches RTK auto-renaming. | ||
| describe('action-type contract', () => { | ||
| it('setReownPendingRequests.type', () => { | ||
| expect(setReownPendingRequests([]).type).toBe('REOWN_SET_PENDING_REQUESTS'); | ||
| }); | ||
|
|
||
| it('types.REOWN_SET_PENDING_REQUESTS literal string', () => { | ||
| expect(types.REOWN_SET_PENDING_REQUESTS).toBe('REOWN_SET_PENDING_REQUESTS'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.