'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _helpers = require('./helpers');

var _2 = require('./');

var _3 = _interopRequireDefault(_2);

var _status = require('../status');

var _status2 = _interopRequireDefault(_status);

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

var SummaryFormatter = function (_Formatter) {
  (0, _inherits3.default)(SummaryFormatter, _Formatter);

  function SummaryFormatter(options) {
    (0, _classCallCheck3.default)(this, SummaryFormatter);

    var _this = (0, _possibleConstructorReturn3.default)(this, (SummaryFormatter.__proto__ || Object.getPrototypeOf(SummaryFormatter)).call(this, options));

    options.eventBroadcaster.on('test-run-finished', _this.logSummary.bind(_this));
    return _this;
  }

  (0, _createClass3.default)(SummaryFormatter, [{
    key: 'isTestCaseFailure',
    value: function isTestCaseFailure(testCase) {
      return _lodash2.default.includes([_status2.default.AMBIGUOUS, _status2.default.FAILED], testCase.result.status);
    }
  }, {
    key: 'isTestCaseWarning',
    value: function isTestCaseWarning(testCase) {
      return _lodash2.default.includes([_status2.default.PENDING, _status2.default.UNDEFINED], testCase.result.status);
    }
  }, {
    key: 'logSummary',
    value: function logSummary(testRun) {
      var _this2 = this;

      var failures = [];
      var warnings = [];
      _lodash2.default.each(this.eventDataCollector.testCaseMap, function (testCase) {
        if (_this2.isTestCaseFailure(testCase)) {
          failures.push(testCase);
        } else if (_this2.isTestCaseWarning(testCase)) {
          warnings.push(testCase);
        }
      });
      if (failures.length > 0) {
        this.logIssues({ issues: failures, title: 'Failures' });
      }
      if (warnings.length > 0) {
        this.logIssues({ issues: warnings, title: 'Warnings' });
      }
      this.log((0, _helpers.formatSummary)({
        colorFns: this.colorFns,
        testCaseMap: this.eventDataCollector.testCaseMap,
        testRun: testRun
      }));
    }
  }, {
    key: 'logIssues',
    value: function logIssues(_ref) {
      var _this3 = this;

      var issues = _ref.issues,
          title = _ref.title;

      this.log(title + ':\n\n');
      issues.forEach(function (testCase, index) {
        var _eventDataCollector$g = _this3.eventDataCollector.getTestCaseData(testCase.sourceLocation),
            gherkinDocument = _eventDataCollector$g.gherkinDocument,
            pickle = _eventDataCollector$g.pickle;

        _this3.log((0, _helpers.formatIssue)({
          colorFns: _this3.colorFns,
          gherkinDocument: gherkinDocument,
          number: index + 1,
          pickle: pickle,
          snippetBuilder: _this3.snippetBuilder,
          testCase: testCase
        }));
      });
    }
  }]);
  return SummaryFormatter;
}(_3.default);

exports.default = SummaryFormatter;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5204 characters]