Skip to content

Conversation

@JanZachmann
Copy link
Contributor

Summary

Add comprehensive unit tests for network configuration state transitions in the Crux Core.

This PR is part of Phase 1 (Core State Transitions) of the frontend testing strategy, specifically PR 1.3: Network Tests.

Tests Added (21 total)

Network Form State Management (4 tests)

  • Start edit transitions to editing state with correct form data
  • Update with unchanged data keeps clean flag
  • Update with changed data sets dirty flag
  • Reset restarts edit from original adapter data

Network Configuration Responses (7 tests)

  • Static IP with rollback enters waiting state
  • Static IP without rollback enters waiting state
  • DHCP with rollback enters waiting state
  • DHCP without rollback goes to idle with spinner
  • Non-server adapter returns to idle
  • Error resets to editing state

IP Change Detection (4 tests)

  • Tick increments attempt counter
  • Tick skips polling when switching to DHCP
  • Timeout transitions to timeout state
  • Successful healthcheck on new IP updates model

Rollback Acknowledgment (4 tests)

  • Clears rollback flag in healthcheck
  • Handles missing healthcheck gracefully
  • Ack rollback response stops loading
  • Ack rollback response error sets error message

Test Coverage

Tests validate:

  • NetworkFormState transitions (Idle → Editing → Submitting)
  • NetworkChangeState state machine (Idle → ApplyingConfig → WaitingForNewIp → NewIpTimeout/NewIpReachable)
  • Form dirty flag tracking
  • DHCP vs static IP configuration handling
  • Rollback protection logic
  • Error handling and state recovery

QA

  • ✅ All tests pass: cargo test -p omnect-ui-core
  • ✅ No clippy warnings: cargo clippy -p omnect-ui-core

Add 21 tests covering network configuration state transitions:

Network Form State Management (4 tests):
- Start edit transitions to editing state with correct form data
- Update with unchanged data keeps clean flag
- Update with changed data sets dirty flag
- Reset restarts edit from original adapter data

Network Configuration Responses (7 tests):
- Static IP with rollback enters waiting state
- Static IP without rollback enters waiting state
- DHCP with rollback enters waiting state
- DHCP without rollback goes to idle with spinner
- Non-server adapter returns to idle
- Error resets to editing state

IP Change Detection (4 tests):
- Tick increments attempt counter
- Tick skips polling when switching to DHCP
- Timeout transitions to timeout state
- Successful healthcheck on new IP updates model

Rollback Acknowledgment (4 tests):
- Clears rollback flag in healthcheck
- Handles missing healthcheck gracefully
- Ack rollback response stops loading
- Ack rollback response error sets error message

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
JanZachmann added a commit to JanZachmann/omnect-ui that referenced this pull request Dec 18, 2025
Update FRONTEND_TEST_CONCEPT.md to reflect:

Phase 1 Complete (92 tests):
- PR omnect#77: Authentication Tests (17 tests)
- PR omnect#78: Device Tests (27 tests)
- PR omnect#79: Network Tests (21 tests)
- PR omnect#80: Reconnection Tests (27 tests)

Phase 2 Skipped:
- Effect emission testing deemed low-value after Phase 1 implementation
- Effects are auto-generated and handled by well-tested macros
- Testing implementation details (how Core communicates) vs behavior (what it does)
- Response handling tests in Phase 1 already validate request/response cycles

Lessons Learned:
- Colocated tests improve maintainability
- Domain organization mirrors code structure
- Response-focused testing validates behavior without coupling
- Avoid testing auto-generated types and macro usage

Key Patterns:
- Use `let _ = app.update(...)` for unused results
- Test response events not request events
- Organize with nested modules
- Use helper functions for test data

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
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.

1 participant