Skip to content

Commit 4d00f2f

Browse files
committed
Get showGive value from landing page data
1 parent c6dd888 commit 4d00f2f

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

src/app/layouts/landing/header/header.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import './header.scss';
55

66
export default function Header({
77
links,
8-
showGive
8+
showGive = true
99
}: {
1010
links: LinkFields[];
11-
showGive: boolean;
11+
showGive?: boolean;
1212
}) {
1313
const riceLogo = useOptimizedImage(
1414
'https://openstax.org/dist/images/rice.webp',

src/app/layouts/landing/landing.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ import {LinkFields} from '../../pages/flex-page/components/Link';
1212
import './landing.scss';
1313

1414
type Props = {
15-
showGive?: boolean;
1615
data: {
1716
title: string;
1817
layout: Array<{
1918
value: {
2019
navLinks: LinkFields[];
20+
showGive?: boolean;
2121
};
2222
}>;
2323
};
2424
};
2525

2626
export default function LandingLayout({
2727
children,
28-
data,
29-
showGive = true
28+
data
3029
}: React.PropsWithChildren<Props>) {
30+
const showGive = data.layout[0]?.value.showGive;
31+
3132
// BrowserRouter has to include everything that uses useLocation
3233
return (
3334
<React.Fragment>

test/src/layouts/layouts.test.tsx

+20-11
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,43 @@ import LandingLayout from '~/layouts/landing/landing';
77
// @ts-expect-error does not exist on
88
const {routerFuture} = global;
99

10+
type Layout = Parameters<typeof LandingLayout>[0]['data']['layout'];
1011

1112
describe('layouts/landing', () => {
12-
const data: Parameters<typeof LandingLayout>[0]['data'] = {
13-
title: 'the-title',
14-
layout: []
15-
};
13+
function Component({layout}: {layout: Layout}) {
14+
const data: Parameters<typeof LandingLayout>[0]['data'] = {
15+
title: 'the-title',
16+
layout
17+
};
1618

17-
function Component({showGive}: {showGive?: boolean}) {
1819
return (
1920
<MemoryRouter initialEntries={['']} future={routerFuture}>
20-
<LandingLayout data={data} showGive={showGive}>
21+
<LandingLayout data={data}>
2122
<div>child contents</div>
2223
</LandingLayout>
2324
</MemoryRouter>
2425
);
2526
}
2627

2728
it('renders without layout values', () => {
28-
render(<Component />);
29+
render(<Component layout={[]} />);
2930
expect(screen.getAllByRole('img')).toHaveLength(2);
3031
expect(screen.getAllByRole('link')).toHaveLength(1);
3132
});
3233
it('suppresses the Give link when specified', () => {
33-
render(<Component showGive={false} />);
34+
const layout = [{
35+
value: {
36+
navLinks: [],
37+
showGive: false
38+
}
39+
}];
40+
41+
render(<Component layout={layout} />);
3442
expect(screen.getAllByRole('img')).toHaveLength(2);
3543
expect(screen.queryAllByRole('link')).toHaveLength(0);
3644
});
3745
it('renders with layout values', () => {
38-
data.layout.push({
46+
const layout = [{
3947
value: {
4048
navLinks: [
4149
{
@@ -47,8 +55,9 @@ describe('layouts/landing', () => {
4755
}
4856
]
4957
}
50-
});
51-
render(<Component />);
58+
}];
59+
60+
render(<Component layout={layout} />);
5261
expect(screen.getAllByRole('link')).toHaveLength(2);
5362
});
5463
});

0 commit comments

Comments
 (0)