Skip to content

Commit

Permalink
feat: use data uri for card fallback image (#3323)
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-smith-tcril authored Dec 12, 2024
1 parent e58002f commit 8a828cf
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Card/CardFallbackDefaultImage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Card/CardImageCap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import Skeleton from 'react-loading-skeleton';
import CardContext from './CardContext';
import cardSrcFallbackImg from './fallback-default.png';
import { cardSrcFallbackImg } from './CardFallbackDefaultImage';

const SKELETON_HEIGHT_VALUE = 140;
const LOGO_SKELETON_HEIGHT_VALUE = 41;
Expand Down
Binary file removed src/Card/fallback-default.png
Binary file not shown.
6 changes: 3 additions & 3 deletions src/Card/tests/CardImageCap.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import renderer from 'react-test-renderer';
import { render, fireEvent, screen } from '@testing-library/react';
import CardImageCap from '../CardImageCap';
import CardContext from '../CardContext';
import { cardSrcFallbackImg } from '../CardFallbackDefaultImage';

// eslint-disable-next-line react/prop-types
function CardImageCapWrapper({ orientation = 'vertical', isLoading, ...props }) {
Expand Down Expand Up @@ -119,13 +120,12 @@ describe('<CardImageCap />', () => {
expect(logoImg.className).toEqual('pgn__card-logo-cap');
});

it('hiding component if it isn`t fallbackSrc and src don`t work', () => {
it('renders the default image if both src and fallbackSrc fail to load', () => {
render(<CardImageCapWrapper src="fakeURL" fallbackSrc="fakeURL" srcAlt="Src alt text" />);

const srcImg = screen.getByAltText('Src alt text');
fireEvent.load(srcImg);
fireEvent.error(srcImg);
// test-file-stub is what our fileMock.js returns for all images
expect(srcImg.src.endsWith('test-file-stub')).toEqual(true);
expect(srcImg.src).toEqual(cardSrcFallbackImg);
});
});

0 comments on commit 8a828cf

Please sign in to comment.