Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrackCard jest test case fixed #4

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading