import { matchActivePath } from './matchActivePath';

describe('matchActivePath', () => {
  const items = ['/nurse', '/nurse/requests', '/nurse/visits'];

  it('picks the longest matching prefix, not the root', () => {
    expect(matchActivePath('/nurse/requests', items)).toBe('/nurse/requests');
  });

  it('matches a nested route under a shorter item', () => {
    expect(matchActivePath('/nurse/requests/42', items)).toBe('/nurse/requests');
  });

  it('falls back to the root item on the root route', () => {
    expect(matchActivePath('/nurse', items)).toBe('/nurse');
  });

  it('never matches a sibling route that merely shares a prefix string', () => {
    expect(matchActivePath('/nurse-other', items)).toBeUndefined();
  });

  it('treats "/" as an exact match only', () => {
    expect(matchActivePath('/bookings', ['/', '/bookings'])).toBe('/bookings');
    expect(matchActivePath('/', ['/', '/bookings'])).toBe('/');
  });

  it('returns undefined when nothing matches', () => {
    expect(matchActivePath('/admin', items)).toBeUndefined();
  });

  it('ignores undefined paths in the candidate list', () => {
    expect(matchActivePath('/nurse/visits', [undefined, ...items])).toBe('/nurse/visits');
  });
});
