"use strict";

var _jsxRuntime = require("react/jsx-runtime");

var _enzyme = require("enzyme");

var _MediaPlayer = _interopRequireDefault(require("../MediaPlayer"));

var _SliderModule = _interopRequireDefault(require("../../Slider/Slider.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var getNode = function getNode(slider) {
  return slider.find("div.".concat(_SliderModule["default"].slider));
};

var blur = function blur(slider) {
  return getNode(slider).simulate('blur');
};

var activate = function activate(slider) {
  return getNode(slider).simulate('keyup', {
    keyCode: 13
  });
};

describe('MediaPlayer', function () {
  function getSourceNode(wrapper) {
    return wrapper.find('Media').instance().media;
  }

  var audioFiles = ['https://sampleswap.org/mp3/artist/254731/BossPlayer_Your-Right-Here-160.mp3', 'https://sampleswap.org/mp3/artist/78152/HiatusManJBanner_Show-Stopper-160.mp3', 'https://sampleswap.org/mp3/artist/47067/DJ-Masque_Oceanic-Dawn-160.mp3', 'https://sampleswap.org/mp3/artist/26546/benzoul_lovevoodoo-160.mp3', 'https://sampleswap.org/mp3/artist/19139/MarkNine_In-my-Place-160.mp3', 'https://sampleswap.org/mp3/artist/47067/DJ-Masque_Dont-Forget-To-Be-Yourself-160.mp3'];
  describe('changing sources', function () {
    test('should use the same node when changing the `source`', function () {
      var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_MediaPlayer["default"], {
        children: audioFiles.map(function (audioFile, index) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)("source", {
            src: audioFile,
            type: "audio/mp3"
          }, index);
        })
      }));
      var expected = getSourceNode(subject);
      subject.setProps({
        source: ['abc.mp3']
      });
      var actual = getSourceNode(subject);
      expect(actual).toBe(expected);
    });
    test('should use same `source` when removing `source`', function () {
      var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_MediaPlayer["default"], {
        children: audioFiles.map(function (audioFile, index) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)("source", {
            src: audioFile,
            type: "audio/mp3"
          }, index);
        })
      }));
      var expected = getSourceNode(subject);
      subject.setProps({
        source: undefined // eslint-disable-line no-undefined

      });
      var actual = getSourceNode(subject);
      expect(actual).toBe(expected);
    });
    test('should reuse source node over two changes', function () {
      var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_MediaPlayer["default"], {
        children: audioFiles.map(function (audioFile, index) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)("source", {
            src: audioFile,
            type: "audio/mp3"
          }, index);
        })
      }));
      var source = getSourceNode(subject);
      subject.setProps({
        source: ['abc.mp3']
      });
      expect(getSourceNode(subject)).toBe(source);
      subject.setProps({
        source: ['def.mp3']
      });
      expect(getSourceNode(subject)).toBe(source);
    });
    test('should activate the mediaPlayer slider on enter keyup', function () {
      var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_MediaPlayer["default"], {
        children: audioFiles.map(function (audioFile, index) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)("source", {
            src: audioFile,
            type: "audio/mp3"
          }, index);
        })
      }));
      activate(subject);
      var expected = 'active';
      var actual = subject.find('Slider').prop('active') ? 'active' : 'not active';
      expect(actual).toBe(expected);
    });
    test('should deactivate the mediaPlayer slider on blur', function () {
      var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_MediaPlayer["default"], {
        children: audioFiles.map(function (audioFile, index) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)("source", {
            src: audioFile,
            type: "audio/mp3"
          }, index);
        })
      }));
      activate(subject);
      blur(subject);
      var expected = 'not active';
      var actual = subject.find('Slider').prop('active') ? 'active' : 'not active';
      expect(actual).toBe(expected);
    });
  });
});