import {
  describe,
  expect,
  it
} from 'vitest';

import { canStepLightbox, stepLightboxIndex } from './chat-message-lightbox.rules';

describe('chat-message-lightbox rules', () => {
  it('steps forward and backward within bounds', () => {
    expect(stepLightboxIndex(1, 1, 3)).toBe(2);
    expect(stepLightboxIndex(1, -1, 3)).toBe(0);
  });

  it('returns null when stepping past the ends', () => {
    expect(stepLightboxIndex(0, -1, 3)).toBeNull();
    expect(stepLightboxIndex(2, 1, 3)).toBeNull();
  });

  it('returns null when there is only one image', () => {
    expect(stepLightboxIndex(0, 1, 1)).toBeNull();
  });

  it('reports whether a step is available', () => {
    expect(canStepLightbox(0, -1, 3)).toBe(false);
    expect(canStepLightbox(0, 1, 3)).toBe(true);
    expect(canStepLightbox(2, 1, 3)).toBe(false);
  });
});
