Decoding Digital Anomalies

  1. World Clock Unit Tests
    1. Running Tests
    2. Test Coverage
    3. Test Results

World Clock Unit Tests

Running Tests

Open the centralized test runner:

# From project root
cd hexo-blog/source/tools
# Open test-runner.html in browser or use:
python -m http.server 8000
# Then navigate to: http://localhost:8000/test-runner.html

Tests are integrated into the main test runner with all other tools.

Test Coverage

The test suite covers:

Constructor & Initialization

  • Default timezone initialization
  • Timezone select population
  • Initial clock rendering

Timezone Operations

  • Adding new timezones
  • Removing timezones
  • Preventing duplicate timezones
  • Extracting city names from timezone strings

Clock Updates

  • Time formatting for all timezones
  • Date formatting for all timezones
  • Handling invalid timezones
  • Handling missing DOM elements
  • Auto-update every second

UI Rendering

  • Creating clock cards
  • Rendering all clocks
  • Preserving add button
  • Re-rendering after changes
  • Showing modal
  • Hiding modal
  • Closing on outside click

Global Functions

  • showAddModal()
  • hideAddModal()
  • addTimezone()
  • removeTimezone()

Edge Cases

  • Empty timezone list
  • Many timezones (50+)
  • Special characters in timezone names
  • Rapid add/remove operations
  • Invalid timezone indices

Test Results

Expected console output:

🧪 Starting World Clock Tests...

✅ Constructor: initializes with default timezones
✅ Constructor: populates timezone select
✅ getCityName: extracts city from timezone
✅ createClockCard: creates card with correct structure
...
✅ Edge: handles rapid add/remove operations

✨ Tests completed!
Share