* card-interactions.test.js: group delete tests used `.dialog-ok` (class selector) but the button has `id="dialog-ok"`. querySelector returned null, the click was skipped, the dialog stayed open and blocked every downstream test. Fixed to getElementById. * runner.js closeAll(): added #dialog, #bucket-super-popover (remove), and #gitea-overlay to the cleanup list. A failed test that leaves any of these open no longer poisons the rest of the suite. * runner.js copy handler: when there are failures or flaky tests, the "copy" button now builds the clipboard text from lastResults — only failed + flaky lines (suite name, test name, timing, error, original error for retried). When everything passed, copies the full output as before. lastResults is set in renderResults(). * bucket-context.test.js: move-left test used `[data-bucket]` to find user bucket tabs, which misses super-bucket tiles (they carry `data-bucket-super`). Changed to `[data-bucket-drag]` which is on both regular and super-bucket tiles but not on fixed filters. * context-menu.test.js: make-ticket pre-fill assertion now polls up to 2s for the title input to be populated (async openCreateForm repo-fetch was racing against the immediate assertion). * card-join.test.js: clickJoin sleep bumped from 400ms → 800ms. joinSelectedCards does 3+ serial API calls (fetch bodies, PATCH winner, N×DELETE losers, _reloadAll) which sometimes exceeded the old 400ms window on slow runs. * Runner cache: RUNNER_V bumped from ?v=2 → ?v=3 in loader.js + all 42 test files so the browser picks up the new runner.js content (copy handler, closeAll, retry progress bar) without a hard reload. super-buckets: remember last selection per group * buckets.js: module-scope lastSuperSelection Map tracks the last active member per super-bucket parent. Updated in renderBar() whenever activeBucket matches a group member. tileFor() uses it as a fallback when the user is on a different bucket — the tile shows the last-picked child's name and color instead of reverting to the parent. The dropdown popover also highlights the last selection when no member is currently active. chore: bump version to 0.9.11 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
115 lines
4.1 KiB
JavaScript
115 lines
4.1 KiB
JavaScript
import { describe, it, expect } from './runner.js?v=3';
|
|
import { state, parseTags, sortedCards, getChildren, getGroupCards, getRecent, markRecent, getFavorites, toggleFavorite, isFavorite } from '../../js/modules/state.js';
|
|
|
|
describe('State: parseTags', () => {
|
|
it('splits comma-separated tags', () => {
|
|
expect(parseTags({ tags: 'alpha,beta,gamma' })).toEqual(['alpha', 'beta', 'gamma']);
|
|
});
|
|
|
|
it('handles empty tags', () => {
|
|
expect(parseTags({ tags: '' })).toEqual([]);
|
|
expect(parseTags({ tags: null })).toEqual([]);
|
|
expect(parseTags({})).toEqual([]);
|
|
});
|
|
|
|
it('handles single tag', () => {
|
|
expect(parseTags({ tags: 'solo' })).toEqual(['solo']);
|
|
});
|
|
|
|
it('handles hierarchical tags', () => {
|
|
expect(parseTags({ tags: 'parent/child,other' })).toEqual(['parent/child', 'other']);
|
|
});
|
|
});
|
|
|
|
describe('State: getChildren / getGroupCards', () => {
|
|
it('getChildren returns child cards', () => {
|
|
const parent = state.cards.find(c => {
|
|
return state.cards.some(ch => ch.parent_id == c.id);
|
|
});
|
|
if (!parent) return; // no groups
|
|
const children = getChildren(parent.id);
|
|
expect(children.length).toBeGreaterThan(0);
|
|
for (const ch of children) expect(ch.parent_id).toBe(parent.id);
|
|
});
|
|
|
|
it('getChildren returns empty for non-parent', () => {
|
|
const orphan = state.cards.find(c => !c.parent_id && !state.cards.some(ch => ch.parent_id == c.id));
|
|
if (!orphan) return;
|
|
expect(getChildren(orphan.id).length).toBe(0);
|
|
});
|
|
|
|
it('getGroupCards returns parent + children', () => {
|
|
const parent = state.cards.find(c => state.cards.some(ch => ch.parent_id == c.id));
|
|
if (!parent) return;
|
|
const group = getGroupCards(parent);
|
|
expect(group.length).toBeGreaterThan(1);
|
|
expect(group[0].id).toBe(parent.id);
|
|
});
|
|
|
|
it('getGroupCards returns null for solo card', () => {
|
|
const solo = state.cards.find(c => !c.parent_id && !state.cards.some(ch => ch.parent_id == c.id));
|
|
if (!solo) return;
|
|
expect(getGroupCards(solo)).toBe(null);
|
|
});
|
|
});
|
|
|
|
describe('State: Recent Cards', () => {
|
|
it('markRecent adds card to recent list', () => {
|
|
const id = 99999;
|
|
markRecent(id);
|
|
expect(getRecent()).toContain(String(id));
|
|
// Clean up
|
|
const r = getRecent().filter(i => i != id);
|
|
localStorage.setItem('hyprcrd-recent', JSON.stringify(r));
|
|
});
|
|
|
|
it('markRecent puts card at front', () => {
|
|
markRecent(88881);
|
|
markRecent(88882);
|
|
const r = getRecent();
|
|
expect(r[0]).toBe('88882');
|
|
expect(r[1]).toBe('88881');
|
|
// Clean up
|
|
const cleaned = r.filter(i => i != '88881' && i != '88882');
|
|
localStorage.setItem('hyprcrd-recent', JSON.stringify(cleaned));
|
|
});
|
|
|
|
it('markRecent deduplicates', () => {
|
|
markRecent(77771);
|
|
markRecent(77772);
|
|
markRecent(77771);
|
|
const r = getRecent();
|
|
const count = r.filter(i => i == '77771').length;
|
|
expect(count).toBe(1);
|
|
expect(r[0]).toBe('77771');
|
|
const cleaned = r.filter(i => i != '77771' && i != '77772');
|
|
localStorage.setItem('hyprcrd-recent', JSON.stringify(cleaned));
|
|
});
|
|
|
|
it('markRecent caps at 10', () => {
|
|
for (let i = 0; i < 15; i++) markRecent(60000 + i);
|
|
expect(getRecent().length).toBeLessThan(12);
|
|
const cleaned = getRecent().filter(i => parseInt(i) < 60000 || parseInt(i) > 60020);
|
|
localStorage.setItem('hyprcrd-recent', JSON.stringify(cleaned));
|
|
});
|
|
});
|
|
|
|
describe('State: Favorites', () => {
|
|
it('toggleFavorite adds and removes', () => {
|
|
const id = 55555;
|
|
const wasFav = isFavorite(id);
|
|
toggleFavorite(id);
|
|
expect(isFavorite(id)).toBe(!wasFav);
|
|
toggleFavorite(id);
|
|
expect(isFavorite(id)).toBe(wasFav);
|
|
});
|
|
|
|
it('isFavorite returns boolean', () => {
|
|
expect(typeof isFavorite(1)).toBe('boolean');
|
|
});
|
|
|
|
it('getFavorites returns array', () => {
|
|
expect(Array.isArray(getFavorites())).toBe(true);
|
|
});
|
|
});
|