Skip to content

Commit

Permalink
Don't render similar artists if they're empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Jul 21, 2024
1 parent 4a5fed0 commit 811c739
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/app/app/components/ArtistView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ const ArtistView: React.FC<ArtistViewProps> = ({

function renderSimilarArtists() {
return (
!isLoading() &&
!isLoading() && !isEmpty(artist.similar) &&
<SimilarArtists
artists={_.get(artist, 'similar', [])}
artists={artist.similar}
artistInfoSearchByName={artistInfoSearchByName}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ describe('Artist view container', () => {
expect(history.location.pathname).toBe('/artist/artist-similar-id');
});

it('should not render similar artists section if there are no similar artists', async () => {
const stateWithArtistDetails = buildStoreState()
.withArtistDetails()
.build();
const initialState = buildStoreState()
.withArtistDetails({
['test-artist-id']: {
...stateWithArtistDetails.search.artistDetails['test-artist-id'],
similar: []
}
})
.withPlugins()
.withConnectivity()
.build();

const { component } = mountComponent(initialState);
await waitFor(() => component.findByText(/popular tracks/i));
const similarArtists = component.queryByText(/similar artists/i);
expect(similarArtists).toBeNull();
});

it('should add a single track to queue after clicking the button in the popup', async () => {
const { component, store } = mountComponent();

Expand Down
57 changes: 20 additions & 37 deletions packages/app/test/storeBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { TrackStream } from '../app/reducers/queue';
import { LocalLibraryState } from '../app/actions/local';
import { DeezerEditorialCharts } from '@nuclear/core/src/rest/Deezer';
import { Loadable } from '../app/reducers/types';
import { ArtistDetailsState } from '../app/reducers/search';
import { SearchResultsSource } from '@nuclear/core/src/plugins/plugins.types';

type StoreStateBuilder = ReturnType<typeof buildStoreState>;
export const buildStoreState = () => {
Expand Down Expand Up @@ -144,7 +146,7 @@ export const buildStoreState = () => {
};
return this as StoreStateBuilder;
},
withArtistDetails(data?: any) {
withArtistDetails(data?: {[key: string]: ArtistDetailsState }) {
state = {
...state,
search: {
Expand All @@ -162,50 +164,40 @@ export const buildStoreState = () => {
{
id: 'test-album-1',
title: ' Test album 1',
artists: [
{
name: 'test artist 1'
}
],
artist: 'test artist 1',
genres: ['genre 1', 'genre 2'],
images: ['image 1'],
thumb: 'image 1',
coverImage: 'image 1',
tracklist: [
{
uuid: 'track-1',
artist: {
name: 'test artist 1'
},
artist: 'test artist 1',
title: 'test track 1',
duration: 10
}
],
year: 2019
year: '2019',
source: SearchResultsSource.Discogs
},
{
id: 'test-album-2',
title: ' Test album 2',
artists: [
{
name: 'test artist 2'
}
],
artist: 'test artist 2',
genres: ['genre 2', 'genre 3'],
images: ['image 2'],
thumb: 'image 2',
coverImage: 'image 2',
tracklist: [
{
uuid: 'track-2',
artist: {
name: 'test artist 2'
},
artist: 'test artist 2',
title: 'test track 2',
duration: 40
}
],
year: 2021
year: '2021',
source: SearchResultsSource.Discogs
}
],
releasesLoading: false,
Expand All @@ -224,37 +216,28 @@ export const buildStoreState = () => {
topTracks: [
{
artist: {
mbid: 'test mbid',
name: 'test artist',
url: 'test artist url'
name: 'test artist'
},
listeners: '771858',
name: 'test artist top track 1',
playcount: '6900237',
listeners: 771858,
playcount: 6900237,
thumb: '',
title: 'test artist top track 1'
},
{
artist: {
mbid: 'test mbid',
name: 'test artist',
url: 'test artist url'
name: 'test artist'
},
listeners: '123',
name: 'test artist top track 2',
playcount: '6969',
listeners: 123,
playcount: 6969,
thumb: '',
title: 'test artist top track 2'
},
{
artist: {
mbid: 'test mbid',
name: 'test artist',
url: 'test artist url'
name: 'test artist'
},
listeners: '9',
name: 'test artist top track 3',
playcount: '1',
listeners: 9,
playcount: 1,
thumb: '',
title: 'test artist top track 3'
}
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/plugins/plugins.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ export type SearchResultsAlbum = {
id: string;
coverImage?: string;
thumb?: string;
genres?: string[];
images?: string[];
title: string;
artist: string;
resourceUrl?: string;
type?: string;
tracklist?: {
uuid: string;
artist: string;
title: string;
duration: number;
}[];
year?: string;
source: SearchResultsSource;
}

Expand Down

0 comments on commit 811c739

Please sign in to comment.