import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/AudioPlayer/test/AudioPlayer.spec.jsx",
  _this = this;
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { createRendererWithUniDriver, cleanup, act } from '../../utils/test-utils/unit';
import AudioPlayer from '../AudioPlayer';
import { audioPlayerPrivateDriverFactory } from './AudioPlayer.private.uni.driver';
import { positionToSeconds, secondsToPosition, secondsToISO, MAX_SECONDS } from '../utils';
describe(AudioPlayer.displayName, function () {
  var render = createRendererWithUniDriver(audioPlayerPrivateDriverFactory);
  var src = 'audio-test-file.mp3';
  afterEach(cleanup);
  it('should render', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var _render, driver;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _render = render(/*#__PURE__*/React.createElement(AudioPlayer, {
            src: src,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 23,
              columnNumber: 31
            }
          })), driver = _render.driver;
          _context.t0 = expect;
          _context.next = 4;
          return driver.exists();
        case 4:
          _context.t1 = _context.sent;
          (0, _context.t0)(_context.t1).toBe(true);
        case 6:
        case "end":
          return _context.stop();
      }
    }, _callee);
  })));
  it('should show --:-- when not loaded', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var _render2, driver;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) switch (_context2.prev = _context2.next) {
        case 0:
          _render2 = render(/*#__PURE__*/React.createElement(AudioPlayer, {
            src: src,
            preload: "none",
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 29,
              columnNumber: 31
            }
          })), driver = _render2.driver;
          _context2.t0 = expect;
          _context2.next = 4;
          return driver.timeIndicatorText();
        case 4:
          _context2.t1 = _context2.sent;
          (0, _context2.t0)(_context2.t1).toBe('--:--');
        case 6:
        case "end":
          return _context2.stop();
      }
    }, _callee2);
  })));
  it('should return right time from position', function () {
    var duration = 60;
    expect(positionToSeconds(0, duration)).toBe(0);
    expect(positionToSeconds(25, duration)).toBe(15);
    expect(positionToSeconds(50, duration)).toBe(30);
    expect(positionToSeconds(75, duration)).toBe(45);
    expect(positionToSeconds(100, duration)).toBe(60);
  });
  it('should return right position from time', function () {
    var duration = 60;
    expect(secondsToPosition(0, duration)).toBe(0);
    expect(secondsToPosition(15, duration)).toBe(25);
    expect(secondsToPosition(30, duration)).toBe(50);
    expect(secondsToPosition(45, duration)).toBe(75);
    expect(secondsToPosition(60, duration)).toBe(100);
  });
  it('should return right ISO time from seconds', function () {
    var durationTenMins = 5 * 60;
    var durationUnderHour = 50 * 60;
    var durationOverHour = 30 * 60 * 60;

    // Not loaded
    expect(secondsToISO(0, false)).toBe('--:--');

    // parsing problems
    expect(secondsToISO(Infinity, true, 12)).toBe('0:00');
    expect(secondsToISO(Infinity, true, durationOverHour)).toBe('00:00:00');
    expect(secondsToISO(MAX_SECONDS + 1, true, durationOverHour)).toBe('00:00:00');

    // Under 10 mins duration
    expect(secondsToISO(12, true, durationTenMins)).toBe('0:12');
    expect(secondsToISO(120, true, durationTenMins)).toBe('2:00');

    // Under hour duration
    expect(secondsToISO(12, true, durationUnderHour)).toBe('00:12');
    expect(secondsToISO(120, true, durationUnderHour)).toBe('02:00');
    expect(secondsToISO(1200, true, durationUnderHour)).toBe('20:00');

    // Over hour duration
    expect(secondsToISO(12, true, durationOverHour)).toBe('00:00:12');
    expect(secondsToISO(120, true, durationOverHour)).toBe('00:02:00');
    expect(secondsToISO(1200, true, durationOverHour)).toBe('00:20:00');
    expect(secondsToISO(12000, true, durationOverHour)).toBe('03:20:00');
    expect(secondsToISO(120000, true, durationOverHour)).toBe('09:20:00');
  });
  it('should be focused when focus method called', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
    var playerRef, _render3, driver;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) switch (_context4.prev = _context4.next) {
        case 0:
          playerRef = /*#__PURE__*/React.createRef();
          _render3 = render(/*#__PURE__*/React.createElement(AudioPlayer, {
            ref: playerRef,
            src: src,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 88,
              columnNumber: 31
            }
          })), driver = _render3.driver;
          _context4.t0 = expect;
          _context4.next = 5;
          return driver.isPlayPauseButtonFocused();
        case 5:
          _context4.t1 = _context4.sent;
          (0, _context4.t0)(_context4.t1).toBeFalsy();
          _context4.next = 9;
          return act(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
            return _regeneratorRuntime.wrap(function _callee3$(_context3) {
              while (1) switch (_context3.prev = _context3.next) {
                case 0:
                  playerRef.current.focus();
                case 1:
                case "end":
                  return _context3.stop();
              }
            }, _callee3);
          })));
        case 9:
          _context4.t2 = expect;
          _context4.next = 12;
          return driver.isPlayPauseButtonFocused();
        case 12:
          _context4.t3 = _context4.sent;
          (0, _context4.t2)(_context4.t3).toBeTruthy();
        case 14:
        case "end":
          return _context4.stop();
      }
    }, _callee4);
  })));
  it('should start playing automatically when `autoplay` is `true`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var _render4, driver;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) switch (_context5.prev = _context5.next) {
        case 0:
          _render4 = render(/*#__PURE__*/React.createElement(AudioPlayer, {
            autoplay: true,
            src: src,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 100,
              columnNumber: 31
            }
          })), driver = _render4.driver;
          _context5.next = 3;
          return driver.waitForFileToLoad();
        case 3:
          _context5.t0 = expect;
          _context5.next = 6;
          return driver.isPlayButtonExists();
        case 6:
          _context5.t1 = _context5.sent;
          (0, _context5.t0)(_context5.t1).toBe(true);
        case 8:
        case "end":
          return _context5.stop();
      }
    }, _callee5);
  })));
  it('should render with volume prop without errors', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var _render5, driver;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) switch (_context6.prev = _context6.next) {
        case 0:
          _render5 = render(/*#__PURE__*/React.createElement(AudioPlayer, {
            src: src,
            volume: 0.5,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 107,
              columnNumber: 31
            }
          })), driver = _render5.driver;
          _context6.t0 = expect;
          _context6.next = 4;
          return driver.exists();
        case 4:
          _context6.t1 = _context6.sent;
          (0, _context6.t0)(_context6.t1).toBe(true);
        case 6:
        case "end":
          return _context6.stop();
      }
    }, _callee6);
  })));
  it('should render with volume=0 without errors', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var _render6, driver;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) switch (_context7.prev = _context7.next) {
        case 0:
          _render6 = render(/*#__PURE__*/React.createElement(AudioPlayer, {
            src: src,
            volume: 0,
            __self: _this,
            __source: {
              fileName: _jsxFileName,
              lineNumber: 113,
              columnNumber: 31
            }
          })), driver = _render6.driver;
          _context7.t0 = expect;
          _context7.next = 4;
          return driver.exists();
        case 4:
          _context7.t1 = _context7.sent;
          (0, _context7.t0)(_context7.t1).toBe(true);
        case 6:
        case "end":
          return _context7.stop();
      }
    }, _callee7);
  })));
});