const ControlArea = require('./control-area');

const building2016 = { codeYear: 2016, fireSuppressionCoverage: true };
const building2001 = { codeYear: 2001, fireSuppressionCoverage: true };

describe('Control Area', () => {
  it('should assign occupancy B based on room occupancies of A', () => {
    const area = new ControlArea({
      rooms: [{ occupancy: 'A' }, { occupancy: 'A' }],
    });
    expect(area.occupancy).toEqual('B');
  });

  it('should assign occupancy B based on room occupancies of B, L, S, H3', () => {
    const area = new ControlArea(
      {
        rooms: [
          { occupancy: 'L' },
          { occupancy: 'B' },
          { occupancy: 'M' },
          { occupancy: 'L' },
          { occupancy: 'S' },
          { occupancy: 'H3' },
        ],
      },
      building2016,
    );
    expect(area.occupancy).toEqual('B');
  });

  it('should assign occupancy L based on room occupancies of L & M', () => {
    const area = new ControlArea(
      {
        isOutdoor: false,
        rooms: [{ occupancy: 'L' }, { occupancy: 'M' }, { occupancy: 'L' }],
      },
      building2016,
    );
    expect(area.occupancy).toEqual('L');
  });

  it('should assign occupancy B based on room occupancies of L without surpression coverage', () => {
    const area = new ControlArea(
      {
        isOutdoor: false,
        rooms: [{ occupancy: 'L' }, { occupancy: 'L' }],
      },
      { codeYear: 2016, fireSuppressionCoverage: false },
    );
    expect(area.occupancy).toEqual('B');
  });

  it('should assign occupancy M based on room occupancies of M & H3', () => {
    const area = new ControlArea(
      {
        rooms: [{ occupancy: 'M' }, { occupancy: 'H3' }],
      },
      building2016,
    );
    expect(area.occupancy).toEqual('M');
  });

  it('should assign occupancy H8 based on 2001 code year', () => {
    const area = new ControlArea(
      {
        rooms: [{ occupancy: 'H8' }],
      },
      building2001,
    );
    expect(area.occupancy).toEqual('H8');
  });

  it('should assign occupancy B based on 2001 code year and room occupancies of B & H8', () => {
    const area = new ControlArea(
      {
        rooms: [{ occupancy: 'H8' }, { occupancy: 'B' }],
      },
      building2001,
    );
    expect(area.occupancy).toEqual('B');
  });

  it('should assign occupancy B for area with no rooms', () => {
    const area = new ControlArea({
      rooms: [],
    });
    expect(area.occupancy).toEqual('B');
  });

  it('should default rooms to possible occupancies based on code year', () => {
    const area = new ControlArea(
      {
        rooms: [{ occupancy: 'H8' }, { occupancy: 'FOO' }],
      },
      building2016,
    );
    expect(area.occupancy).toEqual('B');
  });

  it('should default H8 to B when outdoor', () => {
    const area = new ControlArea(
      {
        isOutdoor: true,
        rooms: [{ occupancy: 'H8' }],
      },
      building2001,
    );
    expect(area.occupancy).toEqual('B');
  });
});
