Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/__tests__/components/InterlinearNavContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function renderNav(hook: () => ScrollGroupTuple) {
*/
function renderNavMutable(initial: SerializedVerseRef) {
let current = initial;
const hook = (): ScrollGroupTuple => [current, () => {}, undefined, () => {}];
const hook = (): ScrollGroupTuple => [current, () => {}, undefined, () => {}, undefined];
const wrapper = ({ children }: { children: ReactNode }) => (
<InterlinearNavProvider useWebViewScrollGroupScrRef={hook}>{children}</InterlinearNavProvider>
);
Expand Down
15 changes: 8 additions & 7 deletions src/__tests__/components/Interlinearizer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Interlinearizer from '../../components/Interlinearizer';
import { InterlinearNavProvider } from '../../components/InterlinearNavContext';
import type { SegmentDisplayMode } from '../../components/SegmentView';
import { RECENTER_FADE_MS } from '../../components/recenter-fade';
import { defaultScrRef, GEN_1_1_BOOK } from '../test-helpers';
import { defaultScrRef, GEN_1_1_BOOK, type ScrollGroupTuple } from '../test-helpers';
import { allFalseViewOptions } from './test-helpers';

jest.mock('lucide-react', () => ({
Expand Down Expand Up @@ -366,12 +366,13 @@ const GEN_SUPERSCRIPTION_BOOK: Book = {
* @returns The element wrapped in a nav provider.
*/
function withNav(ui: ReactNode, navigate: (r: SerializedVerseRef) => void = () => {}): ReactNode {
const scrollGroupHook = (): [
SerializedVerseRef,
(r: SerializedVerseRef) => void,
number | undefined,
(id: number | undefined) => void,
] => [defaultScrRef, navigate, undefined, () => {}];
const scrollGroupHook = (): ScrollGroupTuple => [
defaultScrRef,
navigate,
undefined,
() => {},
undefined,
];
return (
<InterlinearNavProvider useWebViewScrollGroupScrRef={scrollGroupHook}>
{ui}
Expand Down
19 changes: 8 additions & 11 deletions src/__tests__/components/InterlinearizerLoader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import useOptimisticBooleanSetting from '../../hooks/useOptimisticBooleanSetting
import { emptyAnalysis, emptyDraft } from '../../types/empty-factories';
import type { PhraseMode } from '../../types/phrase-mode';
import type { ViewOptions } from '../../types/view-options';
import { GEN_1_1_BOOK, makeScrollGroupHook, makeWebViewState } from '../test-helpers';
import {
GEN_1_1_BOOK,
makeScrollGroupHook,
makeWebViewState,
type ScrollGroupTuple,
} from '../test-helpers';

jest.mock('../../hooks/useInterlinearizerBookData');
jest.mock('../../hooks/useOptimisticBooleanSetting');
Expand Down Expand Up @@ -1413,17 +1418,9 @@ describe('InterlinearizerLoader', () => {
*/
function makeMutableScrollGroupHook(
initial: SerializedVerseRef,
): [
() => [SerializedVerseRef, () => void, undefined, () => void],
(n: SerializedVerseRef) => void,
] {
): [() => ScrollGroupTuple, (n: SerializedVerseRef) => void] {
let current = initial;
const hook = (): [SerializedVerseRef, () => void, undefined, () => void] => [
current,
() => {},
undefined,
() => {},
];
const hook = (): ScrollGroupTuple => [current, () => {}, undefined, () => {}, undefined];
return [
hook,
(next) => {
Expand Down
15 changes: 8 additions & 7 deletions src/__tests__/interlinearizer.web-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { WebViewProps } from '@papi/core';
import type { SerializedVerseRef } from '@sillsdev/scripture';
import { render, screen } from '@testing-library/react';
import { defaultScrRef } from './test-helpers';
import { defaultScrRef, type ScrollGroupTuple } from './test-helpers';

jest.mock('../components/InterlinearizerLoader', () => ({
__esModule: true,
Expand Down Expand Up @@ -37,12 +37,13 @@ function makeProps(projectId?: string, scrRef: SerializedVerseRef = defaultScrRe
() => {},
() => {},
],
useWebViewScrollGroupScrRef: (): [
SerializedVerseRef,
(r: SerializedVerseRef) => void,
number | undefined,
(id: number | undefined) => void,
] => [scrRef, () => {}, undefined, () => {}],
useWebViewScrollGroupScrRef: (): ScrollGroupTuple => [
scrRef,
() => {},
undefined,
() => {},
undefined,
],
updateWebViewDefinition: () => true,
};
}
Expand Down
19 changes: 10 additions & 9 deletions src/__tests__/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @file Shared test helpers for unit and component tests. */
import type { SerializedVerseRef } from '@sillsdev/scripture';
import type { ExecutionActivationContext } from '@papi/core';
import type { ExecutionActivationContext, UseWebViewScrollGroupScrRefHook } from '@papi/core';
import type { Book, InterlinearProject, PhraseAnalysisLink, Token } from 'interlinearizer';
import { UnsubscriberAsyncList } from 'platform-bible-utils';
import type { PhraseStripContextValue } from '../components/PhraseStripContext';
Expand Down Expand Up @@ -94,13 +94,12 @@ export function makePhraseStripContext(
/** Genesis 1:1 serialized verse ref — shared across tests that need a default scroll position. */
export const defaultScrRef: SerializedVerseRef = { book: 'GEN', chapterNum: 1, verseNum: 1 };

/** Tuple shape returned by the PAPI scroll-group hook (`useWebViewScrollGroupScrRef`). */
export type ScrollGroupTuple = [
SerializedVerseRef,
(r: SerializedVerseRef) => void,
number | undefined,
(id: number | undefined) => void,
];
/**
* Tuple shape returned by the PAPI scroll-group hook (`useWebViewScrollGroupScrRef`). Aliased from
* the platform hook's own return type so it tracks the tuple's arity (e.g. the trailing
* `sourceProjectId` added by the host) rather than restating — and drifting from — it.
*/
export type ScrollGroupTuple = ReturnType<UseWebViewScrollGroupScrRefHook>;

/**
* Builds a `useWebViewScrollGroupScrRef` host-hook stub returning the given tuple parts. Every
Expand All @@ -110,15 +109,17 @@ export type ScrollGroupTuple = [
* @param setScrRef - The reference setter; defaults to a no-op.
* @param scrollGroupId - The active scroll-group id; defaults to `undefined` (unlinked).
* @param setScrollGroupId - The scroll-group setter; defaults to a no-op.
* @param sourceProjectId - The scroll group's source project id; defaults to `undefined`.
* @returns A hook returning the assembled tuple.
*/
export function makeScrollGroupHook(
ref: SerializedVerseRef = defaultScrRef,
setScrRef: (r: SerializedVerseRef) => void = () => {},
scrollGroupId: number | undefined = undefined,
setScrollGroupId: (id: number | undefined) => void = () => {},
sourceProjectId: string | undefined = undefined,
): () => ScrollGroupTuple {
return () => [ref, setScrRef, scrollGroupId, setScrollGroupId];
return () => [ref, setScrRef, scrollGroupId, setScrollGroupId, sourceProjectId];
}

/** Pre-built Book with one GEN 1:1 segment and a single word token. */
Expand Down
Loading