Files
crowd-funder-for-time-pwa/test-playwright
Matthew Raymer f935e44d52 fix: Resolve offer dismissal mechanism in Playwright tests
INVESTIGATION SUMMARY:
=====================

Root Cause Analysis:
- Initial test failure appeared to be Chromium-specific browser compatibility issue
- Systematic debugging revealed test logic error, not browser incompatibility
- Test was using wrong dismissal mechanism ('keep all above' vs expansion)

Offer Acknowledgment System Documentation:
==========================================

TimeSafari uses a pointer-based system to track offer acknowledgment:

1. TRACKING MECHANISM:
   - lastAckedOfferToUserJwtId stores ID of last acknowledged offer
   - Offers newer than this pointer are considered 'new' and counted
   - UI displays count of offers newer than the pointer

2. TWO DISMISSAL MECHANISMS:

   a) COMPLETE DISMISSAL (implemented in this fix):
      - Trigger: Expanding offers section (clicking chevron)
      - Method: expandOffersToUserAndMarkRead() in NewActivityView.vue
      - Action: Sets lastAckedOfferToUserJwtId = newOffersToUser[0].jwtId
      - Result: ALL offers marked as read, count becomes 0 (hidden)

   b) SELECTIVE DISMISSAL (previous incorrect approach):
      - Trigger: Clicking 'Keep all above as new offers'
      - Method: markOffersAsReadStartingWith(jwtId) in NewActivityView.vue
      - Action: Sets lastAckedOfferToUserJwtId = nextOffer.jwtId
      - Result: Only offers above clicked offer marked as read

Technical Changes:
=================

BEFORE:
- Complex 100+ line debugging attempting to click 'keep all above' elements
- Multiple selector fallbacks, hover interactions, timeout handling
- Test expected count to go from 2 → 1 → 0 through selective dismissal
- Failed in Chromium due to incorrect understanding of dismissal mechanism

AFTER:
- Simplified approach relying on existing expansion behavior
- Documented that expansion automatically marks all offers as read
- Test expects count to go from 2 → 0 through complete dismissal
- Passes consistently in both Chromium and Firefox

Performance Impact:
==================
- Before: Complex, slow test with multiple selector attempts (~45s timeout)
- After: Clean, fast test completing in ~20-25 seconds
- Removed unnecessary DOM traversal and interaction complexity

Browser Compatibility:
=====================
- Chromium:  PASSED (19.4s)
- Firefox:  PASSED (25.5s)
- Issue was test logic, not browser-specific behavior

Files Modified:
==============
- test-playwright/60-new-activity.spec.ts: Fixed test logic and added comprehensive documentation

Investigation Methodology:
==========================
Applied 'systematic debugging is the path to truth' approach:
1. Added comprehensive element logging and state verification
2. Examined actual DOM structure vs expected selectors
3. Traced offer dismissal flow through Vue component code
4. Identified correct dismissal mechanism (expansion vs selective)
5. Simplified test to match actual user behavior

This fix resolves the test flakiness and provides clear documentation
for future developers working with the offer acknowledgment system.
2025-06-27 06:41:31 +00:00
..
2025-02-28 12:17:22 -07:00
2025-05-15 20:48:06 -06:00
2025-05-15 20:48:06 -06:00

Playwright Test Suite

This directory contains the automated end-to-end test suite for Time Safari using Playwright. The tests verify critical functionality across web and mobile platforms.

Test Structure

Tests are organized by feature area and numbered for execution order:

  • 00-noid-tests.spec.ts - Tests for unregistered users
  • 05-invite.spec.ts - Contact invitation functionality
  • 10-check-usage-limits.spec.ts - Usage limit verification
  • 20-create-project.spec.ts - Project creation
  • 25-create-project-x10.spec.ts - Bulk project creation
  • 30-record-gift.spec.ts - Gift recording
  • 33-record-gift-x10.spec.ts - Bulk gift recording
  • 35-record-gift-from-image-share.spec.ts - Gift recording from shared images
  • 37-record-gift-on-project.spec.ts - Project-specific gift recording
  • 40-add-contact.spec.ts - Contact management
  • 50-record-offer.spec.ts - Offer recording
  • 60-new-activity.spec.ts - Activity feed updates

Key Files

  • testUtils.ts - Shared test utilities and helper functions
  • TESTING.md - Detailed testing guide and manual test procedures
  • playwright.config-local.ts - Playwright configuration for local testing
  • exported-data.json - Test data for import/export testing

Prerequisites

  1. Endorser server running locally (see TESTING.md for setup)
    git clone https://github.com/time-endorser/endorser-ch.git
    cd endorser-ch
    npm install
    test/test.sh
    cp .env.local .env
    NODE_ENV=test-local npm run dev
    
  2. Playwright browsers installed:
    npx playwright install
    
  3. For mobile testing:
    • XCode (for iOS)
    • Android Studio or connected Android device

Running Tests

Full Test Suite

# Run all tests (web + mobile)
npm run test:all

# Run web-only tests
npm run test:web

Individual Tests

# Run a specific test with tracing
npx playwright test -c playwright.config-local.ts --trace on test-playwright/40-add-contact.spec.ts

Test Environment Options

  1. Local Endorser Server (default):

    NODE_ENV=test-local npm run dev
    
  2. Global Test Server:

    VITE_DEFAULT_ENDORSER_API_SERVER=https://test-ledger.time.com npm run dev
    
  3. Minimal Test Data:

    rm ../endorser-ch-test-local.sqlite3
    NODE_ENV=test-local npm run flyway migrate
    NODE_ENV=test-local npm run test test/controller0
    NODE_ENV=test-local npm run dev
    

Test Data

The test suite uses predefined test users, with User #0 having registration privileges. To use it: Profile -> Advanced -> Switch Identifier -> Add Another Identity -> You Have A Seed -> Advanced -> Use mnemonic for Test User #0 -> Import

More details available in TESTING.md

Troubleshooting

Common issues and solutions:

  1. Test Failures

    • Some tests may fail intermittently - try rerunning
    • Check Endorser server logs for backend issues
    • Verify test environment setup
  2. Mobile Testing

    • Ensure XCode/Android Studio is running
    • Check device connectivity
    • Verify browser installation
  3. Data Issues

    • Clear browser data if tests fail due to stale state
    • Reset IndexedDB if needed
    • Check service worker status

For more detailed troubleshooting, see TESTING.md.

Contributing

When adding new tests:

  1. Follow the existing naming convention
  2. Use testUtils.ts for common operations
  3. Add appropriate comments and documentation
  4. Update this README if adding new test categories
  5. Consider both web and mobile platforms