Skip to content

Commit

Permalink
Merge pull request #1669 from guardian/db/ui-indication-for-no-recipe
Browse files Browse the repository at this point in the history
UI indication for no recipe
  • Loading branch information
Divs-B authored Oct 14, 2024
2 parents ffc06cc + 389da0f commit 35cf810
Show file tree
Hide file tree
Showing 11 changed files with 855 additions and 282 deletions.
1 change: 1 addition & 0 deletions fronts-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"fetch-mock": "^6.4.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-styled-components": "^7.2.0",
"jsdom": "^21.1.1",
"prettier": "^2.0.2",
"puppeteer": "^22.3.0",
Expand Down
6 changes: 6 additions & 0 deletions fronts-client/src/components/card/CardContent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import styled from 'styled-components';
import { CardSizes } from 'types/Collection';
import { theme } from '../../constants/theme';

const CardContent = styled.div<{
displaySize?: CardSizes;
textSize?: CardSizes;
isToShowError?: boolean;
}>`
position: relative;
min-width: 0;
Expand All @@ -17,6 +19,10 @@ const CardContent = styled.div<{
p {
margin: 0;
}
background-color: ${({ isToShowError }) =>
isToShowError ? theme.colors.greyMediumLight : theme.colors.white};
color: ${({ isToShowError }) =>
isToShowError ? theme.colors.white : theme.colors.blackLight};
`;

export default CardContent;
4 changes: 3 additions & 1 deletion fronts-client/src/components/card/CardHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { CardSizes } from 'types/Collection';
const Wrapper = styled.span<{
displaySize?: CardSizes;
showLargeHeadline?: boolean;
isToShowError?: boolean;
}>`
font-family: TS3TextSans;
font-weight: normal;
font-weight: ${({ isToShowError }) => (isToShowError ? 'bold' : 'normal')};
padding: 2px 0 0;
font-size: ${theme.card.fontSizeSmall};
${media.large`font-size: 13px;`}
Expand All @@ -21,6 +22,7 @@ interface CardHeading {
html?: boolean;
displaySize?: CardSizes;
showLargeHeadline?: boolean;
isToShowError?: boolean;
}

const CardHeading = ({
Expand Down
13 changes: 11 additions & 2 deletions fronts-client/src/components/card/CardMetaContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { styled } from 'constants/theme';
import { styled, theme } from 'constants/theme';

import ShortVerticalPinline from 'components/layout/ShortVerticalPinline';
import { media } from 'util/mediaQueries';
Expand All @@ -13,6 +13,7 @@ const metaContainerSizeWidthMap = {

interface MetaContainerProps {
size?: CardSizes;
isToShowError?: boolean;
}
const MetaContainer = styled.div<MetaContainerProps>`
position: relative;
Expand All @@ -28,16 +29,24 @@ const MetaContainer = styled.div<MetaContainerProps>`
word-break: break-word;
`}
padding: 0 4px;
background-color: ${({ isToShowError }) =>
isToShowError ? theme.colors.greyMediumLight : theme.colors.white};
`;

export default ({
children,
size = 'default',
isToShowError,
}: {
children?: React.ReactNode;
size?: CardSizes;
isToShowError?: boolean;
}) => (
<MetaContainer size={size}>
<MetaContainer
size={size}
isToShowError={isToShowError}
data-testid="meta-container"
>
{children}
<ShortVerticalPinline />
</MetaContainer>
Expand Down
123 changes: 123 additions & 0 deletions fronts-client/src/components/card/__tests__/ChefCard.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import React from 'react';
import { render, cleanup } from 'react-testing-library';
import configureStore from 'util/configureStore';
import { Provider } from 'react-redux';
import { theme } from '../../../constants/theme';
import { ThemeProvider } from 'styled-components';
import 'jest-styled-components';
import { ChefCard } from '../chef/ChefCard';

const chefFixture = {
backgroundHex: '#20809E',
id: 'profile/yotamottolenghi',
image:
'https://media.guim.co.uk/266825657a291ab9c1c0b798a0391f827b6c53ec/93_150_907_907/500.jpg',
bio: 'Inspiration and global flavours for special occasions',
foregroundHex: '#F9F9F5',
webTitle: 'Yotam Ottolenghi',
};

describe('ChefCard', () => {
afterEach(cleanup);

it('should render a chef', async () => {
const store = configureStore({
feed: {},
cards: {
'test-chef-card': {
id: 'test-chef-id',
uuid: 'test-chef-card',
meta: {
chefTheme: {
id: 'test-chef-theme-id',
palette: {},
},
},
},
},
chefs: {
data: {
'test-chef-id': chefFixture,
},
},
});

const component = render(
<Provider store={store}>
<ThemeProvider theme={theme}>
<ChefCard
onDelete={jest.fn()}
onAddToClipboard={jest.fn()}
id="test-chef-card"
frontId="test-chef-id"
/>
</ThemeProvider>
</Provider>
);

const headline = await component.findAllByTestId('headline');
expect(headline).toHaveLength(1);
expect(headline[0].textContent).toContain('Yotam Ottolenghi');

const metacontainer = await component.findAllByTestId('meta-container');
expect(metacontainer).toHaveLength(1);
expect(metacontainer[0]).toHaveStyleRule(
'background-color',
theme.colors.white
);

expect(await component.findAllByText('Chef', {})).toHaveLength(1);
expect(component.queryByTestId('chef-not-found-icon')).toBeNull();
});

it('should render a warning state if the chef is not defined', async () => {
const store = configureStore({
feed: {},
cards: {
'test-chef-card': {
id: 'test-chef-id',
uuid: 'test-chef-card',
meta: {
chefTheme: {
id: 'test-chef-theme-id',
palette: {},
},
},
},
},
chefs: {
data: {},
},
});

const component = render(
<Provider store={store}>
<ThemeProvider theme={theme}>
<ChefCard
onDelete={jest.fn()}
onAddToClipboard={jest.fn()}
id="test-chef-card"
frontId="test-chef-id"
/>
</ThemeProvider>
</Provider>
);

const headline = await component.findAllByTestId('headline');
expect(headline).toHaveLength(1);
expect(headline[0].textContent).toEqual(
'This chef might not load in the app, please select an alternative.'
);

const metacontainer = await component.findAllByTestId('meta-container');
expect(metacontainer).toHaveLength(1);
expect(metacontainer[0]).toHaveStyleRule(
'background-color',
theme.colors.greyMediumLight
);
expect(component.queryByText('Chef')).toBeNull();
expect(await component.findAllByTestId('chef-not-found-icon')).toHaveLength(
1
);
});
});
Loading

0 comments on commit 35cf810

Please sign in to comment.