Skip to content

Commit 75c422f

Browse files
authored
Remove Scripture nav controls for "simple" UI (#75)
1 parent 103d275 commit 75c422f

4 files changed

Lines changed: 46 additions & 12 deletions

File tree

__mocks__/papi-frontend-react.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ const useLocalizedStrings = jest.fn().mockImplementation((keys: string[]) => [
6262
false,
6363
]);
6464

65+
/**
66+
* Mock for `useSetting`. Returns `[defaultState, setSetting, resetSetting, false]`, passing
67+
* `defaultState` through unchanged so callers receive a predictable initial value.
68+
*
69+
* @param _key - Ignored setting key.
70+
* @param defaultState - Value surfaced as the current setting state.
71+
* @returns Tuple of `[defaultState, jest.fn(), jest.fn(), false]`.
72+
*/
73+
const useSetting = jest
74+
.fn()
75+
.mockImplementation((_key: string, defaultState: unknown) => [
76+
defaultState,
77+
jest.fn(),
78+
jest.fn(),
79+
false,
80+
]);
81+
6582
/**
6683
* Mock for `useRecentScriptureRefs`. Returns an empty history and a no-op `addRecentScriptureRef`
6784
* so components that display recent references render without errors.
@@ -76,6 +93,7 @@ module.exports = {
7693
__esModule: true,
7794
useProjectData,
7895
useProjectSetting,
96+
useSetting,
7997
useLocalizedStrings,
8098
useRecentScriptureRefs,
8199
};

__mocks__/platform-bible-react.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* @file Jest mock for platform-bible-react. The real package ships ESM which Jest cannot parse
3-
* without extra transform configuration. This stub provides the subset used by extension
4-
* components: `BookChapterControl`, `BOOK_CHAPTER_CONTROL_STRING_KEYS`, `TabToolbar`, and
5-
* `ScrollGroupSelector`.
3+
* without extra transform configuration. This stub provides the subset used by the extension.
64
*/
75

86
import type { ReactElement, ReactNode } from 'react';

src/__tests__/components/InterlinearizerLoader.test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference types="jest" />
33
/// <reference types="@testing-library/jest-dom" />
44

5-
import { useLocalizedStrings } from '@papi/frontend/react';
5+
import { useLocalizedStrings, useSetting } from '@papi/frontend/react';
66
import type { SerializedVerseRef } from '@sillsdev/scripture';
77
import { render, screen } from '@testing-library/react';
88
import userEvent from '@testing-library/user-event';
@@ -134,9 +134,11 @@ describe('InterlinearizerLoader', () => {
134134
mockBookData();
135135
mockOptimisticSetting();
136136
jest.mocked(useLocalizedStrings).mockReturnValue([{}, false]);
137+
jest.mocked(useSetting).mockReturnValue(['simple', jest.fn(), jest.fn(), false]);
137138
});
138139

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

153+
it('hides nav controls when interface mode is simple', () => {
154+
render(
155+
<InterlinearizerLoader
156+
projectId={testProjectId}
157+
useWebViewScrollGroupScrRef={makeScrollGroupHook()}
158+
/>,
159+
);
160+
161+
expect(screen.queryByTestId('scripture-nav-controls')).not.toBeInTheDocument();
162+
expect(screen.getByTestId('interlinearizer')).toBeInTheDocument();
163+
});
164+
151165
it('shows Loading when book data has not arrived', () => {
152166
mockBookData({ book: undefined, isLoading: true });
153167
render(

src/components/InterlinearizerLoader.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { UseWebViewScrollGroupScrRefHook } from '@papi/core';
2-
import { useLocalizedStrings } from '@papi/frontend/react';
2+
import { useLocalizedStrings, useSetting } from '@papi/frontend/react';
33
import { TabToolbar } from 'platform-bible-react';
44
import { useMemo } from 'react';
55
import ContinuousScrollToggle from './ContinuousScrollToggle';
@@ -29,6 +29,8 @@ export default function InterlinearizerLoader({
2929
}>) {
3030
const [scrRef, setScrRef, scrollGroupId, setScrollGroupId] = useWebViewScrollGroupScrRef();
3131

32+
const [interfaceMode] = useSetting('platform.interfaceMode', 'simple');
33+
3234
const {
3335
isLoading: isSettingLoading,
3436
onChange: handleContinuousScrollChange,
@@ -51,12 +53,14 @@ export default function InterlinearizerLoader({
5153
<TabToolbar
5254
className="tw:z-10"
5355
startAreaChildren={
54-
<ScriptureNavControls
55-
scrRef={scrRef}
56-
handleSubmit={setScrRef}
57-
scrollGroupId={scrollGroupId}
58-
onChangeScrollGroupId={setScrollGroupId}
59-
/>
56+
interfaceMode === 'power' ? (
57+
<ScriptureNavControls
58+
scrRef={scrRef}
59+
handleSubmit={setScrRef}
60+
scrollGroupId={scrollGroupId}
61+
onChangeScrollGroupId={setScrollGroupId}
62+
/>
63+
) : undefined
6064
}
6165
endAreaChildren={
6266
<ContinuousScrollToggle

0 commit comments

Comments
 (0)