fix(review): stats/a11y review-minor cleanup (bookshelf-6edv) #707
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bd-bookshelf-6edv"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
.stats-cards--listeningmodifier class fromtemplates/pages/stats.html(no CSS rule exists for it)internal/stats/handler_internal_test.go(buildCategoryDonutSlices,buildRatingDonutSlices,buildProgressDonutSlices,buildStatusDonutSlices) to use canonical BeforeEach+JustBeforeEach pattern with one Expect per Itinternal/librarystats/handler_test.gonil-slice tests by hoisting JSON decode intoJustBeforeEachand folding type+empty assertion intoAnd(BeAssignableToTypeOf, BeEmpty)templates/pages/library_stats.htmlempty-state guard to consider all 5 chart fields (FormatSlices/LangSlices/MetadataSlices/PageCountBars/PublicationBars) instead of onlyStats.Formats/Stats.Languages; add corresponding handler tests for the corrected guard conditionDeferred / skipped
Test plan
make test— all passgo build ./...— compiles cleanGetHandler empty-state guardtests cover: all-nil (shows empty state), MetadataSlices-only, PageCountBars-only, PublicationBars-only (none show empty state)Closes bead bookshelf-6edv on merge.
Security Review — bookshelf-6edv
Diff reviewed: dead CSS class removal (
stats-cards--listening), Ginkgo test refactors (BDD-conformBeforeEach/JustBeforeEachsplits), a library_stats empty-state guard fix, and one strengthened JSON-shape assertion.Scoping / data-exposure check (library_stats empty-state guard)
The template change in
templates/pages/library_stats.htmlreplaces:with:
All five fields (
FormatSlices,LangSlices,MetadataSlices,PageCountBars,PublicationBars) are populated insiderenderHTMLfrom aCollectionStatsstruct fetched viagetStats(r.Context(), userID)— the same user-scoped call that was already in place before this PR. The change only widens the empty-state condition to include all chart fields rather than just two; it does not add a new data source, does not touch the query that populates the struct, and does not change what is rendered or to whom. No scoping regression.Other checks
stats-cards--listening→stats-cards): purely cosmetic, no data or auth impact.BeforeEachsetup /JustBeforeEachinvocation / oneExpectperIt). One genuinely new assertion added (And(BeAssignableToTypeOf([]any{}), BeEmpty())for the nil-slice JSON shape) — tighter than before, no regression vector.emptyStateTemplateFShelper: in-memory test FS mirroring the real guard condition; test-only, no prod impact.Findings
None.
REVIEW VERDICT: 0 blocker, 0 major, 0 minor
Code Review — bookshelf-6edv
Fix #1 — dead
.stats-cards--listeningclass (templates/pages/stats.html:342)The modifier is cleanly dropped. No CSS rule ever matched it; the enclosing
.stats-cardsbase class is retained. Correct.Fix #2 — ginkgo BeforeEach/JustBeforeEach refactor (internal/stats/handler_internal_test.go)
The four
Describeblocks (buildCategoryDonutSlices,buildRatingDonutSlices,buildProgressDonutSlices,buildStatusDonutSlices) are correctly refactored: setup moves toBeforeEach, the SUT call moves toJustBeforeEach, and each property assertion gets its ownIt. All assertions are preserved — none are weakened or dropped. One added assertion:buildRatingDonutSlicesnow has an explicitIt("returns nil for all-zero book counts")that was previously only tested withToBeNilinline; it is correctly promoted. Refactor is sound.Fix #7 — empty-state guard expanded (templates/pages/library_stats.html:164 + handler_test.go)
Guard logic correctness. The old guard (
(not .Stats.Formats) and (not .Stats.Languages)) checked rawCollectionStatsfields, missing the three new chart fields. The new guard ((not .FormatSlices) and (not .LangSlices) and (not .MetadataSlices) and (not .PageCountBars) and (not .PublicationBars)) checks the computedpageDatafields used to drive each chart section. The chart-sectionor-gate at line 46 and the empty-stateand (not …)-gate at line 164 are exactly complementary — a populated chart suppresses the empty-state message and causes the chart section to render. Fix is logically correct.emptyStateTemplateFSguard string matches production template exactly — character-for-character verified.Test coverage of new fields. The new
Describe("GetHandler empty-state guard")block tests three of the five fields as individual "non-nil suppresses empty-state" cases (MetadataSlices, PageCountBars, PublicationBars — the genuinely new ones). FormatSlices and LangSlices are exercised in the existing populated-stats happy-path above. Coverage is adequate.Minor convention note. In the nil-slice
Contextblocks inside the existingDescribe("GetHandler"), theJustBeforeEachcallsExpect(json.NewDecoder(resp.Body).Decode(&out)).To(Succeed()). This places an assertion (Expect) insideJustBeforeEach, which is technically a setup step per project conventions (assertions belong inIt). Functionally this works correctly and the pattern is widely used in this codebase for decode-then-assert workflows. Not a blocker.[MINOR] internal/librarystats/handler_test.go —
Expectassertion insideJustBeforeEachfor JSON decodeJustBeforeEachis the action/invocation step; assertions belong inIt. TheExpect(json.NewDecoder(resp.Body).Decode(&out)).To(Succeed())call is an assertion (it fails the spec on decode error). Consider moving to aBeforeEachnested beneathJustBeforeEachor simply using a_, _ = json.Decode(…)+ anIt("decodes successfully")block. No correctness impact — purely a convention nit.REVIEW VERDICT: 0 blocker, 0 major, 1 minor
874d902c10109b910ec8