Skip to content

Add unit tests for mushaf layout JSON export (follow-up to #620)#622

Open
hammadxcm wants to merge 1 commit into
TarteelAI:mainfrom
hammadxcm:test/mushaf-layout-json-export
Open

Add unit tests for mushaf layout JSON export (follow-up to #620)#622
hammadxcm wants to merge 1 commit into
TarteelAI:mainfrom
hammadxcm:test/mushaf-layout-json-export

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

Description

Adds unit tests for Exporter::ExportMushafLayout#export_json (the JSON layout export shipped in #620, closing #257). When that PR was opened the codebase had no exporter tests and I couldn't run anything end-to-end, so the original implementation went in with only static checks. This locks the JSON shape down with a real Minitest spec.

Coverage (9 cases / 31 assertions):

  • export_json returns the JSON directory path it wrote to.
  • info.json carries the mushaf metadata (name, number_of_pages, lines_per_page, font_name).
  • One <page_number>.json file is written per page.
  • surah_name line carries surah_number, type, and centered alignment (and omits ayah-only keys).
  • basmallah line is centered with no word data.
  • ayah line carries data (word text), first_word_id / last_word_id, and justified alignment.
  • ayah falls back to justified when no MushafLineAlignment row exists for the line.
  • Word text honors Mushaf#text_type_method — switching the method to code_v1 swaps the exported text to the glyph codes.
  • Words on a line are sorted by word_index even when the underlying records are out of order.

Test style

Follows the convention already established by test/services/resources/ — standalone Minitest, PORO/Struct stubs for the ActiveRecord models (Mushaf, MushafPage, MushafLineAlignment, plus fake page/word/alignment records), no Rails boot, no database. Stubs are guarded with unless Object.const_defined?(...) so they don't clobber real constants if Rails were loaded.

Related Issue

Follow-up to #257 (closed by #620, which shipped the feature without tests).

Motivation and Context

The JSON export is now consumed by downstream apps — pinning its shape with tests prevents accidental regressions (e.g., a stray rename of a key or a change to the line-type vocabulary). The same fake-AR pattern can be reused for the SQLite export and other exporter tests in the future.

How Has This Been Tested?

$ ruby -Itest test/lib/exporter/export_mushaf_layout_test.rb
9 runs, 31 assertions, 0 failures, 0 errors, 0 skips

Also ruby -c clean and RuboCop (Layout/Lint) clean.

Screenshots (if appropriate):

N/A — test-only change.

Locks in the JSON layout shape introduced in TarteelAI#620 (info.json metadata
file, one <page>.json per page, ayah/surah_name/basmallah line types,
centered/justified alignment, first/last word index range, and word
text resolved via Mushaf#text_type_method) using standalone Minitest
with PORO stubs for the ActiveRecord models, matching the convention
already established in test/services/resources/.

Run with: ruby -Itest test/lib/exporter/export_mushaf_layout_test.rb

Related to TarteelAI#257
@hammadxcm

Copy link
Copy Markdown
Contributor Author

@naveed-ahmad Follow Up PR on unit tests.

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.

1 participant