Música se ordena: pestañas, buscador, y listas de diez con "Mostrar más"
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
La pantalla era una sola columna —radio, después podcasts, después listas— y tres listas de veinte filas es una pantalla por la que se baja buscando lo que ya sabías que querías. Ahora pregunta primero: **Radio | Podcasts | Listas**, una lista a la vez, **diez filas** y un **"Mostrar más"** que dice cuántas esconde. Nada queda fuera de alcance y nada más está en pantalla mientras decidís: el subtítulo también dice qué estás mirando en vez de hablar siempre de listas. El **buscador** busca lo que tengas abierto y en el origen, no en la página: `jazz` le pregunta al directorio de emisoras y `crimen` al de podcasts de Apple —filtrado, como siempre, a español, y pasando por **la misma** función de filtro que una categoría, porque un segundo camino más barato al catálogo es como se pierde una regla—. Con menos de dos letras no se busca ni se pide nada: una letra coincide con todo y sería una petición por tecla para una respuesta inservible. La búsqueda de emisoras **ordena por lo que se buscó**: el directorio coincide con subcadenas en cualquier parte, así que *techno* devolvía "# TOP 100 CLUB CHARTS - DANCE & DJ MIX RADIO" —real, con "techno" entre sus etiquetas— por delante de toda emisora llamada Techno Algo. El nombre pesa antes que la popularidad y a igual peso gana el nombre más corto; los canales de SomaFM y los mixes de Paradise que coinciden van primero, porque no tienen publicidad y su stream ya se sabe que funciona. La búsqueda del directorio va con `is_https=true`, cacheada por consulta. `lib/paging.js` es puro y tiene test porque tiene un borde fácil de equivocar en un componente: una lista que se encoge —una búsqueda nueva, una emisora desmarcada— no puede dejar el tamaño de página pasado del final, que se ve como "Mostrar más" que no hace nada. Verificado contra los directorios reales: `radio?q=jazz` → Sonic Universe (SomaFM) y después Jazz 24; `radio?q=miami` → Miami Beach Radio, 105 Miami; `podcasts?q=crimen` → 20 programas en español (es, es-ar) y `q=entrenamiento en casa` → 3; `?q=j` no busca. `relevance` y `rankStations` se comprobaron por mutación: sacar el orden hace fallar el test que lo mira de punta a punta.
This commit is contained in:
1 parent
22654c61fc
commit
d5cf0d8d64
16 files changed
+845
-81
No files matched your search
@@ -18,7 +18,7 @@ import {
|
||||
CATEGORIES, STORES, MAX_EPISODES, MAX_SHOWS, categoryList, categoryOf, isSpanish, languageOf,
|
||||
publicHost, safeFeedUrl, parseDuration, decodeEntities, episodeFrom, parseFeed, tagText, tagAttr,
|
||||
get, readCapped, feedLanguage, showsFor, episodesFor, chartEntries, showFrom, mapLimit,
|
||||
clearPodcastCache
|
||||
clearPodcastCache, searchShows, appleSearch, normQuery
|
||||
} from '../podcasts.js';
|
||||
|
||||
/* A stand-in for `fetch`: a body, a status, and the url it ended at. */
|
||||
@@ -329,3 +329,85 @@ test('the pool keeps the order and never throws out of itself', async () => {
|
||||
});
|
||||
assert.deepEqual(out, [2, 4, null, 8, 10]);
|
||||
});
|
||||
|
||||
/* ---------- search ---------- */
|
||||
|
||||
test('a query has to be a query here too', () => {
|
||||
assert.equal(normQuery(' Crimen real '), 'Crimen real', 'the term goes to Apple as typed');
|
||||
assert.equal(normQuery('a'), '');
|
||||
assert.equal(normQuery(null), '');
|
||||
assert.equal(normQuery('x'.repeat(200)).length, 80);
|
||||
});
|
||||
|
||||
test('a search is Apple\'s, one request per storefront, Spanish and no key', async () => {
|
||||
clearPodcastCache();
|
||||
const asked = [];
|
||||
const fetchImpl = async url => {
|
||||
asked.push(url);
|
||||
if (url.includes('/search?')) {
|
||||
const country = new URL(url).searchParams.get('country');
|
||||
return res(JSON.stringify({ results: [{
|
||||
collectionId: country + '1',
|
||||
collectionName: 'Crimen ' + country,
|
||||
artistName: 'Alguien',
|
||||
artworkUrl600: 'https://img.example.com/x.jpg',
|
||||
primaryGenreName: 'True Crime',
|
||||
feedUrl: 'https://feeds.example.com/' + country
|
||||
}] }), { url });
|
||||
}
|
||||
// Both feeds declare Spanish, except the Mexican one, which declares English.
|
||||
if (url === 'https://feeds.example.com/es') return res('<language>es-ES</language>', { status: 206, url });
|
||||
if (url === 'https://feeds.example.com/mx') return res('<language>en</language>', { status: 206, url });
|
||||
return res('', { status: 500, url });
|
||||
};
|
||||
const { query, shows, skipped } = await searchShows('crimen', { fetchImpl });
|
||||
assert.equal(query, 'crimen');
|
||||
assert.deepEqual(shows.map(s => s.name), ['Crimen es'], 'only the Spanish one');
|
||||
assert.equal(shows[0].lang, 'es-es');
|
||||
assert.equal(skipped.language, 1, 'and the other one is counted, not silently missing');
|
||||
assert.equal(skipped.failed, 0);
|
||||
|
||||
// One request per storefront, not one per show: `media=podcast`, the storefront, and `lang=es`.
|
||||
const searches = asked.filter(u => u.includes('/search?'));
|
||||
assert.equal(searches.length, 2);
|
||||
const q = new URL(searches[0]).searchParams;
|
||||
assert.equal(q.get('media'), 'podcast');
|
||||
assert.equal(q.get('term'), 'crimen');
|
||||
assert.equal(q.get('lang'), 'es');
|
||||
assert.deepEqual(searches.map(u => new URL(u).searchParams.get('country')).sort(), ['es', 'mx']);
|
||||
});
|
||||
|
||||
test('a search result goes through the same feed rule as a chart entry', async () => {
|
||||
clearPodcastCache();
|
||||
const fetchImpl = async url => {
|
||||
if (url.includes('/search?')) {
|
||||
return res(JSON.stringify({ results: [
|
||||
{ collectionId: '1', collectionName: 'Bueno', feedUrl: 'https://feeds.example.com/a' },
|
||||
{ collectionId: '2', collectionName: 'Inservible', feedUrl: 'http://feeds.example.com/b' },
|
||||
{ collectionId: '3', collectionName: 'Privado', feedUrl: 'https://10.0.0.9/c' }
|
||||
] }), { url });
|
||||
}
|
||||
return res('<language>es</language>', { status: 206, url });
|
||||
};
|
||||
const { shows } = await searchShows('algo', { fetchImpl });
|
||||
assert.deepEqual(shows.map(s => s.name), ['Bueno'], 'an http feed and a private host are not shows');
|
||||
});
|
||||
|
||||
test('one letter is not a search, and nobody is asked', async () => {
|
||||
clearPodcastCache();
|
||||
let called = 0;
|
||||
const fetchImpl = async () => { called++; return res('{}') };
|
||||
const { shows, query } = await searchShows('c', { fetchImpl });
|
||||
assert.deepEqual(shows, []);
|
||||
assert.equal(query, '');
|
||||
assert.equal(called, 0);
|
||||
// And the storefronts are cached: the same query twice is one request each.
|
||||
const impl = async url => url.includes('/search?')
|
||||
? res(JSON.stringify({ results: [{ collectionId: '1', collectionName: 'X', feedUrl: 'https://feeds.example.com/x' }] }), { url })
|
||||
: res('<language>es</language>', { status: 206, url });
|
||||
let n = 0;
|
||||
const counting = async (url, ...rest) => { if (url.includes('/search?')) n++; return impl(url, ...rest) };
|
||||
await searchShows('comedia', { fetchImpl: counting });
|
||||
await searchShows('comedia', { fetchImpl: counting });
|
||||
assert.equal(n, 2, 'one per storefront, then cached');
|
||||
});
|
||||
Reference in new issue
Block a user