"use strict";

var _utils = require("../utils.js");

/*
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.
*/

/* eslint-disable flowtype/no-weak-types */
describe('Popover utils', function () {
  describe('getOppositePosition', function () {
    test('getOppositePosition should return opposite positions', function () {
      expect((0, _utils.getOppositePosition)('top')).toBe('bottom');
      expect((0, _utils.getOppositePosition)('bottom')).toBe('top');
      expect((0, _utils.getOppositePosition)('left')).toBe('right');
      expect((0, _utils.getOppositePosition)('right')).toBe('left');
    });
  });
  describe('capitalize', function () {
    test('capitalize should capitalize input strings', function () {
      expect((0, _utils.capitalize)('top')).toBe('Top');
      expect((0, _utils.capitalize)('left')).toBe('Left');
      expect((0, _utils.capitalize)('')).toBe('');
      expect((0, _utils.capitalize)('topLeft')).toBe('TopLeft');
    });
  });
  describe('toPopperPlacement', function () {
    test('toPopperPlacement should convert from popover placements to popper placements', function () {
      expect((0, _utils.toPopperPlacement)('rightTop')).toBe('right-start');
      expect((0, _utils.toPopperPlacement)('right')).toBe('right');
      expect((0, _utils.toPopperPlacement)('rightBottom')).toBe('right-end');
      expect((0, _utils.toPopperPlacement)('topLeft')).toBe('top-start');
      expect((0, _utils.toPopperPlacement)('top')).toBe('top');
      expect((0, _utils.toPopperPlacement)('topRight')).toBe('top-end');
    });
  });
  describe('fromPopperPlacement', function () {
    test('fromPopperPlacement to convert from popper placements to popover placements', function () {
      expect((0, _utils.fromPopperPlacement)('right-start')).toBe('rightTop');
      expect((0, _utils.fromPopperPlacement)('right')).toBe('right');
      expect((0, _utils.fromPopperPlacement)('right-end')).toBe('rightBottom');
      expect((0, _utils.fromPopperPlacement)('top-start')).toBe('topLeft');
      expect((0, _utils.fromPopperPlacement)('top')).toBe('top');
      expect((0, _utils.fromPopperPlacement)('top-end')).toBe('topRight');
      expect((0, _utils.fromPopperPlacement)('')).toBe(null);
    });
  });
  describe('parsePopperOffset', function () {
    test('parsePopperOffset should handle valid integer inputs', function () {
      expect((0, _utils.parsePopperOffset)({
        top: 10,
        left: 15
      })).toEqual({
        top: 10,
        left: 15
      });
    });
    test('parsePopperOffset should round float inputs', function () {
      expect((0, _utils.parsePopperOffset)({
        top: 10.1,
        left: 15.24
      })).toEqual({
        top: 10,
        left: 15
      });
    });
    test('parsePopperOffset should be resilient to null input', function () {
      expect((0, _utils.parsePopperOffset)({
        top: null,
        left: null
      })).toEqual({
        top: 0,
        left: 0
      });
    });
  });
  describe('splitPlacement', function () {
    test('splitPlacement should split placements apart', function () {
      expect((0, _utils.splitPlacement)('rightTop')).toEqual(['right', 'top']);
      expect((0, _utils.splitPlacement)('right')).toEqual(['right']);
      expect((0, _utils.splitPlacement)('rightBottom')).toEqual(['right', 'bottom']);
      expect((0, _utils.splitPlacement)('topRight')).toEqual(['top', 'right']);
      expect((0, _utils.splitPlacement)('top')).toEqual(['top']);
      expect((0, _utils.splitPlacement)('topLeft')).toEqual(['top', 'left']);
      expect((0, _utils.splitPlacement)('auto')).toEqual(['auto']);
      expect((0, _utils.splitPlacement)('')).toEqual([]);
    });
    test('splitPlacement should handle empty input', function () {
      expect((0, _utils.splitPlacement)('')).toEqual([]);
    });
  });
  describe('isVerticalPosition', function () {
    test('isVerticalPosition should return true if input string is vertical position', function () {
      expect((0, _utils.isVerticalPosition)('top')).toEqual(true);
      expect((0, _utils.isVerticalPosition)('bottom')).toEqual(true);
      expect((0, _utils.isVerticalPosition)('left')).toEqual(false);
      expect((0, _utils.isVerticalPosition)('right')).toEqual(false);
    });
    test('isVerticalPosition should handle empty or null input', function () {
      expect((0, _utils.isVerticalPosition)('')).toEqual(false);
      var nullArg = null;
      expect((0, _utils.isVerticalPosition)(nullArg)).toEqual(false);
    });
  });
  describe('getPopoverMarginStyles', function () {
    test('getPopoverMarginStyles should return correct margins without arrow', function () {
      var showArrow = false;
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'topLeft')).toEqual({
        marginBottom: '8px'
      });
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'top')).toEqual({
        marginBottom: '8px'
      });
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'right')).toEqual({
        marginLeft: '8px'
      });
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'bottomLeft')).toEqual({
        marginTop: '8px'
      });
    });
    test('getPopoverMarginStyles should return correct margins with arrow', function () {
      var showArrow = true;
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'topLeft')).toEqual({
        marginBottom: '6px'
      });
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'top')).toEqual({
        marginBottom: '6px'
      });
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'right')).toEqual({
        marginLeft: '6px'
      });
      expect((0, _utils.getPopoverMarginStyles)(showArrow, 'bottomLeft')).toEqual({
        marginTop: '6px'
      });
    });
  });
  describe('getArrowPositionStyles', function () {
    test('getArrowPositionStyles should return no styles when placement is unknown yet', function () {
      expect((0, _utils.getArrowPositionStyles)({
        top: 0,
        left: 15
      }, 'auto')).toBe(null);
    });
    test('getArrowPositionStyles should return correct styles for topLeft', function () {
      expect((0, _utils.getArrowPositionStyles)({
        top: 0,
        left: 15
      }, 'topLeft')).toEqual({
        bottom: '-4px',
        left: '15px'
      });
    });
    test('getArrowPositionStyles should return correct styles for leftTop', function () {
      expect((0, _utils.getArrowPositionStyles)({
        top: 15,
        left: 0
      }, 'leftTop')).toEqual({
        right: '-4px',
        top: '15px'
      });
    });
  });
  describe('getStartPosition', function () {
    test('getStartPosition should return correct position for topLeft', function () {
      expect((0, _utils.getStartPosition)({
        left: 10,
        top: 15
      }, 'topLeft', true)).toEqual('translate3d(10px, 27px, 0)');
    });
  });
  describe('getEndPosition', function () {
    test('getEndPosition should return correct end position', function () {
      expect((0, _utils.getEndPosition)({
        left: 10,
        top: 15
      })).toEqual('translate3d(10px, 15px, 0)');
    });
  });
});