Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/bible-card-footnote-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@youversion/platform-react-ui": minor
---
Comment thread
Dustin-Kelley marked this conversation as resolved.
Add optional `onFootnotePress` callback to `BibleCard` for custom footnote handling (same pattern as `BibleReader`).
51 changes: 50 additions & 1 deletion packages/ui/src/components/bible-card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
* @vitest-environment jsdom
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { render, act, within } from '@testing-library/react';
import { render, act, within, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { BibleCard } from './bible-card';
import type { FootnoteData } from './verse';
import { usePassage, useVersion, useTheme } from '@youversion/platform-react-hooks';
import type { BiblePassage, BibleVersion } from '@youversion/platform-core';

Expand Down Expand Up @@ -119,3 +121,50 @@ describe('BibleCard - Delayed spinner', () => {
);
});
});

describe('BibleCard - onFootnotePress callback', () => {
const mockPassageWithFootnote: BiblePassage = {
id: 'JHN.1',
content: `<div class="p"><span class="yv-v" v="5"></span><span class="yv-vlbl">5</span>The light shines<span class="yv-n f"><span class="fr">1:5 </span><span class="ft">Or understood</span></span>.</div>`,
reference: 'JHN.1',
};

beforeEach(() => {
vi.mocked(useTheme).mockReturnValue('light');
vi.mocked(useVersion).mockReturnValue({
version: mockVersion,
loading: false,
error: null,
refetch: vi.fn(),
});
vi.mocked(usePassage).mockReturnValue({
passage: mockPassageWithFootnote,
loading: false,
error: null,
refetch: vi.fn(),
});
});

it('should call onFootnotePress when provided via BibleCard', async () => {
const onFootnotePress = vi.fn();

const { container } = render(
<BibleCard reference="JHN.1" versionId={3034} onFootnotePress={onFootnotePress} />,
);

const button = await waitFor(() => {
const btn = container.querySelector('[data-verse-footnote="5"] button');
expect(btn).not.toBeNull();
return btn as HTMLButtonElement;
});

await userEvent.click(button);

expect(onFootnotePress).toHaveBeenCalledTimes(1);
const data = onFootnotePress.mock.calls[0]![0] as FootnoteData;
expect(data.verseNum).toBe('5');
expect(data.reference).toBe('JHN.1');
Comment thread
greptile-apps[bot] marked this conversation as resolved.
expect(data.notes).toHaveLength(1);
expect(data.notes[0]).toContain('Or understood');
});
});
5 changes: 4 additions & 1 deletion packages/ui/src/components/bible-card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { usePassage, useVersion, useTheme } from '@youversion/platform-react-hooks';
import { DEFAULT_LICENSE_FREE_BIBLE_VERSION } from '@youversion/platform-core';
import { BibleTextView } from './verse';
import { BibleTextView, type FootnoteData } from './verse';
import { BibleAppLogoLockup } from './bible-app-logo-lockup';
import { BibleVersionPicker, type BibleVersionPickerPressData } from './bible-version-picker';
import { Button } from './ui/button';
Expand Down Expand Up @@ -37,6 +37,7 @@ export type BibleCardProps = {
background?: 'light' | 'dark';
showVersionPicker?: boolean;
onVersionPickerPress?: (data: BibleVersionPickerPressData) => void;
onFootnotePress?: (data: FootnoteData) => void;
};

function BibleCardHeaderError(): React.ReactNode {
Expand Down Expand Up @@ -127,6 +128,7 @@ export function BibleCard({
background,
showVersionPicker = false,
onVersionPickerPress,
onFootnotePress,
}: BibleCardProps): React.ReactNode {
// Controlled only when both versionId + onVersionChange are provided.
// versionId alone seeds uncontrolled state, preserving backwards compatibility
Expand Down Expand Up @@ -198,6 +200,7 @@ export function BibleCard({
loading: passageLoading,
error: passageError,
}}
onFootnotePress={onFootnotePress}
/>
</AnimatedHeight>

Expand Down
Loading