// The order of a section, proposed with a list one clicks (Yvv, 2026-10-30: // « une simple liste clipable »): an article, then its new place; or its arrows. import { describe, expect, it } from 'vitest'; import { moved, place, sameOrder, step } from '../../src/lib/order'; const section = ['T1', 'E1', 'E2', 'E3']; describe('the order of a section, by clicks', () => { it('an article chosen takes the place clicked, the others close up', () => { expect(place(section, 'E2', 'T1')).toEqual(['E2', 'T1', 'E1', 'E3']); expect(place(section, 'T1', 'E3')).toEqual(['E1', 'E2', 'E3', 'T1']); expect(place(section, 'E1', 'E2')).toEqual(['T1', 'E2', 'E1', 'E3']); // Its own place, or an article not in the list: nothing moves. expect(place(section, 'E1', 'E1')).toEqual(section); expect(place(section, 'X9', 'E1')).toEqual(section); expect(place(section, 'E1', 'X9')).toEqual(section); }); it('the arrows move one place, never beyond the ends', () => { expect(step(section, 'E2', -1)).toEqual(['T1', 'E2', 'E1', 'E3']); expect(step(section, 'E2', 1)).toEqual(['T1', 'E1', 'E3', 'E2']); expect(step(section, 'T1', -1)).toEqual(section); expect(step(section, 'E3', 1)).toEqual(section); }); it('a list never loses nor doubles an article', () => { const once = place(step(place(section, 'E3', 'T1'), 'T1', 1), 'E1', 'E3'); expect([...once].sort()).toEqual([...section].sort()); }); it('tells the order in force from another, and what moved', () => { expect(sameOrder(section, [...section])).toBe(true); expect(sameOrder(section, step(section, 'E1', 1))).toBe(false); expect(sameOrder(section, section.slice(1))).toBe(false); expect([...moved(section, ['E1', 'T1', 'E2', 'E3'])].sort()).toEqual(['E1', 'T1']); expect(moved(section, section).size).toBe(0); }); });