import { describe, it, expect } from 'vitest';
import { stepRegion } from './regionNavigation';

describe('stepRegion', () => {
	const ids = ['a', 'b', 'c'];

	it('returns null for an empty list', () => {
		expect(stepRegion([], null, 1)).toBe(null);
		expect(stepRegion([], 'a', -1)).toBe(null);
	});

	it('steps forward from the middle', () => {
		expect(stepRegion(ids, 'a', 1)).toBe('b');
		expect(stepRegion(ids, 'b', 1)).toBe('c');
	});

	it('steps backward from the middle', () => {
		expect(stepRegion(ids, 'c', -1)).toBe('b');
		expect(stepRegion(ids, 'b', -1)).toBe('a');
	});

	it('wraps forward past the last region to the first', () => {
		expect(stepRegion(ids, 'c', 1)).toBe('a');
	});

	it('wraps backward past the first region to the last', () => {
		expect(stepRegion(ids, 'a', -1)).toBe('c');
	});

	it('lands on the first region when entering fresh (no active) going forward', () => {
		expect(stepRegion(ids, null, 1)).toBe('a');
	});

	it('lands on the last region when entering fresh (no active) going backward', () => {
		expect(stepRegion(ids, null, -1)).toBe('c');
	});

	it('treats an unknown active id as a fresh entry', () => {
		expect(stepRegion(ids, 'zzz', 1)).toBe('a');
		expect(stepRegion(ids, 'zzz', -1)).toBe('c');
	});

	it('returns the single region for both directions (wrap of length 1)', () => {
		expect(stepRegion(['only'], 'only', 1)).toBe('only');
		expect(stepRegion(['only'], 'only', -1)).toBe('only');
		expect(stepRegion(['only'], null, 1)).toBe('only');
	});
});
