"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _index = _interopRequireWildcard(require("../index"));

var _reactTestbed = _interopRequireDefault(require("../../../../../../tests/util/react-testbed"));

var styles = {
  componentId: 'cYuau',
  template: function template(theme) {
    return "\n\n.FormattedDuration__styles__dark {\n  color: ".concat(theme.darkColor || 'inherit', ";\n}\n");
  },
  'dark': 'FormattedDuration__styles__dark'
};
describe('FormattedDuration Presenter', function () {
  var props = {
    timeLimitInSeconds: 3600,
    styles: {
      hours: {},
      minutes: {},
      seconds: {}
    }
  };
  var testbed = (0, _reactTestbed.default)(_index.default, props);
  var TEN_SECONDS = 10;
  var SEVEN_SECONDS = 7;
  var FIFTY_NINE_SECONDS = 59;
  var FIVE_MINUTES = 60 * 5;
  var SEVEN_MINUTES = 60 * 7;
  var TWO_HOURS = 60 * 60 * 2;
  describe('#getHoursMinutesSeconds', function () {
    context('with time limit in hours', function () {
      it('outputs a hash with correct hours', function () {
        var output = (0, _index.getHoursMinutesSeconds)(TWO_HOURS);
        expect(output.hours).to.eq(2);
      });
      context('with minutes', function () {
        it('outputs a hash with correct hours and minutes', function () {
          var output = (0, _index.getHoursMinutesSeconds)(TWO_HOURS + FIVE_MINUTES);
          expect(output.hours).to.eq(2);
          expect(output.minutes).to.eq(5);
        });
        context('with seconds', function () {
          it('outputs a hash with correct hours and minutes and seconds', function () {
            var output = (0, _index.getHoursMinutesSeconds)(TWO_HOURS + FIVE_MINUTES + TEN_SECONDS);
            expect(output.hours).to.eq(2);
            expect(output.minutes).to.eq(5);
            expect(output.seconds).to.eq(10);
          });
        });
      });
    });
    context('with time limit in minutes', function () {
      it('outputs a hash with hours to 0', function () {
        var output = (0, _index.getHoursMinutesSeconds)(FIVE_MINUTES);
        expect(output.hours).to.eq(0);
      });
      it('outputs a hash with correct minutes', function () {
        var output = (0, _index.getHoursMinutesSeconds)(SEVEN_MINUTES);
        expect(output.minutes).to.eq(7);
      });
      context('with seconds', function () {
        it('outputs a hash with correct minutes and seconds', function () {
          var output = (0, _index.getHoursMinutesSeconds)(SEVEN_MINUTES + FIFTY_NINE_SECONDS);
          expect(output.minutes).to.eq(7);
          expect(output.seconds).to.eq(59);
        });
      });
    });
    context('with time limit in seconds', function () {
      it('outputs a hash with hours to 0', function () {
        var output = (0, _index.getHoursMinutesSeconds)(FIFTY_NINE_SECONDS);
        expect(output.hours).to.eq(0);
      });
      it('outputs a hash with minutes to 0', function () {
        var output = (0, _index.getHoursMinutesSeconds)(FIFTY_NINE_SECONDS);
        expect(output.minutes).to.eq(0);
      });
      it('outputs a hash with seconds set correctly', function () {
        var output = (0, _index.getHoursMinutesSeconds)(SEVEN_SECONDS + TEN_SECONDS);
        expect(output.seconds).to.eq(17);
      });
    });
    context('with 0 passed in', function () {
      it('outputs a hash with hours, minutes, and seconds set to 0', function () {
        var output = (0, _index.getHoursMinutesSeconds)(0);
        expect(output.hours).to.eq(0);
        expect(output.minutes).to.eq(0);
        expect(output.seconds).to.eq(0);
      });
    });
    context('with null passed in', function () {
      it('outputs a hash with hours, minutes, and seconds set to 0', function () {
        var output = (0, _index.getHoursMinutesSeconds)(null);
        expect(output.hours).to.eq(0);
        expect(output.minutes).to.eq(0);
        expect(output.seconds).to.eq(0);
      });
    });
    context('with undefined passed in', function () {
      it('outputs a hash with hours, minutes, and seconds set to 0', function () {
        var output = (0, _index.getHoursMinutesSeconds)(void 0);
        expect(output.hours).to.eq(0);
        expect(output.minutes).to.eq(0);
        expect(output.seconds).to.eq(0);
      });
    });
  });
  describe('#pad', function () {
    it('adds a 0 if number is less than 10', function () {
      expect((0, _index.pad)(7)).to.eq('07');
    });
    it('doesn\'t add a 0 if number is more than 10', function () {
      expect((0, _index.pad)(17)).to.eq('17');
    });
  });
  describe('#render', function () {
    context('with hours', function () {
      it('displays the hours, minutes, and seconds', function () {
        testbed.render({
          timeLimitInSeconds: TWO_HOURS + FIVE_MINUTES + TEN_SECONDS
        });
        var text = testbed.getText();
        expect(text).to.include('02');
        expect(text).to.include('05');
        expect(text).to.include('10');
      });
    });
    context('with no hours', function () {
      it('does display the minutes and seconds', function () {
        testbed.render({
          timeLimitInSeconds: FIVE_MINUTES + TEN_SECONDS
        });
        var text = testbed.getText();
        expect(text).to.include('05');
        expect(text).to.include('10');
      });
    });
    context('with minutes', function () {
      it('displays the minutes and seconds', function () {
        testbed.render({
          timeLimitInSeconds: FIVE_MINUTES + TEN_SECONDS
        });
        var text = testbed.getText();
        expect(text).to.include('05');
        expect(text).to.include('10');
      });
      it('styles the minutes and seconds with the dark style', function () {
        testbed.render({
          timeLimitInSeconds: FIVE_MINUTES + TEN_SECONDS
        });
        var count = testbed.findChildrenByClass(styles.dark).length;
        expect(count).to.eq(2);
      });
    });
    context('with no minutes', function () {
      it('displays the minutes and seconds', function () {
        testbed.render({
          timeLimitInSeconds: TEN_SECONDS
        });
        var text = testbed.getText();
        expect(text).to.include('00');
        expect(text).to.include('10');
      });
      it('does not style the minutes with the dark style', function () {
        testbed.render({
          timeLimitInSeconds: TEN_SECONDS
        });
        var count = testbed.findChildrenByClass(styles.dark).length;
        expect(count).to.eq(1);
      });
    });
    context('with no time', function () {
      it('displays the minutes and seconds', function () {
        testbed.render({
          timeLimitInSeconds: 0
        });
        var text = testbed.getText();
        expect(text).to.include('00');
        expect(text).to.not.include('10');
      });
      it('does not style the minutes or seconds with the dark style', function () {
        testbed.render({
          timeLimitInSeconds: 0
        });
        var count = testbed.findChildrenByClass(styles.dark).length;
        expect(count).to.eq(0);
      });
    });
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
  });
});