var settings = require('../../../../../settings.js');
var liveDomain = settings.Settings ? settings.Settings.liveDomain : settings.default.liveDomain;
// const adUnit = settings.Settings ? settings.Settings.adUnit : settings.default.adUnit

var requestChecks = function requestChecks() {
  console.log('settings', settings);
  it('gets all routes', function () {
    // cy.task('getAllRoutes');
    cy.task('getAllRoutes').then(function (result) {
      console.log('result', result);
      result.forEach(function (route) {
        cy.request({
          url: '/' + route,
          failOnStatusCode: true
        });
      });
    });
  });
};

var adTest = function adTest() {
  it('checks for rendered Ads', function () {
    cy.on('uncaught:exception', function () {
      return false;
    });
    cy.visit(liveDomain);
    cy.wait(5000);
    cy.get('iframe').each(function ($el, index) {
      // if ($el[0].id === `google_ads_iframe_4688/${adUnit}_${index}` {
      if ($el[0].id.includes('google_ads_iframe_4688')) {
        expect($el).to.have.attr('data-load-complete', 'true');
      }
    });
  });
};

var noIndex = function noIndex() {
  it('does not detect noindex, nofollow', function () {
    cy.on('uncaught:exception', function () {
      return false;
    });
    cy.visit(liveDomain);
    cy.get('head meta[name="robots"]').should('not.exist');
  });
};

export { adTest, noIndex, requestChecks };
