Skip to content
This repository was archived by the owner on Feb 28, 2026. It is now read-only.

Commit 7d5be1c

Browse files
committed
Slim down artist page tests
1 parent 792541e commit 7d5be1c

File tree

4 files changed

+353
-324
lines changed

4 files changed

+353
-324
lines changed

packages/player/src/test/builders/MetadataProviderBuilder.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
11
import { MetadataProvider } from '@nuclearplayer/plugin-sdk';
22

3+
import {
4+
ALBUMS_BEATLES,
5+
BIO_BEATLES,
6+
PLAYLISTS_DEADMAU5,
7+
RELATED_ARTISTS_BEATLES,
8+
RELATED_ARTISTS_DEADMAU5,
9+
SEARCH_RESULT,
10+
SOCIAL_STATS_DEADMAU5,
11+
TOP_TRACKS_BEATLES,
12+
TOP_TRACKS_DEADMAU5,
13+
} from '../fixtures/artists';
14+
315
export class MetadataProviderBuilder {
416
private provider: MetadataProvider;
517

18+
static bioStyleProvider(): MetadataProviderBuilder {
19+
return new MetadataProviderBuilder()
20+
.withSearchCapabilities(['unified', 'artists'])
21+
.withArtistMetadataCapabilities([
22+
'artistBio',
23+
'artistAlbums',
24+
'artistTopTracks',
25+
'artistRelatedArtists',
26+
])
27+
.withAlbumMetadataCapabilities(['albumDetails'])
28+
.withSearch(async () => SEARCH_RESULT)
29+
.withFetchArtistBio(async () => BIO_BEATLES)
30+
.withFetchArtistAlbums(async () => ALBUMS_BEATLES)
31+
.withFetchArtistTopTracks(async () => TOP_TRACKS_BEATLES)
32+
.withFetchArtistRelatedArtists(async () => RELATED_ARTISTS_BEATLES);
33+
}
34+
35+
static socialStatsStyleProvider(): MetadataProviderBuilder {
36+
return new MetadataProviderBuilder()
37+
.withSearchCapabilities(['unified', 'artists'])
38+
.withArtistMetadataCapabilities([
39+
'artistSocialStats',
40+
'artistTopTracks',
41+
'artistPlaylists',
42+
'artistRelatedArtists',
43+
])
44+
.withSearch(async () => SEARCH_RESULT)
45+
.withFetchArtistSocialStats(async () => SOCIAL_STATS_DEADMAU5)
46+
.withFetchArtistTopTracks(async () => TOP_TRACKS_DEADMAU5)
47+
.withFetchArtistPlaylists(async () => PLAYLISTS_DEADMAU5)
48+
.withFetchArtistRelatedArtists(async () => RELATED_ARTISTS_DEADMAU5);
49+
}
50+
651
constructor() {
752
this.provider = {
853
id: 'test-metadata-provider',
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import type {
2+
AlbumRef,
3+
ArtistBio,
4+
ArtistRef,
5+
ArtistSocialStats,
6+
PlaylistRef,
7+
SearchResults,
8+
TrackRef,
9+
} from '@nuclearplayer/model';
10+
11+
const TEST_PROVIDER_ID = 'test-metadata-provider';
12+
const TEST_ARTIST_ID = 'test-artist-id';
13+
14+
const testSource = (id: string) => ({ provider: TEST_PROVIDER_ID, id });
15+
16+
export const SEARCH_RESULT: SearchResults = {
17+
artists: [
18+
{
19+
name: 'Test Artist',
20+
artwork: {
21+
items: [
22+
{
23+
url: 'https://img/avatar.jpg',
24+
purpose: 'avatar' as const,
25+
width: 300,
26+
},
27+
{
28+
url: 'https://img/cover.jpg',
29+
purpose: 'cover' as const,
30+
width: 1200,
31+
},
32+
],
33+
},
34+
source: testSource(TEST_ARTIST_ID),
35+
},
36+
],
37+
};
38+
39+
export const BIO_BEATLES: ArtistBio = {
40+
name: 'The Beatles',
41+
onTour: true,
42+
tags: ['rock', 'indie', 'brit-pop'],
43+
artwork: {
44+
items: [
45+
{ url: 'https://img/avatar.jpg', purpose: 'avatar' as const, width: 300 },
46+
{ url: 'https://img/cover.jpg', purpose: 'cover' as const, width: 1200 },
47+
],
48+
},
49+
source: testSource(TEST_ARTIST_ID),
50+
};
51+
52+
export const SOCIAL_STATS_DEADMAU5: ArtistSocialStats = {
53+
name: 'Deadmau5',
54+
artwork: {
55+
items: [
56+
{ url: 'https://img/avatar.jpg', purpose: 'avatar' as const, width: 300 },
57+
],
58+
},
59+
city: 'Toronto',
60+
country: 'CA',
61+
followersCount: 5400000,
62+
followingsCount: 120,
63+
trackCount: 340,
64+
playlistCount: 22,
65+
source: testSource(TEST_ARTIST_ID),
66+
};
67+
68+
export const ALBUMS_BEATLES: AlbumRef[] = [
69+
{
70+
title: 'Hello World LP',
71+
artists: [{ name: 'Test Artist', source: testSource(TEST_ARTIST_ID) }],
72+
artwork: {
73+
items: [
74+
{ url: 'https://img/debut.jpg', purpose: 'cover' as const, width: 300 },
75+
],
76+
},
77+
source: testSource('album-1'),
78+
},
79+
];
80+
81+
export const TOP_TRACKS_BEATLES: TrackRef[] = [
82+
{
83+
title: 'Smells Like Cheap Spirit',
84+
artists: [{ name: 'Test Artist', source: testSource(TEST_ARTIST_ID) }],
85+
artwork: {
86+
items: [
87+
{
88+
url: 'https://img/track.jpg',
89+
purpose: 'thumbnail' as const,
90+
width: 64,
91+
},
92+
],
93+
},
94+
source: testSource('track-1'),
95+
},
96+
];
97+
98+
export const TOP_TRACKS_DEADMAU5: TrackRef[] = [
99+
{
100+
title: 'Strobe',
101+
artists: [{ name: 'Deadmau5', source: testSource(TEST_ARTIST_ID) }],
102+
artwork: {
103+
items: [
104+
{
105+
url: 'https://img/track.jpg',
106+
purpose: 'thumbnail' as const,
107+
width: 64,
108+
},
109+
],
110+
},
111+
source: testSource('track-1'),
112+
},
113+
];
114+
115+
export const PLAYLISTS_DEADMAU5: PlaylistRef[] = [
116+
{
117+
id: 'playlist-1',
118+
name: 'mau5trap selects',
119+
artwork: {
120+
items: [
121+
{
122+
url: 'https://img/playlist1.jpg',
123+
purpose: 'cover' as const,
124+
width: 300,
125+
},
126+
],
127+
},
128+
source: testSource('playlist-1'),
129+
},
130+
];
131+
132+
export const RELATED_ARTISTS_BEATLES: ArtistRef[] = [
133+
{
134+
name: 'John Lennon',
135+
artwork: {
136+
items: [
137+
{
138+
url: 'https://img/similar1.jpg',
139+
purpose: 'avatar' as const,
140+
width: 64,
141+
},
142+
],
143+
},
144+
source: testSource('artist-2'),
145+
},
146+
{
147+
name: 'Kurt Cobain',
148+
artwork: {
149+
items: [
150+
{
151+
url: 'https://img/similar2.jpg',
152+
purpose: 'avatar' as const,
153+
width: 64,
154+
},
155+
],
156+
},
157+
source: testSource('artist-3'),
158+
},
159+
];
160+
161+
export const RELATED_ARTISTS_DEADMAU5: ArtistRef[] = [
162+
{
163+
name: 'Skrillex',
164+
artwork: {
165+
items: [
166+
{
167+
url: 'https://img/similar1.jpg',
168+
purpose: 'avatar' as const,
169+
width: 64,
170+
},
171+
],
172+
},
173+
source: testSource('artist-2'),
174+
},
175+
];

packages/player/src/views/Artist/Artist.test-wrapper.tsx

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,91 @@ export const ArtistWrapper = {
1919
const component = await SearchWrapper.mount('test artist');
2020
const artistLink = await screen.findByText('Test Artist');
2121
await user.click(artistLink);
22-
await new Promise((r) => setTimeout(r, 0));
22+
await new Promise((resolve) => setTimeout(resolve, 0));
2323
return component;
2424
},
25+
2526
getHeader: (name: string) => screen.getByRole('heading', { name }),
26-
getPopularTracksSection: () =>
27-
screen.getByRole('heading', { name: /popular tracks/i }),
28-
getSimilarArtistsSection: () =>
29-
screen.getByRole('heading', { name: /similar artists/i }),
30-
getAlbumsGrid: () => screen.getByTestId('artist-albums-grid'),
31-
getAlbums: () => screen.queryAllByTestId('card'),
32-
getSimilarArtistItems: () => screen.queryAllByRole('listitem'),
33-
getTracksTable: () => screen.queryByRole('table'),
34-
expectSimilarArtistItem(li: HTMLElement) {
35-
const utils = within(li);
36-
const img = utils.queryByRole('img');
37-
const name = utils.getByText(/.+/);
38-
return { img, name };
27+
28+
bioHeader: {
29+
get loader() {
30+
return screen.queryByTestId('artist-header-loader');
31+
},
32+
async findLoader() {
33+
return screen.findByTestId('artist-header-loader');
34+
},
35+
},
36+
37+
socialHeader: {
38+
get element() {
39+
return screen.queryByTestId('artist-social-header');
40+
},
41+
get loader() {
42+
return screen.queryByTestId('artist-social-header-loader');
43+
},
44+
async findLoader() {
45+
return screen.findByTestId('artist-social-header-loader');
46+
},
3947
},
48+
49+
popularTracks: {
50+
get heading() {
51+
return screen.getByRole('heading', { name: /popular tracks/i });
52+
},
53+
get table() {
54+
return screen.queryByRole('table');
55+
},
56+
get loader() {
57+
return screen.queryByTestId('popular-tracks-loader');
58+
},
59+
async findLoader() {
60+
return screen.findByTestId('popular-tracks-loader');
61+
},
62+
},
63+
64+
similarArtists: {
65+
get heading() {
66+
return screen.getByRole('heading', { name: /similar artists/i });
67+
},
68+
get items() {
69+
return screen.queryAllByRole('listitem');
70+
},
71+
get loader() {
72+
return screen.queryByTestId('similar-artists-loader');
73+
},
74+
async findLoader() {
75+
return screen.findByTestId('similar-artists-loader');
76+
},
77+
inspectItem(listItem: HTMLElement) {
78+
const utils = within(listItem);
79+
return {
80+
img: utils.queryByRole('img'),
81+
name: utils.getByText(/.+/),
82+
};
83+
},
84+
},
85+
86+
albums: {
87+
get cards() {
88+
return screen.queryAllByTestId('card');
89+
},
90+
get loader() {
91+
return screen.queryByTestId('artist-albums-loader');
92+
},
93+
async findLoader() {
94+
return screen.findByTestId('artist-albums-loader');
95+
},
96+
},
97+
98+
playlists: {
99+
get loader() {
100+
return screen.queryByTestId('artist-playlists-loader');
101+
},
102+
async findLoader() {
103+
return screen.findByTestId('artist-playlists-loader');
104+
},
105+
},
106+
40107
async toggleFavorite() {
41108
const button = await screen.findByTestId('artist-favorite-button');
42109
await user.click(button);

0 commit comments

Comments
 (0)