'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() {
  const loginPage = new _LoginPage2.default();
  const landingPage = new _ProtectedPage2.default();

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

    landingPage.becomesVisible();
  });

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

    before(() => {
      landingPage.clickCreateNewLink();

      createPage.becomesVisible();
    });

    testParams.visibleRecordTypes.forEach(recordTypeDescriptor => {
      var _recordTypeDescriptor = _slicedToArray(recordTypeDescriptor, 3);

      const serviceType = _recordTypeDescriptor[0],
            name = _recordTypeDescriptor[1],
            displayName = _recordTypeDescriptor[2];


      it(`should show a link for the ${serviceType} record named "${name}" with link text "${displayName}"`, () => {
        createPage.hasRecordType({ serviceType, name, displayName }).should.equal(true);
      });
    });

    testParams.visibleVocabularies.forEach(vocabularyDescriptor => {
      var _vocabularyDescriptor = _slicedToArray(vocabularyDescriptor, 3);

      const authorityName = _vocabularyDescriptor[0],
            name = _vocabularyDescriptor[1],
            displayName = _vocabularyDescriptor[2];


      it(`should show a link for the ${authorityName} vocabulary named "${name}" with link text "${displayName}"`, () => {
        createPage.hasVocabulary({ authorityName, name, displayName }).should.equal(true);
      });
    });

    testParams.hiddenRecordTypes.forEach(recordTypeDescriptor => {
      const name = recordTypeDescriptor;

      it(`should not show a link for the record named "${name}"`, () => {
        createPage.hasRecordType({ name }).should.equal(false);
      });
    });

    testParams.hiddenVocabularies.forEach(vocabularyDescriptor => {
      var _vocabularyDescriptor2 = _slicedToArray(vocabularyDescriptor, 2);

      const authorityName = _vocabularyDescriptor2[0],
            name = _vocabularyDescriptor2[1];


      it(`should not show a link for the ${authorityName} vocabulary named "${name}"`, () => {
        createPage.hasVocabulary({ authorityName, name }).should.equal(false);
      });
    });
  });

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