Skip to content
Snippets Groups Projects
search-page.e2e-spec.ts 1.83 KiB
Newer Older
Lotte Hofstede's avatar
Lotte Hofstede committed
import { ProtractorPage } from './search-page.po';
Lotte Hofstede's avatar
Lotte Hofstede committed
import { browser } from 'protractor';
import { promise } from 'selenium-webdriver';
describe('protractor SearchPage', () => {
Lotte Hofstede's avatar
Lotte Hofstede committed
  let page: ProtractorPage;

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

  it('should contain query value when navigating to page with query parameter', () => {
    const queryString = 'Interesting query string';
    page.navigateToSearchWithQueryParameter(queryString);
    page.getCurrentQuery().then((query: string) => {
      expect<string>(query).toEqual(queryString);
    });
  });

  it('should have right scope selected when navigating to page with scope parameter', () => {
Lotte Hofstede's avatar
Lotte Hofstede committed
    const scope: promise.Promise<string> = page.getRandomScopeOption();
    scope.then((scopeString: string) => {
      page.navigateToSearchWithScopeParameter(scopeString);
      page.getCurrentScope().then((s: string) => {
        expect<string>(s).toEqual(scopeString);
      });
    });
  });

  it('should redirect to the correct url when scope was set and submit button was triggered', () => {
    const scope: promise.Promise<string> = page.getRandomScopeOption();
    scope.then((scopeString: string) => {
      page.setCurrentScope(scopeString);
      page.submitSearchForm();
      browser.wait(() => {
        return browser.getCurrentUrl().then((url: string) => {
          return url.indexOf('scope=' + encodeURI(scopeString)) !== -1;
        });
Lotte Hofstede's avatar
Lotte Hofstede committed
      });
    });
  });

  it('should redirect to the correct url when query was set and submit button was triggered', () => {
    const queryString = 'Another interesting query string';
    page.setCurrentQuery(queryString);
    page.submitSearchForm();
    browser.wait(() => {
      return browser.getCurrentUrl().then((url: string) => {
        return url.indexOf('query=' + encodeURI(queryString)) !== -1;
      });
Lotte Hofstede's avatar
Lotte Hofstede committed
    });
  });
});