Skip to content

Commit

Permalink
TrackCard jest test case fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
anasnadeemws committed Mar 4, 2024
1 parent 13b9631 commit e379e09
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions app/components/TrackCard/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,40 @@ import { translate } from '@app/utils/index';

describe('<TrackCard />', () => {
it('should render and match the snapshot', () => {
const { baseElement } = renderWithIntl(<TrackCard />);
const mockSetTrackPlaying = jest.fn();
const { baseElement } = renderWithIntl(<TrackCard setTrackPlaying={mockSetTrackPlaying} />);
expect(baseElement).toMatchSnapshot();
});

it('should contain 1 TrackCard component', () => {
const { getAllByTestId } = renderWithIntl(<TrackCard />);
const mockSetTrackPlaying = jest.fn();
const { getAllByTestId } = renderWithIntl(<TrackCard setTrackPlaying={mockSetTrackPlaying} />);
expect(getAllByTestId('track-card').length).toBe(1);
});

it('should render the track details inside the card', () => {
const collectionName = 'Sunflower';
const artistName = 'Post Malone';
const shortDescription = '';
const artworkUrl100 = 'https://someurl.com';
const previewUrl = '';
const { getByTestId } = renderWithIntl(
<TrackCard
collectionName={collectionName}
artistName={artistName}
shortDescription={shortDescription}
artworkUrl100={artworkUrl100}
previewUrl={previewUrl}
/>
);
expect(getByTestId('collectionName')).toHaveTextContent(collectionName);
const mockSetTrackPlaying = jest.fn();
const trackData = {
collectionName: 'Sunflower',
artistName: 'Post Malone',
shortDescription: 'Sample Description',
artworkUrl100: 'https://example.com/image.jpg',
previewUrl: 'https://example.com/preview.mp3'
};
const { getByTestId } = renderWithIntl(<TrackCard setTrackPlaying={mockSetTrackPlaying} {...trackData} />);

expect(getByTestId('collectionName')).toHaveTextContent(trackData.collectionName);
expect(getByTestId('artistName')).toHaveTextContent(trackData.artistName);
expect(getByTestId('track_shortdesc')).toHaveTextContent(trackData.shortDescription);
});

it('should render the track unavailable messages in case any props are unavailable or have falsy values', () => {
const mockSetTrackPlaying = jest.fn();
const collectionNameUnavailable = translate('collection_name_unavailable');
const artistNameUnavailable = translate('track_artist_name_unavailable');
const shortDescriptionUnavailable = translate('track_shortdesc_unavailable');
const { getByTestId } = renderWithIntl(<TrackCard />);

const { getByTestId } = renderWithIntl(<TrackCard setTrackPlaying={mockSetTrackPlaying} />);
expect(getByTestId('collection_name_unavailable')).toHaveTextContent(collectionNameUnavailable);
expect(getByTestId('track_artist_name_unavailable')).toHaveTextContent(artistNameUnavailable);
expect(getByTestId('track_shortdesc_unavailable')).toHaveTextContent(shortDescriptionUnavailable);
Expand Down

0 comments on commit e379e09

Please sign in to comment.