Skip to content

Commit

Permalink
fix: add fallback page title when first name is missing (#1573)
Browse files Browse the repository at this point in the history
* fix: add fallback page title when first name is missing

* fix: correctly pass external param to <ToolIconAndLink>

* test: add home page title tests

* fix: add parameter to setup; fix default title test
  • Loading branch information
paulschreiber authored Mar 7, 2024
1 parent 4eaa6e4 commit 4fca5e1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/home/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ const Home = () => {

return (
<PageContainer>
<PageHeader header={t('home.page_title', { name: user.firstName })} />
<PageHeader
header={
user.firstName
? t('home.page_title', { name: user.firstName })
: t('home.document_title')
}
/>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Stack spacing={3}>
Expand Down
31 changes: 26 additions & 5 deletions src/home/components/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ jest.mock('home/homeService', () => ({
fetchHomeData: jest.fn(),
}));

const setup = async () => {
const setup = async (
currentUserData = { firstName: 'First', lastName: 'Last' }
) => {
await render(<Home />, {
account: {
hasToken: true,
currentUser: {
fetching: false,
data: {
firstName: 'First',
lastName: 'Last',
},
data: currentUserData,
},
},
});
Expand Down Expand Up @@ -249,3 +248,25 @@ test('Home: Display defaults', async () => {
)
).toBeInTheDocument();
});

test('Home: Display title', async () => {
fetchHomeData.mockReturnValue(
Promise.resolve({
groups: [],
landscapes: [],
})
);
await setup();
expect(screen.getByText(/First’s Terraso/i)).toBeInTheDocument();
});

test('Home: Display title (default)', async () => {
fetchHomeData.mockReturnValue(
Promise.resolve({
groups: [],
landscapes: [],
})
);
await setup({ firstName: undefined, lastName: undefined });
expect(screen.getByText(/Terraso Home/i)).toBeInTheDocument();
});
6 changes: 5 additions & 1 deletion src/tool/components/ToolCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ const ToolCard = ({ tool }) => {
</section>

<section>
<ToolIconAndLink tool={tool} title={toolTitle} external />
<ToolIconAndLink
tool={tool}
title={toolTitle}
external={external}
/>
</section>
</Stack>
</Card>
Expand Down

0 comments on commit 4fca5e1

Please sign in to comment.