33 lines
1.6 KiB
TypeScript
33 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { dropIndex } from '../../src/editor/tile/PictureStrip';
|
||
|
||
/**
|
||
* Reordering the pictures of a tile by dragging a row (#118). The index the move command
|
||
* takes counts in the list without the dragged row, which is where the off-by-ones live.
|
||
*/
|
||
describe('dropping a picture row', () => {
|
||
it('takes the place of the row it is dropped on', () => {
|
||
expect(dropIndex(0, { at: 'onto', targetId: '1' }, 3)).toBe(1);
|
||
expect(dropIndex(2, { at: 'onto', targetId: '0' }, 3)).toBe(0);
|
||
// Dropping a row on itself is nothing to do – which is also what the list reports as no spot.
|
||
expect(dropIndex(1, { at: 'onto', targetId: '1' }, 3)).toBe(1);
|
||
});
|
||
|
||
it('counts a gap in the list the row has already left', () => {
|
||
// Downwards: the gap below row 1 is index 1 once row 0 is out of the way.
|
||
expect(dropIndex(0, { at: 'after', targetId: '1' }, 3)).toBe(1);
|
||
expect(dropIndex(0, { at: 'before', targetId: '2' }, 3)).toBe(1);
|
||
// Upwards nothing shifts: the gap above row 0 stays index 0.
|
||
expect(dropIndex(2, { at: 'before', targetId: '0' }, 3)).toBe(0);
|
||
expect(dropIndex(2, { at: 'after', targetId: '0' }, 3)).toBe(1);
|
||
expect(dropIndex(1, { at: 'end' }, 3)).toBe(2);
|
||
});
|
||
|
||
it('refuses a row or a target that is not in the list', () => {
|
||
expect(dropIndex(-1, { at: 'end' }, 3)).toBe(-1);
|
||
expect(dropIndex(3, { at: 'end' }, 3)).toBe(-1);
|
||
expect(dropIndex(0, { at: 'onto', targetId: '9' }, 3)).toBe(-1);
|
||
expect(dropIndex(0, { at: 'before', targetId: 'nonsense' }, 3)).toBe(-1);
|
||
});
|
||
});
|