Skip to content
Closed
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": patch
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cameronapak Should this be a patch?

---
Add optional `onFootnotePress` callback to `BibleCard` for custom footnote handling (same pattern as `BibleReader`).
49 changes: 48 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,48 @@ 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');
});
});
5 changes: 4 additions & 1 deletion packages/ui/src/components/bible-card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { usePassage, useVersion, useTheme } from '@youversion/platform-react-hooks';
import { BibleTextView } from './verse';
import { BibleTextView, type FootnoteData } from './verse';
import { BibleAppLogoLockup } from './bible-app-logo-lockup';
import { BibleVersionPicker } from './bible-version-picker';
import { Button } from './ui/button';
Expand Down Expand Up @@ -32,6 +32,7 @@ export type BibleCardProps = {
versionId: number;
background?: 'light' | 'dark';
showVersionPicker?: boolean;
onFootnotePress?: (data: FootnoteData) => void;
};

function BibleCardHeaderError(): React.ReactNode {
Expand Down Expand Up @@ -116,6 +117,7 @@ export function BibleCard({
versionId,
background,
showVersionPicker = false,
onFootnotePress,
}: BibleCardProps): React.ReactNode {
const [versionNum, setVersionNum] = useState(versionId);
const { version } = useVersion(versionNum);
Expand Down Expand Up @@ -177,6 +179,7 @@ export function BibleCard({
loading: passageLoading,
error: passageError,
}}
onFootnotePress={onFootnotePress}
/>
</AnimatedHeight>

Expand Down
Loading