Move Commander basic-land checks and deck aggregate metrics into lib/deck-builder-stats.js with unit tests; render the summary row via DeckBuilderStatsBar to shrink the page god-component. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { computeDeckStats, isBasicLand, BASIC_LAND_NAMES } from '../../lib/deck-builder-stats.js';
|
|
|
|
describe('isBasicLand', () => {
|
|
it('returns true for each basic land name', () => {
|
|
for (const name of BASIC_LAND_NAMES) {
|
|
expect(isBasicLand({ name })).toBe(true);
|
|
}
|
|
});
|
|
|
|
it('returns false for non-basic cards', () => {
|
|
expect(isBasicLand({ name: 'Lightning Bolt' })).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('computeDeckStats', () => {
|
|
it('returns zeros for an empty deck', () => {
|
|
expect(computeDeckStats([])).toEqual({
|
|
totalCards: 0,
|
|
avgCmc: 0,
|
|
colorCounts: {},
|
|
typeCounts: {},
|
|
});
|
|
});
|
|
|
|
it('quantity-weights CMC and parses JSON colors', () => {
|
|
const stats = computeDeckStats([
|
|
{ quantity: 2, cmc: 3, colors: '["R","G"]', card_type: 'Creature — Elf' },
|
|
{ quantity: 1, cmc: 1, colors: '["R"]', card_type: 'Instant' },
|
|
]);
|
|
expect(stats.totalCards).toBe(3);
|
|
expect(stats.avgCmc).toBe('2.3');
|
|
expect(stats.colorCounts).toEqual({ R: 3, G: 2 });
|
|
expect(stats.typeCounts.Creature).toBe(2);
|
|
expect(stats.typeCounts.Instant).toBe(1);
|
|
});
|
|
});
|