Skip to content

Commit d7f790d

Browse files
author
Greg Trihus
committed
TT-6814-17, TT-6428 Add Phrase Back Translation mobile layout
- Introduced Cypress component testing takeaways to guide best practices in testing setups and assertions. - Added Jest testing takeaways for unit tests, emphasizing mocking strategies and edge case coverage. - Refactored MediaRecord, WSAudioPlayer, and related components to improve props handling and mobile responsiveness. - Updated UserMenu and PlanTabs components to utilize new mobile utility functions for better layout management. - feedback fixes
1 parent 8e80934 commit d7f790d

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

src/renderer/src/components/PassageDetail/mobile/PassageDetailMobileContext.cy.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,22 @@ describe('PassageDetailMobileContext', () => {
176176
});
177177

178178
it('falls back to book code when book data is missing', () => {
179+
const baseAttributes = createPassageDetailState().passage.attributes;
179180
mountContext({
180181
bookDataOverrides: [],
181182
passageOverrides: {
182-
attributes: { book: 'EXO', reference: '2:3' },
183+
attributes: { ...baseAttributes, book: 'EXO', reference: '2:3' },
183184
},
184185
});
185186

186187
cy.contains('EXO 2:3').should('be.visible');
187188
});
188189

189190
it('renders empty reference when passage reference is missing', () => {
191+
const baseAttributes = createPassageDetailState().passage.attributes;
190192
mountContext({
191193
passageOverrides: {
192-
attributes: { book: '', reference: '' },
194+
attributes: { ...baseAttributes, book: '', reference: '' },
193195
},
194196
});
195197

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react';
2+
import { ThemeProvider, createTheme } from '@mui/material/styles';
3+
import PassageDetailMobileLayout from './PassageDetailMobileLayout';
4+
5+
const mountLayout = ({
6+
withFooterAbove = false,
7+
contentSx,
8+
}: {
9+
withFooterAbove?: boolean;
10+
contentSx?: Record<string, unknown>;
11+
} = {}) => {
12+
const theme = createTheme();
13+
cy.mount(
14+
<ThemeProvider theme={theme}>
15+
<PassageDetailMobileLayout
16+
header={<div data-cy="layout-header">Header</div>}
17+
footer={<div data-cy="layout-footer">Footer</div>}
18+
footerAbove={
19+
withFooterAbove ? (
20+
<div data-cy="layout-footer-above">Footer Above</div>
21+
) : undefined
22+
}
23+
contentSx={contentSx}
24+
>
25+
<div>Content body</div>
26+
</PassageDetailMobileLayout>
27+
</ThemeProvider>
28+
);
29+
};
30+
31+
describe('PassageDetailMobileLayout', () => {
32+
it('renders header, content, and footer', () => {
33+
mountLayout();
34+
35+
cy.get('[data-cy="layout-header"]').should('contain.text', 'Header');
36+
cy.contains('Content body').should('be.visible');
37+
cy.get('[data-cy="layout-footer"]').should('contain.text', 'Footer');
38+
});
39+
40+
it('renders footerAbove when provided', () => {
41+
mountLayout({ withFooterAbove: true });
42+
43+
cy.get('[data-cy="layout-footer-above"]')
44+
.should('be.visible')
45+
.and('contain.text', 'Footer Above');
46+
});
47+
48+
it('applies contentSx overrides', () => {
49+
mountLayout({ contentSx: { pt: 4 } });
50+
51+
cy.contains('Content body')
52+
.parent()
53+
.should('have.css', 'padding-top', '32px');
54+
});
55+
});

src/renderer/src/components/WSAudioPlayer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ function WSAudioPlayer(props: IProps) {
15711571
/>
15721572
</MenuItem>
15731573
)}
1574-
{allowRecord && (
1574+
{allowRecord === true && (
15751575
<>
15761576
{noiseRemovalControl() && (
15771577
<MenuItem onClick={handleMoreMenuClose}>

src/renderer/src/crud/prevPasId.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export const prevPasId = (
1515
if (Array.isArray(passRecIds)) {
1616
const passages: PassageD[] = passRecIds
1717
.map((p) => findRecord(memory, 'passage', p.id) as PassageD)
18-
.sort((a, b) => a.attributes.sequencenum - b.attributes.sequencenum);
18+
.sort(
19+
(a, b) =>
20+
(a?.attributes?.sequencenum ?? 0) - (b?.attributes?.sequencenum ?? 0)
21+
);
1922
let curIndex = passages.findIndex((p) => p.id === curPass);
2023
if (curIndex !== -1) {
2124
for (curIndex -= 1; curIndex >= 0; curIndex--) {

0 commit comments

Comments
 (0)