Repository navigation
fix: studio skip reason i18n #320
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
Changes from all commits
0cb13b7
368b47f
9c5849a
f59ff6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react' | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
|
|
||
| const post = vi.hoisted(() => vi.fn()) | ||
| const toast = vi.hoisted(() => ({ info: vi.fn(), success: vi.fn(), error: vi.fn() })) | ||
|
|
||
| vi.mock('@/lib/api', () => ({ api: { post }, getErrorMessage: (_: unknown, fallback: string) => fallback })) | ||
| vi.mock('sonner', () => ({ toast })) | ||
| // The global next-intl mock drops the namespace and ICU values, so this one keeps both to | ||
| // prove each label comes from the catalogs rather than from raw values. | ||
| vi.mock('next-intl', () => ({ | ||
| useLocale: () => 'en', | ||
| useFormatter: () => ({ | ||
| number: (value: number) => String(value), | ||
| list: (items: string[]) => items.join(', '), | ||
| }), | ||
| useTranslations: (namespace: string) => { | ||
| const t = (key: string, values?: Record<string, unknown>) => | ||
| `${namespace}.${key}${values ? ` ${JSON.stringify(values)}` : ''}` | ||
| t.raw = t | ||
| t.rich = t | ||
| t.markup = t | ||
| t.has = () => true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Unknown type expects a nonexistent translation When the test is meant to verify the label produced with the real catalog, when Use a type present in the catalog for the translation assertion, or assert the readable fallback for Prompt for AI agentsIn `frontend/tests/studio-panels-i18n.test.tsx` at line 23:
**Unknown type expects a nonexistent translation**
When the test is meant to verify the label produced with the real catalog, when `kimono` is absent from the real English type catalog, `useCatalogLabel` correctly falls back to `Kimono`, but this mock forces `t.has` to return true and fabricates `constants.types.kimono`, so the CanvasPanel assertion passes with output the real catalog would not produce.
Use a type present in the catalog for the translation assertion, or assert the readable fallback for `kimono` and make the mock's `has` reflect catalog membership. |
||
| return t | ||
| }, | ||
| })) | ||
|
|
||
| import { CanvasPanel } from '@/components/studio/canvas-panel' | ||
| import { DetailsPanel } from '@/components/studio/details-panel' | ||
| import type { StudioItem } from '@/lib/studio/editor-state' | ||
|
|
||
| function studioItem(id: string, type: string, name: string | null = null): StudioItem { | ||
| return { id, type, name, thumbnail_url: null, image_url: null, primary_color: 'blue' } | ||
| } | ||
|
|
||
| function assistWith(canvas: StudioItem[], suggested: StudioItem[]) { | ||
| post.mockResolvedValue({ items: suggested }) | ||
| render( | ||
| <DetailsPanel | ||
| items={canvas} | ||
| name="" | ||
| occasion="casual" | ||
| onNameChange={vi.fn()} | ||
| onOccasionChange={vi.fn()} | ||
| onAiMerge={vi.fn()} | ||
| /> | ||
| ) | ||
| fireEvent.click(screen.getByText('outfits.details.letAiFinish')) | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| describe('DetailsPanel AI assist', () => { | ||
| it('names the canvas piece that already fills the spot', async () => { | ||
| assistWith([studioItem('1', 'shirt', 'Shirt')], [studioItem('2', 't-shirt', 'Tee')]) | ||
| await waitFor(() => | ||
| expect(toast.info).toHaveBeenCalledWith( | ||
| 'outfits.details.skippedItem {"name":"Tee","other":"Shirt"}' | ||
| ) | ||
| ) | ||
| }) | ||
|
|
||
| it('falls back to translated type labels for unnamed pieces', async () => { | ||
| assistWith([studioItem('1', 'dress')], [studioItem('2', 'shirt')]) | ||
| await waitFor(() => | ||
| expect(toast.info).toHaveBeenCalledWith( | ||
| 'outfits.details.skippedItem {"name":"constants.types.shirt","other":"constants.types.dress"}' | ||
| ) | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe('CanvasPanel', () => { | ||
| it('labels a type without a role through the type catalog', () => { | ||
| const kimono = { ...studioItem('1', 'kimono', 'Kimono'), thumbnail_url: '/kimono.jpg' } | ||
| render(<CanvasPanel items={[kimono]} onRemove={vi.fn()} />) | ||
| expect(screen.getByText('constants.types.kimono')).toBeTruthy() | ||
| expect(screen.queryByText('kimono')).toBeNull() | ||
| }) | ||
| }) | ||
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.
🟡 Medium · Unknown types stay in English
When a canvas or studio item has a type with no matching catalog entry,
typeLabelcallsuseCatalogLabel, which falls back to title-cased raw text for an absent type, so the item label remains in English instead of the current locale.Provide a localized fallback for types that are absent from the catalog instead of displaying humanized raw text.
Also at
frontend/tests/studio-panels-i18n.test.tsx:24.Prompt for AI agents