"use strict";

var _useReducedMotion = _interopRequireDefault(require("./useReducedMotion"));

var _reactHooks = require("@testing-library/react-hooks");

var _mq = _interopRequireDefault(require("./__mocks__/mq"));

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

var MOTION_MQ = {
  reduced: '(prefers-reduced-motion: reduce)',
  default: '(prefers-reduced-motion: default)'
};
var matchMedia;
describe('useReducedMotion', function () {
  afterEach(function () {
    matchMedia.destroy();
  });
  it('returns true if user preference is to reduce motion', function () {
    matchMedia = new _mq.default(MOTION_MQ.reduced);

    var _renderHook = (0, _reactHooks.renderHook)(function () {
      return (0, _useReducedMotion.default)();
    }),
        result = _renderHook.result;

    expect(result.current).toBe(true);
  });
  it('returns true if user preference is not to reduce motion', function () {
    matchMedia = new _mq.default(MOTION_MQ.default);

    var _renderHook2 = (0, _reactHooks.renderHook)(function () {
      return (0, _useReducedMotion.default)();
    }),
        result = _renderHook2.result;

    expect(result.current).toBe(false);
  });
  it('change result accordingly when user changes motion settings', function () {
    matchMedia = new _mq.default(MOTION_MQ.default);

    var _renderHook3 = (0, _reactHooks.renderHook)(function () {
      return (0, _useReducedMotion.default)();
    }),
        result = _renderHook3.result;

    expect(result.current).toBe(false);
    (0, _reactHooks.act)(function () {
      return matchMedia.updateMediaQuery(MOTION_MQ.reduced);
    });
    expect(result.current).toBe(true);
    (0, _reactHooks.act)(function () {
      return matchMedia.updateMediaQuery(MOTION_MQ.default);
    });
    expect(result.current).toBe(false);
    (0, _reactHooks.act)(function () {
      return matchMedia.updateMediaQuery(MOTION_MQ.reduced);
    });
    expect(result.current).toBe(true);
  });
});