diff --git a/apps/mobile/__tests__/components/habits/habit-row.test.tsx b/apps/mobile/__tests__/components/habits/habit-row.test.tsx new file mode 100644 index 0000000000..7906a5b45c --- /dev/null +++ b/apps/mobile/__tests__/components/habits/habit-row.test.tsx @@ -0,0 +1,71 @@ +import { describe, it, expect, vi } from 'vitest' +import { createMockHabit } from '@orbit/shared/__tests__/factories' +import { HabitRow } from '@/components/habits/habit-row' + +const TestRenderer = require('react-test-renderer') + +vi.mock('react-i18next', () => ({ + useTranslation: () => ({ t: (key: string) => key, i18n: { language: 'en' } }), +})) + +vi.mock('@/hooks/use-time-format', () => ({ + useTimeFormat: () => ({ displayTime: (value: string) => value }), +})) + +vi.mock('@/lib/use-app-theme', () => ({ + useAppTheme: () => ({ currentScheme: 'purple', currentTheme: 'dark' }), +})) + +vi.mock('@/lib/motion', () => ({ + usePrefersReducedMotion: () => true, +})) + +function collectStrings(node: unknown): string[] { + if (node == null) return [] + if (typeof node === 'string') return [node] + if (Array.isArray(node)) return node.flatMap(collectStrings) + return collectStrings((node as { children?: unknown }).children) +} + +function renderRowText(habit: ReturnType): string[] { + let tree: { toJSON: () => unknown } + TestRenderer.act(() => { + tree = TestRenderer.create() + }) + return collectStrings(tree!.toJSON()) +} + +describe('HabitRow tags (mobile)', () => { + it('renders the habit tag names on the row', () => { + const texts = renderRowText( + createMockHabit({ + title: 'Read', + tags: [ + { id: '1', name: 'Learning', color: '#7c3aed' }, + { id: '2', name: 'Evening', color: '#10b981' }, + ], + }), + ) + + expect(texts).toContain('Learning') + expect(texts).toContain('Evening') + }) + + it('caps visible tags at three and shows a +N overflow counter', () => { + const texts = renderRowText( + createMockHabit({ + title: 'Read', + tags: Array.from({ length: 10 }, (_, i) => ({ + id: String(i), + name: `Tag${i}`, + color: '#7c3aed', + })), + }), + ) + + expect(texts).toContain('Tag0') + expect(texts).toContain('Tag2') + expect(texts).not.toContain('Tag3') + expect(texts.join('')).toContain('+7') + }) +}) diff --git a/apps/mobile/components/habits/habit-detail-drawer.tsx b/apps/mobile/components/habits/habit-detail-drawer.tsx index b511faa516..4481f34079 100644 --- a/apps/mobile/components/habits/habit-detail-drawer.tsx +++ b/apps/mobile/components/habits/habit-detail-drawer.tsx @@ -141,7 +141,7 @@ function HabitDetailContent({ showsVerticalScrollIndicator={false} keyboardShouldPersistTaps="always" > - {habit.emoji || summaryStrip ? ( + {habit.emoji || summaryStrip || habit.tags.length > 0 ? ( {habit.emoji ? ( ) : null} + {habit.tags.length > 0 ? ( + + {habit.tags.map((tag) => ( + + + + {tag.name} + + + ))} + + ) : null} ) : null} @@ -468,6 +480,27 @@ function createStyles(tokens: ReturnType) { paddingTop: 8, paddingBottom: 16, }, + drawerTagRow: { + flexDirection: 'row', + flexWrap: 'wrap', + justifyContent: 'center', + alignItems: 'center', + gap: 8, + }, + drawerTagChip: { + flexDirection: 'row', + alignItems: 'center', + gap: 5, + }, + drawerTagDot: { + width: 6, + height: 6, + borderRadius: 3, + }, + drawerTagName: { + fontFamily: 'Rubik_400Regular', + fontSize: 13, + }, emojiWell: { width: 76, height: 76, diff --git a/apps/mobile/components/habits/habit-row.tsx b/apps/mobile/components/habits/habit-row.tsx index 9fb4c51c40..93a226cb4e 100644 --- a/apps/mobile/components/habits/habit-row.tsx +++ b/apps/mobile/components/habits/habit-row.tsx @@ -47,6 +47,8 @@ import { ParentRing } from '@/components/ui/parent-ring' import { SelectCheck } from '@/components/ui/select-check' import type { StatusDotState } from '@/components/ui/status-dot' +const MAX_VISIBLE_TAGS = 3 + /** * Action callbacks consumed by HabitRow. */ @@ -439,6 +441,24 @@ function HabitRowContent({ ) : null} ) : null} + + {habit.tags.length > 0 ? ( + + {habit.tags.slice(0, MAX_VISIBLE_TAGS).map((tag) => ( + + + + {tag.name} + + + ))} + {habit.tags.length > MAX_VISIBLE_TAGS ? ( + + +{habit.tags.length - MAX_VISIBLE_TAGS} + + ) : null} + + ) : null} ) } @@ -827,6 +847,34 @@ const styles = StyleSheet.create({ fontSize: 13, lineHeight: 17, }, + tagRow: { + flexDirection: 'row', + alignItems: 'center', + gap: 8, + marginTop: 1, + overflow: 'hidden', + }, + tagChip: { + flexDirection: 'row', + alignItems: 'center', + gap: 5, + flexShrink: 0, + }, + tagDot: { + width: 6, + height: 6, + borderRadius: 3, + }, + tagName: { + fontFamily: 'Rubik_400Regular', + fontSize: 12, + maxWidth: 96, + }, + tagOverflow: { + fontFamily: 'Roboto_400Regular', + fontSize: 12, + flexShrink: 0, + }, trailing: { flexDirection: 'row', alignItems: 'center', diff --git a/apps/web/__tests__/components/habits/habit-detail-drawer.test.tsx b/apps/web/__tests__/components/habits/habit-detail-drawer.test.tsx index 01f0ac1658..0031df1286 100644 --- a/apps/web/__tests__/components/habits/habit-detail-drawer.test.tsx +++ b/apps/web/__tests__/components/habits/habit-detail-drawer.test.tsx @@ -63,11 +63,13 @@ vi.mock('@/components/ui/app-overlay', () => ({ open, children, title, + titleContent, footer, }: { open: boolean children: React.ReactNode title?: string + titleContent?: React.ReactNode description?: string footer?: React.ReactNode expandable?: boolean @@ -75,7 +77,7 @@ vi.mock('@/components/ui/app-overlay', () => ({ }) => open ? (
- {title &&

{title}

} + {(titleContent || title) &&

{titleContent || title}

} {children} {footer}
@@ -197,6 +199,24 @@ describe('HabitDetailDrawer', () => { expect(screen.getByText('Exercise')).toBeDefined() }) + it('renders the habit tags in the detail header', () => { + render( + , + ) + expect(screen.getByText('Learning')).toBeDefined() + expect(screen.getByText('Evening')).toBeDefined() + }) + it('shows due time when habit has dueTime', () => { render( { expect(screen.getByText('Child preview')).toBeDefined() }) }) + +describe('HabitRow tags', () => { + it('renders the habit tag names on the row', () => { + render( + , + ) + + expect(screen.getByText('Learning')).toBeDefined() + expect(screen.getByText('Evening')).toBeDefined() + }) + + it('caps visible tags at three and shows a +N overflow counter for the rest', () => { + render( + ({ + id: String(i), + name: `Tag${i}`, + color: '#7c3aed', + })), + })} + />, + ) + + expect(screen.getByText('Tag0')).toBeDefined() + expect(screen.getByText('Tag1')).toBeDefined() + expect(screen.getByText('Tag2')).toBeDefined() + expect(screen.queryByText('Tag3')).toBeNull() + expect(screen.getByText('+7')).toBeDefined() + }) +}) diff --git a/apps/web/components/habits/habit-detail-drawer.tsx b/apps/web/components/habits/habit-detail-drawer.tsx index 6583862081..288702c9da 100644 --- a/apps/web/components/habits/habit-detail-drawer.tsx +++ b/apps/web/components/habits/habit-detail-drawer.tsx @@ -181,6 +181,29 @@ export function HabitDetailDrawer({ {summaryStrip} ) : null} + {habit.tags.length > 0 ? ( + + {habit.tags.map((tag) => ( + + + ))} + + ) : null} ) : undefined } diff --git a/apps/web/components/habits/habit-row.tsx b/apps/web/components/habits/habit-row.tsx index c3c5f6aa0f..edeae7516f 100644 --- a/apps/web/components/habits/habit-row.tsx +++ b/apps/web/components/habits/habit-row.tsx @@ -23,6 +23,8 @@ import { Popover } from '@/components/ui/popover' import { SelectCheck } from '@/components/ui/select-check' import type { StatusDotState } from '@/components/ui/status-dot' +const MAX_VISIBLE_TAGS = 3 + /** Action callbacks consumed by HabitRow. Mirrors the mobile shape so that * cross-platform call sites can pass the same handler bag. */ export interface HabitRowActions { @@ -277,6 +279,47 @@ export function HabitRow({ )} )} + {habit.tags.length > 0 && ( + + {habit.tags.slice(0, MAX_VISIBLE_TAGS).map((tag) => ( + + + ))} + {habit.tags.length > MAX_VISIBLE_TAGS && ( + + +{habit.tags.length - MAX_VISIBLE_TAGS} + + )} + + )}