Skip to content

Commit 0086917

Browse files
authored
Merge pull request #19976 from mozilla/splitlayout-en
feat(cms): Temporarily don't load splitLayout for non-EN locales
2 parents 2dcae73 + 2ccb716 commit 0086917

2 files changed

Lines changed: 64 additions & 5 deletions

File tree

packages/fxa-settings/src/components/AppLayout/index.test.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
MOCK_CMS_INFO_HEADER_LOGO_WITH_OTHER_PROPS,
1818
} from './mocks';
1919
import { MOCK_CMS_INFO } from '../../pages/mocks';
20+
import { useDynamicLocalization } from '../../contexts/DynamicLocalizationContext';
2021

2122
// Mock the useConfig hook
2223
jest.mock('../../models/hooks', () => ({
@@ -30,6 +31,17 @@ jest.mock('../../models/hooks', () => ({
3031
}),
3132
}));
3233

34+
jest.mock('../../contexts/DynamicLocalizationContext', () => ({
35+
useDynamicLocalization: jest.fn(() => ({
36+
currentLocale: 'en',
37+
switchLanguage: jest.fn(),
38+
clearLanguagePreference: jest.fn(),
39+
isLoading: false,
40+
})),
41+
}));
42+
43+
const mockUseDynamicLocalization = useDynamicLocalization as jest.Mock;
44+
3345
describe('<AppLayout />', () => {
3446
it('renders as expected with children', async () => {
3547
renderWithLocalizationProvider(
@@ -379,4 +391,46 @@ describe('<AppLayout />', () => {
379391
expect(headerBackground).toMatchSnapshot('header background');
380392
});
381393
});
394+
395+
describe('splitLayout with locale restrictions (temp hack)', () => {
396+
it('renders split layout when splitLayout is true and locale is English', () => {
397+
mockUseDynamicLocalization.mockReturnValue({
398+
currentLocale: 'en-US',
399+
switchLanguage: jest.fn(),
400+
clearLanguagePreference: jest.fn(),
401+
isLoading: false,
402+
});
403+
404+
const { container } = renderWithLocalizationProvider(
405+
<AppLayout splitLayout={true}>
406+
<p>Split layout content</p>
407+
</AppLayout>
408+
);
409+
410+
// Split layout does not render the card wrapper
411+
expect(container.querySelector('.card')).not.toBeInTheDocument();
412+
screen.getByText('Split layout content');
413+
});
414+
415+
it('renders default layout when splitLayout is true but locale is not English', () => {
416+
mockUseDynamicLocalization.mockReturnValue({
417+
currentLocale: 'fr',
418+
switchLanguage: jest.fn(),
419+
clearLanguagePreference: jest.fn(),
420+
isLoading: false,
421+
});
422+
423+
const { container } = renderWithLocalizationProvider(
424+
<AppLayout splitLayout={true} cmsInfo={MOCK_CMS_INFO_HEADER_LOGO}>
425+
<p>Default layout content</p>
426+
</AppLayout>
427+
);
428+
429+
// Default layout renders with card wrapper
430+
expect(container.querySelector('.card')).toBeInTheDocument();
431+
screen.getByText('Default layout content');
432+
// CMS info is still applied even when split layout is disabled
433+
expect(screen.getByAltText('CMS Custom Logo')).toBeInTheDocument();
434+
});
435+
});
382436
});

packages/fxa-settings/src/components/AppLayout/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { LocaleToggle } from '../LocaleToggle';
1313
import { useConfig } from '../../models/hooks';
1414
import { CardLoadingSpinner } from '../CardLoadingSpinner';
1515
import LoadingSpinner from 'fxa-react/components/LoadingSpinner';
16+
import { useDynamicLocalization } from '../../contexts/DynamicLocalizationContext';
1617

1718
type AppLayoutProps = {
1819
// TODO: FXA-6803 - the title prop should be made mandatory
@@ -54,16 +55,20 @@ export const AppLayout = ({
5455
}: AppLayoutProps) => {
5556
const { l10n } = useLocalization();
5657
const config = useConfig();
58+
const { currentLocale } = useDynamicLocalization();
59+
60+
// TEMP HACK (FXA-12988): Only show split layout for English locales
61+
const showSplitLayout = splitLayout && currentLocale.startsWith('en');
5762

5863
// Set the current page's layout preference in state so navigation
5964
// preserves the layout during Suspense fallback, preventing visual flash.
6065
// Only update if setCurrentSplitLayout is provided (it's omitted from Suspense fallback).
6166
// Uses useLayoutEffect instead of useEffect to prevent flicker of incorrect layout before paint
6267
useLayoutEffect(() => {
6368
if (setCurrentSplitLayout) {
64-
setCurrentSplitLayout(splitLayout);
69+
setCurrentSplitLayout(showSplitLayout);
6570
}
66-
}, [splitLayout, setCurrentSplitLayout]);
71+
}, [showSplitLayout, setCurrentSplitLayout]);
6772

6873
const cmsBackgrounds = cmsInfo?.shared?.backgrounds;
6974
const cmsPageTitle = cmsInfo?.shared?.pageTitle;
@@ -83,7 +88,7 @@ export const AppLayout = ({
8388
className={classNames(
8489
'flex min-h-screen flex-col items-center',
8590
cmsBackgrounds?.defaultLayout && 'tablet:[background:var(--cms-bg)]',
86-
splitLayout && 'tablet:relative'
91+
showSplitLayout && 'tablet:relative'
8792
)}
8893
style={
8994
cmsBackgrounds?.defaultLayout
@@ -101,7 +106,7 @@ export const AppLayout = ({
101106
cmsBackgrounds?.header &&
102107
'tablet:[background:var(--cms-header-bg)]',
103108
// Absolute position so the background-image can optionally show through.
104-
splitLayout && 'tablet:absolute'
109+
showSplitLayout && 'tablet:absolute'
105110
)}
106111
style={
107112
cmsBackgrounds?.header
@@ -136,7 +141,7 @@ export const AppLayout = ({
136141
</LinkExternal>
137142
</header>
138143

139-
{!splitLayout ? (
144+
{!showSplitLayout ? (
140145
<>
141146
<main className="flex mobileLandscape:items-center flex-1">
142147
<section>

0 commit comments

Comments
 (0)