"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("enzyme");

var _ = _interopRequireDefault(require("."));

var _Tutorials = require("../../../views/Tutorials");

describe('TutorialCard', function () {
  describe('not admin', function () {
    var node;
    beforeEach(function () {
      var props = {
        numTutorials: 3,
        deleteTutorial: jest.fn(),
        makeHero: jest.fn(),
        shiftOrder: jest.fn(),
        publish: jest.fn(),
        tutorial: {
          backgroundColor: '#fff',
          description: 'test tutorial desc',
          title: 'test tutorial title',
          hero: false,
          stepCount: 3,
          published: false,
          emoji: '🦉'
        }
      };
      node = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_["default"], props));
    });
    it('should display the TutorialCard component', function () {
      expect(node.find('.TutorialCard').hasClass('TutorialCard')).toBe(true);
    });
    it('should not display button bar without admin privelages', function () {
      var buttonBar = node.find('.TutorialCard-Toolbar-Button');
      expect(buttonBar.find('button').exists()).toBe(false);
    });
  });
  describe('admin', function () {
    var node;
    var props;
    beforeEach(function () {
      props = {
        numTutorials: 3,
        deleteTutorial: jest.fn(),
        makeHero: jest.fn(),
        shiftOrder: jest.fn(),
        publish: jest.fn(),
        tutorial: {
          _id: '123',
          backgroundColor: '#fff',
          description: 'test tutorial desc',
          title: 'test tutorial title',
          hero: false,
          stepCount: 3,
          published: true,
          emoji: ''
        }
      };
      node = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_Tutorials.PermissionContext.Provider, {
        value: true
      }, /*#__PURE__*/_react["default"].createElement(_["default"], props)));
    });
    it('should display the button bar with admin', function () {
      var buttonBar = node.find('.TutorialCard-Toolbar');
      expect(buttonBar.find('button').exists()).toBe(true);
    });
    describe('button actions', function () {
      it('shiftLeft', function () {
        var buttonBar = node.find('.TutorialCard-Toolbar-Arrow');
        var button = buttonBar.find('button').first();
        button.simulate('click');
        expect(props.shiftOrder).toHaveBeenCalledWith({
          _id: '123',
          direction: -1
        });
      });
      it('shiftRight', function () {
        var buttonBar = node.find('.TutorialCard-Toolbar-Arrow');
        var button = buttonBar.find('button').last();
        button.simulate('click');
        expect(props.shiftOrder).toHaveBeenCalledWith({
          _id: '123',
          direction: 1
        });
      });
      it('togglePublish', function () {
        var buttonBar = node.find('.TutorialCard-Toolbar-Button');
        var button = buttonBar.find('button').at(1);
        button.simulate('click');
        expect(props.publish).toHaveBeenCalledWith({
          _id: '123',
          published: false
        });
      });
      it('makeHero', function () {
        var buttonBar = node.find('.TutorialCard-Toolbar-Button');
        var button = buttonBar.find('button').at(2);
        button.simulate('click');
        expect(props.makeHero).toHaveBeenCalledWith({
          _id: '123',
          published: true
        });
      });
      it('deleteTutorial', function () {
        var buttonBar = node.find('.TutorialCard-Toolbar-Button');
        var button = buttonBar.find('button').last();
        button.simulate('click');
        expect(props.deleteTutorial).toHaveBeenCalledWith({
          _id: '123'
        });
      });
    });
    describe('status', function () {
      it('should show a notification if admin + non-published status', function () {
        var p2 = {
          numTutorials: 3,
          deleteTutorial: jest.fn(),
          makeHero: jest.fn(),
          shiftOrder: jest.fn(),
          publish: jest.fn(),
          tutorial: {
            _id: '123',
            backgroundColor: '#fff',
            description: 'test tutorial desc',
            title: 'test tutorial title',
            hero: true,
            stepCount: 3,
            published: true,
            emoji: ''
          }
        };
        var n2 = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_Tutorials.PermissionContext.Provider, {
          value: true
        }, /*#__PURE__*/_react["default"].createElement(_["default"], p2)));
        var status = n2.find('.TutorialCard-Status');
        expect(status.exists()).toBe(true);
      });
    });
  });
});