"use strict";

var _util = require("@enact/core/util");
var _DurationFmt = _interopRequireDefault(require("ilib/lib/DurationFmt"));
var _util2 = require("../util");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var memoGetDurFmt = (0, _util.memoize)(function /* locale */
() {
  return new _DurationFmt["default"]({
    length: 'medium',
    style: 'clock',
    useNative: false
  });
});
var getDurFmt = function getDurFmt(locale) {
  if (typeof window === 'undefined') return null;
  return memoGetDurFmt(locale);
};
describe('util', function () {
  describe('secondsToPeriod', function () {
    test('should return String formatted for use in a `datetime` field of a `<time>` tag', function () {
      var value = 10;
      var expected = "P10S";
      var actual = (0, _util2.secondsToPeriod)(value);
      expect(actual).toEqual(expected);
    });
  });
  describe('secondsToTime', function () {
    test('should return hour unit string when seconds is 3600 sec or more and includeHour is true', function () {
      var seconds = 4850;
      var expected = '1:20:50';
      var actual = (0, _util2.secondsToTime)(seconds, getDurFmt('en'), {
        includeHour: true
      });
      expect(actual).toEqual(expected);
    });
    test('should return hour unit string as 00 when seconds is less than 3600 sec and includeHour is true', function () {
      var seconds = 100;
      var expected = '00:01:40';
      var actual = (0, _util2.secondsToTime)(seconds, getDurFmt('en'), {
        includeHour: true
      });
      expect(actual).toEqual(expected);
    });
    test('should not return hour unit string when seconds is less than 3600 sec and includeHour is false', function () {
      var seconds = 100;
      var expected = '01:40';
      var actual = (0, _util2.secondsToTime)(seconds, getDurFmt('en'), {
        includeHour: false
      });
      expect(actual).toEqual(expected);
    });
    test('should return 00:00:00 when instance of a `ilib.DurationFmt` object is null and includeHour is true', function () {
      var seconds = 100;
      var expected = '00:00:00';
      var actual = (0, _util2.secondsToTime)(seconds, null, {
        includeHour: true
      });
      expect(actual).toEqual(expected);
    });
    test('should return 00:00 when instance of a `ilib.DurationFmt` object is null and includeHour is false', function () {
      var seconds = 100;
      var expected = '00:00';
      var actual = (0, _util2.secondsToTime)(seconds, null, {
        includeHour: false
      });
      expect(actual).toEqual(expected);
    });
  });
});