Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions js/popups/popupsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ export function createDetailedListOfPoets(poets, data) {
* @returns {string}
*/
function createGenreString(lookups, poetId) {
const genres = getGenres(lookups, poetId);
const genreNames = genres.map(genre => genre.genre).join(", ");
// genres.csv is one row per citation rather than per genre, so a poet
// attested in the same genre by two sources has two rows. This line names the
// genres a poet worked in and shows none of the citations behind them, so a
// name repeated is only ever a repetition.
const genreNames = [...new Set(getGenres(lookups, poetId).map(genre => genre.genre))].filter(Boolean);
// Blank when a poet has no genres, and also when the ones they have are
// unnamed, which is what reading the joined string off the row did.
if (!genreNames) return "";
return `${genres.length > 1 ? "Genres" : "Genre"}: ${genreNames}<br>`;
if (!genreNames.length) return "";
return `${genreNames.length > 1 ? "Genres" : "Genre"}: ${genreNames.join(", ")}<br>`;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/data-integrity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,13 @@ describe("known data bugs: incomplete or inconsistent fields", () => {
row => filled(row.source_citation) && !(filled(row.source_translation) && filled(row.source_translator))
);
assert.equal(incomplete.length, KNOWN_INCOMPLETE_CITATION_COUNT);
// renderReference() prints `Citation: X: "" (trans. )` for these. This is
// the shape of issues #313 and #329. geopoetCities and genres are clean.
// These used to render `Citation: X: "..." (trans. )`, which is the shape of
// issues #313 and #329, until #356 stopped renderReference() printing a
// credit with nobody in it. Seventeen of the eighteen are Pindar titles and
// are meant to carry no translator, per the December 2015 corrections; the
// eighteenth, Stesandros at Ath. 14.638b, is a real omission. The count is
// still worth pinning, because it is now invisible on the page.
// geopoetCities and genres are clean.
for (const file of CLEAN_CITED_CSVS) {
const bad = raw[file].filter(
row => filled(row.source_citation) && !(filled(row.source_translation) && filled(row.source_translator))
Expand Down
34 changes: 34 additions & 0 deletions tests/popups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { loadInitializedData, ALL_DATES } from "./helpers/loadData.js";
import { calcPlacesPoetCities, calcGeoPoetCities } from "../js/renderMap/calcPoetCities.js";
import { calculatePlacesBubbles, calculateGeoBubbles } from "../js/renderMap/calcBubbles.js";
import { createTravelPopupHtml } from "../js/popups/travelPopups.js";
import { createDetailedListOfPoets } from "../js/popups/popupsCommon.js";

const { data } = loadInitializedData();

Expand Down Expand Up @@ -204,6 +205,39 @@ describe("citation credits", () => {
});
});

describe("the genre line", () => {
// genres.csv is one row per citation rather than per genre, so a poet
// attested in one genre by two sources has two rows. No poet does today —
// the only pair the data ever had was Kinesias 14 and Cinesias 4, and those
// are not merged — so the case is built here rather than found.
const cinesias = data.poets.find(poet => poet.poetDetailName === "Cinesias");
assert.ok(cinesias, "expected Cinesias in poets.csv");
const poetId = cinesias.poetId;

/**
* The same data with one poet's genre list doubled.
* @param {Genre[]} genres
* @returns {string}
*/
function detailFor(genres) {
const doubled = { ...data, genresByPoetId: { ...data.genresByPoetId, [poetId]: genres } };
return createDetailedListOfPoets([{ poetId }], doubled);
}

test("a genre attested by two sources is named once", () => {
const [dithyramb] = data.genresByPoetId[poetId];
const html = detailFor([dithyramb, { ...dithyramb }]);
assert.match(html, /Genre: Dithyramb<br>/);
assert.doesNotMatch(html, /Dithyramb, Dithyramb/, "the genre is named twice");
});

test("distinct genres are all named, and pluralised", () => {
const [dithyramb] = data.genresByPoetId[poetId];
const html = detailFor([dithyramb, { ...dithyramb, genre: "Paean" }]);
assert.match(html, /Genres: Dithyramb, Paean<br>/);
});
});

describe("popup html is well formed enough to render", () => {
test("no popup leaks 'undefined' or 'NaN' into the page", () => {
for (const [view, bubbles] of ALL_VIEWS) {
Expand Down
Loading