Skip to content

Test the language chooser -> Bloom data mapping - #8236

Merged
andrew-polk merged 1 commit into
masterfrom
language-chooser-data-mapping-tests
Aug 26, 2026
Merged

Test the language chooser -> Bloom data mapping#8236
andrew-polk merged 1 commit into
masterfrom
language-chooser-data-mapping-tests

Conversation

@andrew-polk

@andrew-polk andrew-polk commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Problem

Picking a language in the language chooser hands Bloom five things that cross from TypeScript into C#: the language tag, the name to show, whether the user renamed it, whether the script reads right-to-left, and the country. Neither side of that handoff had a single automated test.

It has not been quiet code. Three shipped bugs were defects in the TypeScript half alone — BL-15190 (choosing a script didn't change the name Bloom stored), BL-13982 (the right-to-left setting stopped surviving a restart) and BL-14426 (the C# side couldn't read the name field at all). A fourth defect of the same shape would have reached users the same way.

What the PR does

The TypeScript half. Moves getLanguageData() and ILanguageData, unchanged, out of LanguageChooserDialog.tsx into their own languageData.ts, so tests can reach the function without loading the dialog's MUI and bloomApi chain. The function body is byte-for-byte what it was. Adds 12 tests over the five fields — including the difference between "the script says left-to-right" and "the script didn't say", which is what BL-13982 turned on — plus 4 more pinning the corners where this function deliberately differs from EthnoLib's defaultDisplayName(language, script), so folding the two together has to be a decision rather than an accident.

The C# half. Bloom decides whether a name is the language's own or one the user typed by comparing DesiredName with DefaultName — written out inline, four times over, in the handlers for Language 1, 2, 3 and the sign language. That could not be tested as written; a test could only have re-implemented the comparison and asserted on itself. It now has a name, LanguageChangeEventArgs.IsCustomName, and all four sites call it. Behavior is unchanged, the duplication is gone, and 9 NUnit tests cover it.

PublishApi has its own, different rule for the same question, and this PR does not touch it — that divergence is described in the remarks on IsCustomName and pinned by two tests, so it cannot be unified by accident. Fixing it is BL-16760, in the PR stacked on this one.

Also records why the sign-language handler, unlike Language 1-3, does not apply args.IsRtl: a sign language has no text direction.

Every production change here is behavior-preserving.

Devin review


This change is Reviewable

@andrew-polk

Copy link
Copy Markdown
Contributor Author

(Claude Opus 5 (1M context)) Consulted Devin on 2026-08-26 04:59 UTC up to commit cca9bc19496896891d426c4fb78348b9aa999ec2.

Clean: no bugs, no investigate flags, no informational items.

@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR extracts the language-chooser data mapping into a directly testable module and centralizes the existing C# custom-name comparison without changing its behavior.

  • Adds TypeScript coverage for language tags, names, text direction, and country mapping.
  • Adds NUnit coverage for custom-name classification and its intentional difference from PublishApi.
  • Rewires both chooser entry points to the extracted mapping module.

Important Files Changed

Filename Overview
src/BloomBrowserUI/collection/languageData.ts Extracts the existing language-selection mapping unchanged into a standalone module.
src/BloomBrowserUI/collection/languageData.test.ts Adds focused Vitest coverage for all serialized language-data fields and documented edge cases.
src/BloomExe/web/controllers/LanguageChangeEventArgs.cs Introduces an IsCustomName property equivalent to the previously repeated string comparison.
src/BloomExe/Collection/CollectionSettingsDialog.cs Replaces four equivalent inline custom-name comparisons with the shared property.
src/BloomTests/web/controllers/LanguageChangeEventArgsTests.cs Adds NUnit coverage for custom-name classification and the intentionally distinct PublishApi rule.

Reviews (2): Last reviewed commit: "Test the language chooser -> Bloom data ..." | Re-trigger Greptile

@andrew-polk

Copy link
Copy Markdown
Contributor Author

(Claude Opus 5 (1M context)) Consulted Devin on 2026-08-26 up to commit 0b4f608eb14443b02b78740930b2cdbacd6cd1a5 (adds the C# custom-name coverage).

No bugs, no investigate flags. Two informational items, both confirming rather than questioning the change: that the C# IsCustomName extraction is behavior-preserving, and that getLanguageData moved without change. Neither mirrored as a review thread (informational items are low signal).

Note: pr-automation and Greptile did not register for this push — GitHub was having problems at the time — so Devin was triggered manually via its review page.

getLanguageData() is the single point where everything the EthnoLib language
chooser knows about a selection crosses into Bloom's C# side: the language tag,
the name to display, whether the user renamed it, whether the script reads
right-to-left, and the country. Three shipped bugs -- BL-15190, BL-13982 and
BL-14426 -- were all defects in this one function, and it had no automated test
of any kind.

Move getLanguageData() and ILanguageData, unchanged, out of
LanguageChooserDialog.tsx into their own collection/languageData.ts, so tests
can reach the function without loading the dialog's MUI and bloomApi chain. The
interface and the function body are byte-for-byte what they were.

Add 16 vitest tests. Twelve cover the five fields the C# side receives --
including the difference between "the script says left-to-right" and "the script
didn't say", which is what BL-13982 turned on. The other four pin the corners
where this function deliberately differs from EthnoLib's
defaultDisplayName(language, script), which is the obvious thing to replace it
with: that returns "" for the unlisted language and for manually-entered-tag
languages even when a script is supplied. Nothing reachable depends on the
difference today, so those tests exist to make folding the two together a
deliberate decision rather than a silent behavior change.

On the C# side, the rule for "did the user type this name or accept the offered
one?" was written out inline, four times over, in CollectionSettingsDialog's
handlers for Language 1, 2, 3 and the sign language. It could not be tested as
written -- a test could only have re-implemented the comparison and asserted on
itself. It now has a name, LanguageChangeEventArgs.IsCustomName, and all four
sites call it. Behavior is unchanged; 9 NUnit tests cover it.

Also record why the sign-language handler, unlike Language 1-3, does not apply
args.IsRtl: a sign language has no text direction.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@andrew-polk
andrew-polk force-pushed the language-chooser-data-mapping-tests branch from a954e61 to 7a195de Compare August 26, 2026 20:39
@andrew-polk
andrew-polk marked this pull request as ready for review August 26, 2026 21:13
@andrew-polk
andrew-polk merged commit eca813d into master Aug 26, 2026
2 checks passed
@andrew-polk
andrew-polk deleted the language-chooser-data-mapping-tests branch August 26, 2026 21:13
andrew-polk added a commit that referenced this pull request Aug 26, 2026
…g-tests

Test the language chooser -> Bloom data mapping
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