Skip to content

Latest commit

 

History

History
214 lines (169 loc) · 5.34 KB

File metadata and controls

214 lines (169 loc) · 5.34 KB

Price Hider Extension - Test Suite Summary

Overview

This document provides a summary of the comprehensive test suite created for the Price Hider browser extension.

Test Statistics

  • Total Tests: 107
  • Test Files: 2
  • All Tests Passing: ✅ Yes

Coverage Metrics

------------|---------|----------|---------|---------|-------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------|---------|----------|---------|---------|-------------------
All files   |   98.42 |    84.94 |     100 |    98.4 |                   
 content.js |   98.42 |    84.94 |     100 |    98.4 | 304,340           
------------|---------|----------|---------|---------|-------------------
  • Statement Coverage: 98.42% ✅ (Target: 70%)
  • Branch Coverage: 84.94% ✅ (Target: 70%)
  • Function Coverage: 100% ✅ (Target: 70%)
  • Line Coverage: 98.4% ✅ (Target: 70%)

Test Files

1. content.test.js (52 tests)

Unit tests covering individual functions and logic:

Pattern Matching (4 tests)

  • ✅ Dollar amounts with prefix ($100)
  • ✅ Dollar amounts with suffix (100€)
  • ✅ Various currency codes (USD, EUR, GBP, etc.)
  • ✅ Avoiding false positives (plain numbers)

looksLikePrice Function (5 tests)

  • ✅ Detection with currency symbols
  • ✅ Detection with currency codes
  • ✅ Rejection without currency
  • ✅ Rejection without digits
  • ✅ Empty/null handling

Style Injection (2 tests)

  • ✅ Preventing duplicate style injection
  • ✅ CSS rule validation

DOM Masking (5 tests)

  • ✅ Simple price text masking
  • ✅ Multiple prices in same text
  • ✅ Script tag exclusion
  • ✅ Input field exclusion
  • ✅ Ignore attribute respect

isPriceContainer Function (6 tests)

  • ✅ Split-element price identification
  • ✅ Already processed element rejection
  • ✅ Broad container tag rejection
  • ✅ Non-price content rejection
  • ✅ Long text rejection
  • ✅ Ignored section handling

shouldSkipTextNode Function (7 tests)

  • ✅ Script tag text nodes
  • ✅ Style tag text nodes
  • ✅ Input element text nodes
  • ✅ Already masked text nodes
  • ✅ Ignored section text nodes
  • ✅ Regular text nodes
  • ✅ Orphaned text nodes

Integration Tests (6 tests)

  • ✅ Schema.org attributes
  • ✅ ARIA labels
  • ✅ Multiple currencies
  • ✅ Number format variations
  • ✅ Price ranges
  • ✅ Content preservation

Edge Cases (7 tests)

  • ✅ Empty elements
  • ✅ Deeply nested structures
  • ✅ Text boundary prices
  • ✅ Special characters
  • ✅ Excessive spacing
  • ✅ Malformed HTML
  • ✅ Whitespace-only text

Currency Symbol Coverage (8 tests)

  • ✅ Dollar ($)
  • ✅ Euro (€)
  • ✅ Pound (£)
  • ✅ Yen (¥)
  • ✅ Rupee (₹)
  • ✅ Won (₩)
  • ✅ Ruble (₽)
  • ✅ Baht (฿)

Performance (2 tests)

  • ✅ Large element counts (100+ items)
  • ✅ Rapid DOM changes

2. content.integration.test.js (55 tests)

End-to-end integration tests using actual exported functions:

Function Testing (40 tests)

  • injectStyles (3 tests)
  • looksLikePrice (3 tests)
  • isPriceContainer (7 tests)
  • shouldSkipTextNode (8 tests)
  • hasPriceMatch (2 tests)
  • maskTextNode (6 tests)
  • maskPriceElements (6 tests)
  • walkAndMask - Full Integration (9 tests)

Real-world Scenarios (4 tests)

  • ✅ E-commerce product listings
  • ✅ Shopping carts
  • ✅ International pricing
  • ✅ Discount labels

Edge Cases and Robustness (7 tests)

  • ✅ Malformed prices
  • ✅ Very long numbers
  • ✅ Text boundaries
  • ✅ Empty documents
  • ✅ Deep nesting
  • ✅ Mixed content
  • ✅ Unicode/special characters

Testing Technology Stack

  • Test Framework: Jest 29.7.0
  • Test Environment: jsdom (simulated browser environment)
  • DOM Testing Utilities: @testing-library/dom 10.4.0

Key Features Tested

Multi-Currency Support

Tests verify detection and masking of:

  • 30+ currency symbols
  • 14+ currency codes
  • Various number formats (commas, periods, spaces)

Smart Detection

  • Text-based price masking
  • Element-level price containers
  • Split-element prices (currency and amount in separate elements)
  • Schema.org microdata
  • Accessibility attributes

DOM Safety

  • Script/style tag exclusion
  • Input field protection
  • Selective ignoring via data attributes
  • Non-destructive masking

Performance

  • Handles 100+ price elements
  • Rapid DOM mutation handling
  • Deep nesting support

Running the Tests

# Install dependencies
npm install

# Run all tests
npm test

# Run tests in watch mode (for development)
npm run test:watch

# Generate coverage report
npm run test:coverage

CI/CD Integration

These tests are ready to be integrated into CI/CD pipelines:

# Example GitHub Actions workflow
- name: Install dependencies
  run: npm install
  
- name: Run tests
  run: npm test
  
- name: Check coverage
  run: npm run test:coverage

Maintenance

When adding new features to the extension:

  1. Add unit tests in content.test.js for new functions
  2. Add integration tests in content.integration.test.js for workflows
  3. Ensure coverage remains above 70% (current: 98%+)
  4. Test both happy paths and edge cases
  5. Run tests before committing: npm test

Notes

  • All tests run in an isolated jsdom environment
  • No actual browser required for testing
  • Tests are fast (completes in <1 second)
  • Zero test flakiness - deterministic results
  • Cross-platform compatible (macOS, Linux, Windows)