Skip to content

Add IndexedDB integration tests for Planet CacheManager.js#5906

Merged
omsuneri merged 1 commit intosugarlabs:masterfrom
farhan-momin:todo-planet-CacheManager-tests
Feb 26, 2026
Merged

Add IndexedDB integration tests for Planet CacheManager.js#5906
omsuneri merged 1 commit intosugarlabs:masterfrom
farhan-momin:todo-planet-CacheManager-tests

Conversation

@farhan-momin
Copy link
Contributor

Summary

  • This PR adds comprehensive integration tests for planet/js/CacheManager.js, covering IndexedDB initialization, all cache operations (metadata, project data, thumbnail), expiry logic, LRU cache removal, cache stats, and cleanup, using in-memory IndexedDB from fake-indexeddb.
  • The tests include 6 todos in Jest tests (also shown in results for npm run test).

Changes

1. Added fake-indexeddb package for testing IndexedDB operations

  • What it is: fake-indexeddb is an in-memory implementation of the IndexedDB API for Node.js environments.
  • Why it is needed: Without a real IndexedDB implementation, its operations in CacheManager.js cannot be tested.
  • How it is used: The IDBFactory and IDBKeyRange from fake-indexeddb Package are used in the IndexedDB CacheManager integration test suite. This allows to open a in-memory IndexedDB database, and execute all DB operations as they would in a browser.

2. Added 38 IndexedDB integration tests using fake-indexeddb for CacheManager.js


Test Additions

Describe Block Tests Added Tests
init() 5
  • returns true on success and sets isInitialized
  • calls clearExpired automatically
  • returns false when indexedDB is missing
  • skips re-opening DB on second call
  • creates all three object stores
cacheMetadata / getMetadata 4
  • cache and retrieve metadata by id
  • unknown id returns null
  • expired entry returns null
  • non-expired entry returns data
cacheProject / getProject 4
  • cache and retrieve project by id
  • unknown id returns null
  • expired project returns null
  • project stored past metadataExpiry but within projectExpiry
cacheThumbnail / getThumbnail 5
  • Cache and retrieve thumbnail data URL
  • cacheThumbnail returns value
  • unknown id returns null
  • expired thumbnail returns null
  • getThumbnail does not update lastAccessed
clearExpired 5
  • returns 0 when nothing expired
  • removes only expired metadata
  • removes only expired projects
  • clears from all three stores
  • returns 0 after clearAll()
clearAll 4
  • clearAll returns true
  • getStats return all zeros after clearing
  • cached items are inaccessible after clearing
  • calling twice returns true both times
getStats 5
  • All zeros after init
  • accurate counts after caching
  • Returns all zeros after clearAll()
  • re-caching same id does not double-count
  • counts expired entries
enforceMaxSize 3
  • count stays at maxCacheSize after insertion beyond max
  • does not remove when count below the limit
  • LRU removal: oldest lastAccessed entry is removed first on overflow
updateLastAccessed 3
  • getMetadata updates lastAccessed
  • does not throw for non-existent key
  • getProject updates lastAccessed

Total tests added: 38


Steps to Test PR

  1. Install dependencies:
    npm install
    (Ensures fake-indexeddb package is added)

  2. Run the test suite:
    npm run test

  3. All test should pass


Coverage

Before

Screenshot from 2026-02-26 01-13-18

After

Screenshot from 2026-02-26 01-12-30

Verification

All CacheManager.js tests pass

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@farhan-momin farhan-momin force-pushed the todo-planet-CacheManager-tests branch from 88319a0 to 90e3747 Compare February 25, 2026 20:05
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@farhan-momin farhan-momin marked this pull request as ready for review February 25, 2026 20:11
@farhan-momin
Copy link
Contributor Author

@omsuneri @walterbender Ready for review

Copy link
Contributor

@7se7en72025 7se7en72025 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !! @walterbender

@omsuneri omsuneri merged commit 87187dc into sugarlabs:master Feb 26, 2026
7 checks passed
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.

3 participants