openvibers/openvibe.inventory Commits

Inventory: the home's kind count matches the kinds it shows (said 6 over 4 cards) (#40)

OP OpenVibers committed 29 days ago · e20018c071 · 2 files, +7 −1

**"N items in K kinds" counts the kinds it shows.**

**Found:** while reviewing every home page. inventory.openvibe.network read "70 items in 6 kinds today" above four cards (Voice 46, Name effect 13, Hat 6, Particle effect 5). The two kinds without items are rightly not shown as cards, but they were still counted.

**Change (`server/http/pages.js`):** the lede counts only kinds that have items, the same filter the cards use.

**Test:** `layout.test.js` checks that the number of cards under "What you can collect" equals the kind count in its lede.

Changes

ddiff --git a/server/http/pages.js b/server/http/pages.js
iindex 9d1f11e..c8a62cc 100644
---- a/server/http/pages.js
++++ b/server/http/pages.js
@@@ -96,7 +96,9 @@ function createPageRoutes(ctx) {
body: html`${raw(hero)}
${raw(showcase.features({
title: 'What you can collect',
-- lede: `${plural(defs.length, 'item', 'items')} in ${plural(kinds.length, 'kind', 'kinds')} today. Each kind knows where it shows, so a new kind is all it takes for a new site or game to join.`,
++ // The count is of the kinds shown: an empty kind (no issuer has defined anything in it yet) is neither a card
++ // nor counted, so "in 4 kinds" sits over four cards.
++ lede: `${plural(defs.length, 'item', 'items')} in ${plural(kinds.filter((k) => (byKind.get(k.id) || []).length).length, 'kind', 'kinds')} today. Each kind knows where it shows, so a new kind is all it takes for a new site or game to join.`,
// Kinds that have items, the biggest first; an empty kind waits until an issuer defines something in it.
items: kinds.filter((k) => (byKind.get(k.id) || []).length).sort((a, b) => byKind.get(b.id).length - byKind.get(a.id).length).map((k) => ({ icon: KIND_ICON[k.id] || 'ov:ov', title: `${k.name} · ${(byKind.get(k.id) || []).length}`, text: `${k.description || ''} Shows in ${k.surfaces.map((s) => surfaceLabel(s.surface)).join(', ')}.`, href: `/items?kind=${encodeURIComponent(k.id)}` })),
}))}
ddiff --git a/test/layout.test.js b/test/layout.test.js
iindex e0e11c5..ca77367 100644
---- a/test/layout.test.js
++++ b/test/layout.test.js
@@@ -63,6 +63,10 @@ const BOOST = /<script src="\/shared\/boost\.js\?v=[0-9a-f]{12}" data-main="#mai
assert.ok(r.text.includes('OpenVibe.Inventory'), 'the service name is on the page');
assert.ok(r.text.includes('Your items, on every OpenVibe site.'), 'the tagline is on the page');
assert.ok(r.text.includes('/shared/showcase.css'), 'the showcase stylesheet');
++ // "N items in K kinds" counts the kinds it shows: an empty kind is neither a card nor counted.
++ const collect = (/<section class="sc-sec"[^>]*aria-labelledby="sc-what-you-can-collect"[\s\S]*?<\/section>/.exec(r.text) || [''])[0];
++ const said = /in (\d+) kinds? today/.exec(collect);
++ if (said) assert.strictEqual((collect.match(/class="sc-card"/g) || []).length, Number(said[1]), collect.slice(0, 400));
assert.ok(!r.text.includes('/home/') && !r.text.includes('/mnt/'), 'no local filesystem path on the page');
});