import { formatName } from './format-name.component';

describe('formatName', () => {
  it('should format full name with first and last name', () => {
    // Arrange
    const input = {
      firstName: 'John',
      lastName: 'Doe',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('Doe John');
  });

  it('should format name with organisation and full name', () => {
    // Arrange
    const input = {
      firstName: 'John',
      lastName: 'Doe',
      organisationName: 'Acme Corp',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('Acme Corp - Doe John');
  });

  it('should format with only organisation name', () => {
    // Arrange
    const input = {
      organisationName: 'Acme Corp',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('Acme Corp');
  });

  it('should format with only last name', () => {
    // Arrange
    const input = {
      lastName: 'Doe',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('Doe');
  });

  it('should format with only first name', () => {
    // Arrange
    const input = {
      firstName: 'John',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('John');
  });

  it('should return empty string when all inputs are undefined', () => {
    // Arrange
    const input = {};

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('');
  });

  it('should return empty string when all inputs are empty strings', () => {
    // Arrange
    const input = {
      firstName: '',
      lastName: '',
      organisationName: '',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('');
  });

  it('should format with organisation and only last name', () => {
    // Arrange
    const input = {
      lastName: 'Doe',
      organisationName: 'Acme Corp',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('Acme Corp - Doe');
  });

  it('should format with organisation and only first name', () => {
    // Arrange
    const input = {
      firstName: 'John',
      organisationName: 'Acme Corp',
    };

    // Act
    const result = formatName(input);

    // Assert
    expect(result).toBe('Acme Corp - John');
  });
});
