Skip to content
Draft
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
18 changes: 18 additions & 0 deletions __mocks__/papi-frontend-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ const useLocalizedStrings = jest.fn().mockImplementation((keys: string[]) => [
false,
]);

/**
* Mock for `useSetting`. Returns `[defaultState, setSetting, resetSetting, false]`, passing
* `defaultState` through unchanged so callers receive a predictable initial value.
*
* @param _key - Ignored setting key.
* @param defaultState - Value surfaced as the current setting state.
* @returns Tuple of `[defaultState, jest.fn(), jest.fn(), false]`.
*/
const useSetting = jest
.fn()
.mockImplementation((_key: string, defaultState: unknown) => [
defaultState,
jest.fn(),
jest.fn(),
false,
]);

/**
* Mock for `useRecentScriptureRefs`. Returns an empty history and a no-op `addRecentScriptureRef`
* so components that display recent references render without errors.
Expand All @@ -76,6 +93,7 @@ module.exports = {
__esModule: true,
useProjectData,
useProjectSetting,
useSetting,
useLocalizedStrings,
useRecentScriptureRefs,
};
Expand Down
4 changes: 1 addition & 3 deletions __mocks__/platform-bible-react.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* @file Jest mock for platform-bible-react. The real package ships ESM which Jest cannot parse
* without extra transform configuration. This stub provides the subset used by extension
* components: `BookChapterControl`, `BOOK_CHAPTER_CONTROL_STRING_KEYS`, `TabToolbar`, and
* `ScrollGroupSelector`.
* without extra transform configuration. This stub provides the subset used by the extension.
*/

import type { ReactElement, ReactNode } from 'react';
Expand Down
18 changes: 16 additions & 2 deletions src/__tests__/components/InterlinearizerLoader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference types="jest" />
/// <reference types="@testing-library/jest-dom" />

import { useLocalizedStrings } from '@papi/frontend/react';
import { useLocalizedStrings, useSetting } from '@papi/frontend/react';
import type { SerializedVerseRef } from '@sillsdev/scripture';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -134,9 +134,11 @@ describe('InterlinearizerLoader', () => {
mockBookData();
mockOptimisticSetting();
jest.mocked(useLocalizedStrings).mockReturnValue([{}, false]);
jest.mocked(useSetting).mockReturnValue(['simple', jest.fn(), jest.fn(), false]);
});

it('renders Interlinearizer and the nav controls when book data is available', () => {
it('shows nav controls when interface mode is power', () => {
jest.mocked(useSetting).mockReturnValue(['power', jest.fn(), jest.fn(), false]);
render(
<InterlinearizerLoader
projectId={testProjectId}
Expand All @@ -148,6 +150,18 @@ describe('InterlinearizerLoader', () => {
expect(screen.getByTestId('interlinearizer')).toBeInTheDocument();
});

it('hides nav controls when interface mode is simple', () => {
render(
<InterlinearizerLoader
projectId={testProjectId}
useWebViewScrollGroupScrRef={makeScrollGroupHook()}
/>,
);

expect(screen.queryByTestId('scripture-nav-controls')).not.toBeInTheDocument();
expect(screen.getByTestId('interlinearizer')).toBeInTheDocument();
});

it('shows Loading when book data has not arrived', () => {
mockBookData({ book: undefined, isLoading: true });
render(
Expand Down
18 changes: 11 additions & 7 deletions src/components/InterlinearizerLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { UseWebViewScrollGroupScrRefHook } from '@papi/core';
import { useLocalizedStrings } from '@papi/frontend/react';
import { useLocalizedStrings, useSetting } from '@papi/frontend/react';
import { TabToolbar } from 'platform-bible-react';
import { useMemo } from 'react';
import ContinuousScrollToggle from './ContinuousScrollToggle';
Expand Down Expand Up @@ -29,6 +29,8 @@ export default function InterlinearizerLoader({
}>) {
const [scrRef, setScrRef, scrollGroupId, setScrollGroupId] = useWebViewScrollGroupScrRef();

const [interfaceMode] = useSetting('platform.interfaceMode', 'simple');

const {
isLoading: isSettingLoading,
onChange: handleContinuousScrollChange,
Expand All @@ -51,12 +53,14 @@ export default function InterlinearizerLoader({
<TabToolbar
className="tw:z-10"
startAreaChildren={
<ScriptureNavControls
scrRef={scrRef}
handleSubmit={setScrRef}
scrollGroupId={scrollGroupId}
onChangeScrollGroupId={setScrollGroupId}
/>
interfaceMode === 'power' ? (
<ScriptureNavControls
scrRef={scrRef}
handleSubmit={setScrRef}
scrollGroupId={scrollGroupId}
onChangeScrollGroupId={setScrollGroupId}
/>
) : undefined
}
endAreaChildren={
<ContinuousScrollToggle
Expand Down
Loading