"use strict";

var Utils = _interopRequireWildcard(require("../utils"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
describe('Menu Utils - getSharedProps', function () {
  test('successfully maps', function () {
    var props = {
      someStyletronProps: 'styletron',
      normalProps: 'normal'
    };
    var mapper = {
      someStyletronProps: true
    };
    expect(Utils.getSharedProps(props, mapper)).toEqual({
      $someStyletronProps: 'styletron',
      normalProps: 'normal'
    });
  });
});
describe('Menu Utils - scrollItemIntoView', function () {
  test('scrolling down', function () {
    var mockNode = {
      current: {
        getBoundingClientRect: jest.fn().mockReturnValue({
          bottom: 100
        }).mockReturnValueOnce({
          bottom: 0
        }),
        scrollIntoView: jest.fn()
      }
    };
    var mockParentNode = {
      current: {
        getBoundingClientRect: jest.fn().mockReturnValue({
          bottom: 50,
          height: 50
        }),
        scrollHeight: 50,
        scrollTop: 100
      }
    }; // First call

    Utils.scrollItemIntoView({
      // $FlowFixMe
      node: mockNode,
      // $FlowFixMe
      parentNode: mockParentNode
    });
    expect(mockNode.current.scrollIntoView).not.toHaveBeenCalled(); // Subsequent calls

    Utils.scrollItemIntoView({
      // $FlowFixMe
      node: mockNode,
      // $FlowFixMe
      parentNode: mockParentNode
    });
    expect(mockNode.current.scrollIntoView).toHaveBeenCalledWith(false); // Last item

    Utils.scrollItemIntoView({
      // $FlowFixMe
      node: mockNode,
      // $FlowFixMe
      parentNode: mockParentNode,
      isLast: true
    });
    expect(mockParentNode.current.scrollTop).toBe(0);
  });
  test('scrolling up', function () {
    var mockNode = {
      current: {
        getBoundingClientRect: jest.fn().mockReturnValue({
          top: 0
        }).mockReturnValueOnce({
          top: 100
        }),
        scrollIntoView: jest.fn()
      }
    };
    var mockParentNode = {
      current: {
        getBoundingClientRect: jest.fn().mockReturnValue({
          top: 50
        }),
        scrollTop: 100
      }
    }; // First call

    Utils.scrollItemIntoView({
      // $FlowFixMe
      node: mockNode,
      // $FlowFixMe
      parentNode: mockParentNode
    });
    expect(mockNode.current.scrollIntoView).not.toHaveBeenCalled(); // Subsequent calls

    Utils.scrollItemIntoView({
      // $FlowFixMe
      node: mockNode,
      // $FlowFixMe
      parentNode: mockParentNode
    });
    expect(mockNode.current.scrollIntoView).toHaveBeenCalled();
    expect(mockNode.current.scrollIntoView.mock.calls[0][0]).toBe(undefined); // First item

    Utils.scrollItemIntoView({
      // $FlowFixMe
      node: mockNode,
      // $FlowFixMe
      parentNode: mockParentNode,
      isFirst: true
    });
    expect(mockParentNode.current.scrollTop).toBe(0);
  });
});