'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _CreatePage = require('./pageObjects/CreatePage');

var _CreatePage2 = _interopRequireDefault(_CreatePage);

var _LoginPage = require('./pageObjects/LoginPage');

var _LoginPage2 = _interopRequireDefault(_LoginPage);

var _ProtectedPage = require('./pageObjects/ProtectedPage');

var _ProtectedPage2 = _interopRequireDefault(_ProtectedPage);

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

describe('record types', function suite() {
  var loginPage = new _LoginPage2.default();
  var landingPage = new _ProtectedPage2.default();

  before(function () {
    loginPage.open();
    loginPage.login(testParams.adminUser.username, testParams.adminUser.password);

    landingPage.becomesVisible();
  });

  context('on the create page', function context() {
    var createPage = new _CreatePage2.default();

    before(function () {
      landingPage.clickCreateNewLink();

      createPage.becomesVisible();
    });

    testParams.visibleRecordTypes.forEach(function (recordTypeDescriptor) {
      var _recordTypeDescriptor = _slicedToArray(recordTypeDescriptor, 3),
          serviceType = _recordTypeDescriptor[0],
          name = _recordTypeDescriptor[1],
          displayName = _recordTypeDescriptor[2];

      it('should show a link for the ' + serviceType + ' record named "' + name + '" with link text "' + displayName + '"', function () {
        createPage.hasRecordType({ serviceType: serviceType, name: name, displayName: displayName }).should.equal(true);
      });
    });

    testParams.visibleVocabularies.forEach(function (vocabularyDescriptor) {
      var _vocabularyDescriptor = _slicedToArray(vocabularyDescriptor, 3),
          authorityName = _vocabularyDescriptor[0],
          name = _vocabularyDescriptor[1],
          displayName = _vocabularyDescriptor[2];

      it('should show a link for the ' + authorityName + ' vocabulary named "' + name + '" with link text "' + displayName + '"', function () {
        createPage.hasVocabulary({ authorityName: authorityName, name: name, displayName: displayName }).should.equal(true);
      });
    });

    testParams.hiddenRecordTypes.forEach(function (recordTypeDescriptor) {
      var name = recordTypeDescriptor;

      it('should not show a link for the record named "' + name + '"', function () {
        createPage.hasRecordType({ name: name }).should.equal(false);
      });
    });

    testParams.hiddenVocabularies.forEach(function (vocabularyDescriptor) {
      var _vocabularyDescriptor2 = _slicedToArray(vocabularyDescriptor, 2),
          authorityName = _vocabularyDescriptor2[0],
          name = _vocabularyDescriptor2[1];

      it('should not show a link for the ' + authorityName + ' vocabulary named "' + name + '"', function () {
        createPage.hasVocabulary({ authorityName: authorityName, name: name }).should.equal(false);
      });
    });
  });

  // TODO: Test expected record types appear in search dropdowns and permissions list.
});