import {
  getDateAsString,
  getTimeAsString,
  getTimeFromString,
  lowerFirstLetter,
  setColorOpacity,
} from './stringHelpers';

describe('lowerFirstLetter', () => {
  it('Name with multiple characters', () => {
    const expected = 'karel';
    const given = 'Karel';
    expect(lowerFirstLetter(given)).toEqual(expected);
  });

  it('Name with none characters', () => {
    const expected = '';
    const given = '';
    expect(lowerFirstLetter(given)).toEqual(expected);
  });
});

describe('getDateAsString', () => {
  it('Date with time', () => {
    const expected = '1.2.2021 12:00';
    const given = new Date(2021, 1, 1, 12, 0, 0);
    expect(getDateAsString(given, true)).toEqual(expected);
  });

  it('Date without time', () => {
    const expected = '1.2.2021';
    const given = new Date(2021, 1, 1, 12, 0, 0);
    expect(getDateAsString(given)).toEqual(expected);
  });
});

describe('getTimeAsString', () => {
  it('Time with minutes', () => {
    const expected = 'PT12H30M';
    const given = new Date(2021, 1, 1, 12, 30, 0);
    expect(getTimeAsString(given)).toEqual(expected);
  });

  it('Time without minutes', () => {
    const expected = 'PT12H';
    const given = new Date(2021, 1, 1, 12, 0, 0);
    expect(getTimeAsString(given)).toEqual(expected);
  });
});

describe('getTimeFromString', () => {
  it('Time with minutes', () => {
    const expected = new Date(2021, 1, 1, 12, 30, 0);
    const given = 'PT12H30M';
    expect(getTimeFromString(given).getHours()).toEqual(expected.getHours());
    expect(getTimeFromString(given).getMinutes()).toEqual(expected.getMinutes());
  });

  it('Time without minutes', () => {
    const expected = new Date(2021, 1, 1, 12, 0, 0);
    const given = 'PT12H';
    expect(getTimeFromString(given).getHours()).toEqual(expected.getHours());
    expect(getTimeFromString(given).getMinutes()).toEqual(expected.getMinutes());
  });
});

describe('setColorOpacity', () => {
  it('Opacity < 1', () => {
    const expected = '#ffffff7f';
    const given = '#ffffff';
    expect(setColorOpacity(given, 0.5)).toEqual(expected);
  });

  it('Opacity > 1', () => {
    const expected = '#ffffff4fb';
    const given = '#ffffff';
    expect(setColorOpacity(given, 5)).toEqual(expected);
  });
});
