import { renderHook } from '@testing-library/react';
import { useGetScheduleString } from './utils';
describe('useGetScheduleString', function () {
  describe('Schedule strings', function () {
    const createSchedule = (partialSchedule = {}) => ({
      minute: ['*'],
      hour: ['*'],
      dayOfMonth: ['*'],
      month: ['*'],
      dayOfWeek: ['*'],
      ...partialSchedule
    });
    const testSchedules = [{
      schedule: createSchedule({
        minute: [15, 45],
        month: [1, 4, 8, 12]
      }),
      expectedScheduleString: 'Complex schedule',
      hasTimeStandard: false
    }, {
      schedule: createSchedule({
        minute: [1]
      }),
      expectedScheduleString: 'Hourly at 1 minute past the hour',
      hasTimeStandard: false
    }, {
      schedule: createSchedule({
        minute: [5]
      }),
      expectedScheduleString: 'Hourly at 5 minutes past the hour',
      hasTimeStandard: false
    }, {
      schedule: createSchedule({
        hour: [12],
        minute: [30]
      }),
      expectedScheduleString: 'Daily at 12:30',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        dayOfWeek: [1],
        hour: [12],
        minute: [30]
      }),
      expectedScheduleString: 'Weekly on Monday at 12:30',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        dayOfWeek: [1, 2],
        hour: [12],
        minute: [30]
      }),
      expectedScheduleString: 'Weekly on multiple days at 12:30',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        dayOfMonth: [1],
        hour: [6],
        minute: [45]
      }),
      expectedScheduleString: 'Monthly on day 1 at 06:45',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        dayOfMonth: [1, 2],
        hour: [6],
        minute: [45]
      }),
      expectedScheduleString: 'Monthly on days 1, 2 at 06:45',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        month: [1, 4, 7, 10],
        dayOfMonth: [1],
        hour: [1],
        minute: [30]
      }),
      expectedScheduleString: 'Quarterly on day 1 at 01:30',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        month: [1, 4, 7, 10],
        dayOfMonth: [1, 15],
        hour: [1],
        minute: [30]
      }),
      expectedScheduleString: 'Quarterly on days 1, 15 at 01:30',
      hasTimeStandard: true
    }, {
      schedule: createSchedule({
        dayOfMonth: [1],
        month: [6],
        hour: [17],
        minute: [0]
      }),
      expectedScheduleString: 'Yearly on June 1 at 17:00',
      hasTimeStandard: true
    }];
    describe('Default time standard (UTC)', function () {
      testSchedules.forEach(function ({
        schedule,
        expectedScheduleString,
        hasTimeStandard
      }) {
        const expectedString = `${expectedScheduleString}${hasTimeStandard ? ' (UTC)' : ''}`;
        it(`should generate "${expectedString}"`, function () {
          const {
            result
          } = renderHook(() => useGetScheduleString()(schedule));
          expect(result.current).toBe(`${expectedString}`);
        });
      });
    });
    describe('Alternate time standard (EST)', function () {
      testSchedules.forEach(function ({
        schedule,
        expectedScheduleString,
        hasTimeStandard
      }) {
        const expectedString = `${expectedScheduleString}${hasTimeStandard ? ' (EST)' : ''}`;
        it(`should generate "${expectedString}"`, function () {
          const {
            result
          } = renderHook(() => useGetScheduleString()(schedule, {
            timeStandardString: '(EST)'
          }));
          expect(result.current).toBe(`${expectedString}`);
        });
      });
    });
    describe('No time standard (locale time)', function () {
      testSchedules.forEach(function ({
        schedule,
        expectedScheduleString
      }) {
        it(`should generate "${expectedScheduleString}"`, function () {
          const {
            result
          } = renderHook(() => useGetScheduleString()(schedule, {
            timeStandardString: null
          }));
          expect(result.current).toBe(expectedScheduleString);
        });
      });
    });
  });
});