import getPageTitle from './getPageTitle.js';

describe('getPageTitle', () => {
  test('returns title for valid path', () => {
    const result = getPageTitle('/dashboard');
    expect(result).toBeDefined();
  });

  test('returns undefined for non-existent path', () => {
    const result = getPageTitle('/non-existent-path');
    expect(result).toBeUndefined();
  });

  test('handles home path', () => {
    const result = getPageTitle('/');
    expect(result).toBeUndefined();
  });

  test('handles user profile path with pattern', () => {
    const result = getPageTitle('/user-profile/123');
    expect(result).toBe('User Profile Summary');
  });

  test('handles user profile path with different ID', () => {
    const result = getPageTitle('/user-profile/456');
    expect(result).toBe('User Profile Summary');
  });

  test('handles user profile path with large ID', () => {
    const result = getPageTitle('/user-profile/999999');
    expect(result).toBe('User Profile Summary');
  });

  test('does not match invalid user profile paths', () => {
    const result = getPageTitle('/user-profile/abc');
    expect(result).toBeUndefined();
  });

  test('handles empty string path', () => {
    const result = getPageTitle('');
    expect(result).toBeUndefined();
  });

  test('returns MenuName when SubMenuName equals MenuName', () => {
    const result = getPageTitle('/dashboard');
    if (result) {
      expect(typeof result).toBe('string');
    }
  });

  test('returns SubMenuName when different from MenuName', () => {
    const result = getPageTitle('/users');
    if (result) {
      expect(typeof result).toBe('string');
    }
  });

  test('function returns string or undefined', () => {
    const result = getPageTitle('/dashboard');
    expect(['string', 'undefined']).toContain(typeof result);
  });

  test('handles paths with trailing slash', () => {
    const result = getPageTitle('/dashboard/');
    expect(result).toBeUndefined();
  });
});
