import { AppPage } from './app.po';
import { throttleTime } from 'rxjs/operators';


describe('EnvoScholar Compatibility Tests', () => {
  var searchField = "drugs";
  var baseURL = "http://localhost:4200/";
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  it('Able to search and click on articles', () => {
    page.navigateTo();
    expect(page.getPageTitleText()).toEqual('EnvoScholar v3.0');

    expect(page.sendSearchInput(searchField)).toEqual(searchField);

    expect(page.getDisplayResultsURL()).toEqual(baseURL + "displayresults?search=" + 
                                                searchField + "&page=1");

    /* Check that the article name that was clicked in display results is the same
       in both the Display Results Page and the Article Information Page
    */                               
    page.getDisplayResultsArticleName().then(function(firstArticleText) {
      expect(page.clickDisplayResultsArticle());
      return firstArticleText;
    }).then(function(passedFirstArticleText) {
      expect(page.getArticleInformationArticleName()).toEqual(passedFirstArticleText);
    });
  });

  it('Able to go to the last page in pagination', () => {
    page.navigateTo();
    expect(page.getPageTitleText()).toEqual('EnvoScholar v3.0');

    expect(page.sendSearchInput(searchField)).toEqual(searchField);

    expect(page.getDisplayResultsURL()).toEqual(baseURL + "displayresults?search=" + 
                                                searchField + "&page=1");

    page.getLastPagePosition().then(function(position) {
      expect(page.goToLastPageInPagination(position));
    });

  });

});