-
-
Notifications
You must be signed in to change notification settings - Fork 148
feat(client): localize card art to the UI language #7070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
client/src/components/deck-builder/__tests__/PrintingPickerModal.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { cleanup, render, screen, waitFor } from "@testing-library/react"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { PrintingPickerModal } from "../PrintingPickerModal"; | ||
| import { usePreferencesStore } from "../../../stores/preferencesStore.ts"; | ||
|
|
||
| // `vi.mock` is hoisted above the imports, so the fixture its factory closes over | ||
| // has to be hoisted too — a plain `const` would be in the temporal dead zone. | ||
| const { EN_ID, DE_ID, cardUrl } = vi.hoisted(() => { | ||
| const EN_ID = "0dbac7ce-a6fa-466e-b6ba-173cf2dec98e"; | ||
| const DE_ID = "345a1cf0-e4de-42a9-9c72-ed16826b9067"; | ||
| // Real five-segment `cards.scryfall.io` shape: a shorter URL is not | ||
| // localizable at all, so every assertion below would pass vacuously. | ||
| const cardUrl = (id: string) => | ||
| `https://cards.scryfall.io/normal/front/${id[0]}/${id[1]}/${id}.jpg`; | ||
| return { EN_ID, DE_ID, cardUrl }; | ||
| }); | ||
|
|
||
| // Only `getCardPrintings` is stubbed. The localization path under test — | ||
| // `resolvePrintingImageUrl`, `loadLocaleArt`, `isLocaleArtReady` — stays real and | ||
| // shares one module closure, so the map a load installs is the map a tile reads. | ||
| vi.mock("../../../services/scryfall.ts", async (importOriginal) => { | ||
| const actual = | ||
| await importOriginal<typeof import("../../../services/scryfall.ts")>(); | ||
| return { | ||
| ...actual, | ||
| getCardPrintings: vi.fn().mockResolvedValue([ | ||
| { | ||
| id: EN_ID, | ||
| set: "mid", | ||
| set_name: "Innistrad: Midnight Hunt", | ||
| collector_number: "7", | ||
| released_at: "2021-09-24", | ||
| border_color: "black", | ||
| frame_effects: [], | ||
| full_art: false, | ||
| faces: [{ normal: cardUrl(EN_ID), art_crop: cardUrl(EN_ID) }], | ||
| }, | ||
| ]), | ||
| }; | ||
| }); | ||
|
|
||
| describe("PrintingPickerModal localized art", () => { | ||
| afterEach(() => { | ||
| cleanup(); | ||
| vi.unstubAllGlobals(); | ||
| usePreferencesStore.getState().setLanguage("en"); | ||
| }); | ||
|
|
||
| it("swaps tile art when the locale map arrives after the modal mounts", async () => { | ||
| usePreferencesStore.getState().setLanguage("de"); | ||
|
|
||
| // Hold the locale map in flight so the modal is forced through the state | ||
| // this test exists for: mounted, localized language, no map yet. | ||
| let settle: ((r: Response) => void) | undefined; | ||
| vi.stubGlobal( | ||
| "fetch", | ||
| vi.fn( | ||
| () => | ||
| new Promise<Response>((resolve) => { | ||
| settle = resolve; | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| render( | ||
| <PrintingPickerModal cardName="Card" oracleId="oracle-1" onClose={() => {}} />, | ||
| ); | ||
|
|
||
| // Pending map: the tile renders English art rather than blocking on a | ||
| // fetch that may 404. This is also the reach guard for the swap below — | ||
| // without it, a tile that never rendered at all would satisfy the final | ||
| // assertion by never having been English in the first place. | ||
| const img = await screen.findByRole("img"); | ||
| expect(img).toHaveAttribute("src", cardUrl(EN_ID)); | ||
|
|
||
| settle!( | ||
| new Response(JSON.stringify({ [EN_ID]: DE_ID }), { | ||
| status: 200, | ||
| headers: { "Content-Type": "application/json" }, | ||
| }), | ||
| ); | ||
|
|
||
| // The picker resolves tile URLs during render, so arrival of the map is | ||
| // only visible if the component subscribed to it. Drop `useLocaleArt()` | ||
| // from the modal and this assertion fails on stale English art. | ||
| await waitFor(() => { | ||
| expect(screen.getByRole("img")).toHaveAttribute("src", cardUrl(DE_ID)); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Cache the AllSetFiles input after locale-map generation.
The
mtgjson-full-*cache is saved before this step. It cannot containAllSetFiles.tarorallsets/. Because GitHub Actions caches are immutable, later cache hits cannot add them. Each release then downloads and extracts the full MTGJSON archive again.Generate the maps before saving the MTGJSON cache and roll the cache key, or add a separate versioned cache for the AllSetFiles inputs.
🤖 Prompt for AI Agents