Add unit tests for storage, settings and achievements

Đang mở
#30 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
78/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
testing

Hướng nghiên cứu

Start with shared/storage.ts, shared/settings.ts, and shared/achievements.ts at the listed lines, then check the project’s package scripts and CI setup to find how tests should run. Add a Node test environment with an in-memory localStorage stub and cover the listed cases, including the reset behavior. Done when the tests pass in CI and the issue’s acceptance cases are covered.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

help wanted severity: medium testing

Summary

The three modules that hold all persisted player data (high scores, settings, trophies, stats) are Phaser-free and have no tests.

Where

  • shared/storage.ts:4-30
  • shared/settings.ts:55-78
  • shared/achievements.ts:91, shared/achievements.ts:100-167

Suggested fix

Use a node environment with an in-memory localStorage stub and vi.resetModules() plus a dynamic import per test, because settings and achievements read storage at import.

Storage

  • loadJSON returns the fallback when nothing is stored, when storage is unavailable or throws, and on invalid JSON
  • saveJSON writes under the gh-arcade: prefix and swallows a throwing setItem
  • submitHighScore: 10 is a record, 10 again is not, 9 is not, 11 is; 0 on a fresh game is not

Settings

  • Defaults; reducedMotion follows matchMedia
  • A stored partial merges over defaults
  • updateSettings persists, notifies each listener once and returns the new object; unsubscribe works
  • resetSettings restores defaults and notifies

Achievements

  • unlock of an unknown id returns false; a known id returns true once
  • The tenth unlock grants the collection trophy; the collection trophy itself is not counted
  • addCounter unlocks exactly at the target
  • recordPlay accumulates plays, best and total score
  • The "play every game" trophy unlocks only after every game has a play
  • drainRecentUnlocks returns new trophies once
  • After resetTrophies, nothing is unlocked and drainRecentUnlocks() is empty (fails today)

Acceptance criteria

  • The cases above pass in CI

Getting started

  • Relevant files: shared/storage.ts, shared/settings.ts, shared/achievements.ts
  • Run locally: npm install, then npm run dev
  • Checks: npm run typecheck and npm run build (there is no test suite yet)
  • Related docs: README.md

Filed by repo-audit/full-audit at b001f5d. Severity: medium. Effort: M. audit-key: testing|shared/achievements.ts|unlock

Ngôn ngữ chính
TypeScript
Star
3
Fork
3
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TMHSDigital/GH-Arcade

Tất cả issue của TMHSDigital/GH-Arcade

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.