'use strict';
console.log('here');
const verifyNoBrowserErrors = require('./helpers').verifyNoBrowserErrors;
const scrollToEl = require('./helpers').scrollToEl;
const fixFFTest = require('./helpers').fixFFTest;
const eachNth = require('./helpers').eachNth;

const URL = 'index.html';

function basicTests(swaggerUrl, title) {
  describe(`Basic suite for ${title}`, () => {
    let specUrl = URL;
    if (swaggerUrl) {
      specUrl += `?url=${encodeURIComponent(swaggerUrl)}`;
    }

    beforeEach((done) => {
      browser.get(specUrl);
      fixFFTest(done);
    });

    afterEach(() => {
      verifyNoBrowserErrors();
    });

    it('should init redoc without errors', () => {
      let $redoc = $('redoc');
      expect($redoc.isPresent()).toBe(true);
      let $methods = $$('method');
      expect($methods.count()).toBeGreaterThan(0);
    });
  });
}

basicTests(null, 'Extended Petstore');


describe('Scroll sync', () => {
  let specUrl = URL;

  beforeEach((done) => {
    browser.get(specUrl);
    fixFFTest(done);
  });

  it('should update active menu entries on page scroll', () => {
    scrollToEl('[tag="store"]').then(function() {
      expect($('.menu-cat-header.active').getInnerHtml()).toContain('store');
      expect($('.selected-tag').getInnerHtml()).toContain('store');
    });
  });
});

if (process.env.JOB === 'e2e-guru') {
  describe('APIs.guru specs test', ()=> {

    // global.apisGuruList was loaded in onPrepare method of protractor config
    let apisGuruList = global.apisGuruList;

    // Remove certain APIs that are known to cause problems
    delete apisGuruList['motaword.com']; // invalid (see https://github.com/BigstickCarpet/swagger-parser/issues/26)
    delete apisGuruList['learnifier.com']; // allof object and no type
    delete apisGuruList['googleapis.com:mirror']; // bad urls in images
    delete apisGuruList['googleapis.com:discovery']; // non-string references
    delete apisGuruList['clarify.io']; // non-string references
    delete apisGuruList['pushpay.com']; // https://github.com/Rebilly/ReDoc/issues/30

    // run quick version of e2e test on all builds except releases
    if (process.env.TRAVIS && !process.env.TRAVIS_TAG) {
      console.log('Running on short APIs guru list');
      apisGuruList = eachNth(apisGuruList, 10);
    } else {
      console.log('Running on full APIs guru list')
    }

    for (let apiName of Object.keys(apisGuruList)) {
      let apiInfo = apisGuruList[apiName].versions[apisGuruList[apiName].preferred];
      let url = apiInfo.swaggerUrl;

      // temporary hack due to this issue: https://github.com/substack/https-browserify/issues/6
      url = url.replace('https://', 'http://');
      url = url.replace('apis-guru.github.io/', 'apis-guru.github.io:80/');
      basicTests(url, `${apiName}:${apiInfo.info.version}\n${url}`);
    }
  });
}

@@ -1084,16 +1084,25 @@
 e scroll
+ forwards
 ', () =%3E
@@ -1145,18 +1145,13 @@
 hen(
-function()
+() =%3E
  %7B%0A 
@@ -1223,24 +1223,24 @@
 n('store');%0A
-
       expect
@@ -1308,16 +1308,932 @@
 );%0A  %7D);
+%0A%0A  it('should update active menu entries on page scroll backwards', () =%3E %7B%0A    scrollToEl('%5Boperation-id=%22getPetById%22%5D').then(() =%3E %7B%0A      expect($('.menu-cat-header.active').getInnerHtml()).toContain('pet');%0A      expect($('.selected-tag').getInnerHtml()).toContain('pet');%0A      expect($('.menu-cat li.active').getInnerHtml()).toContain('Find pet by ID');%0A      expect($('.selected-endpoint').getInnerHtml()).toContain('Find pet by ID');%0A    %7D);%0A  %7D);%0A%7D);%0A%0Adescribe('Language tabs sync', () =%3E %7B%0A  let specUrl = URL;%0A%0A  beforeEach((done) =%3E %7B%0A    browser.get(specUrl);%0A    fixFFTest(done);%0A  %7D);%0A%0A  it('should sync language tabs', () =%3E %7B%0A    var $item = $$('%5Boperation-id=%22addPet%22%5D tabs %3E ul %3E li').last();%0A    // check if correct item%0A    expect($item.getText()).toContain('PHP');%0A    $item.click().then(() =%3E %7B%0A      expect($('%5Boperation-id=%22updatePet%22%5D li.active').getText()).toContain('PHP');%0A    %7D);%0A  %7D);
 %0A%7D);%0A%0Aif

Add more e2e tests