import { WebComponent , Browser , Page , findBy , Button , TextInput , elementIsVisible , pageHasLoaded } from '../lib' ; import { ShowIdeaPage , GoogleSignInPage , FacebookSignInPage } from './' ; import config from '../config' ; export class HomePage extends Page { constructor ( browser ) { super ( browser ) ; this . setUrl ( `${ config . baseUrl }/` ) ; } @ findBy ( '#new-idea-input' ) public IdeaTitle : TextInput ; @ findBy ( '.ui.form textarea' ) public IdeaDescription : TextInput ; @ findBy ( '.ui.button.primary' ) public SubmitIdea : Button ; @ findBy ( '.signin' ) public UserMenu : WebComponent ; @ findBy ( '.fdr-profile-popup .button.google' ) public GoogleSignIn : Button ; @ findBy ( '.fdr-profile-popup .button.facebook' ) public FacebookSignIn : Button ; @ findBy ( '.signout' ) private SignOut : Button ; public loadCondition ( ) { return elementIsVisible ( ( ) => this . IdeaTitle ) ; } public async submitNewIdea ( title , description ) { await this . IdeaTitle . type ( title ) ; await this . IdeaDescription . type ( description ) ; await this . SubmitIdea . click ( ) ; await this . browser . wait ( pageHasLoaded ( ShowIdeaPage ) ) ; } public async signOut ( ) { try { await this . SignOut . click ( ) ; } catch ( ex ) { return ; } await this . browser . wait ( pageHasLoaded ( HomePage ) ) ; } public async signInWithGoogle ( ) { await this . browser . clearCookies ( 'https://accounts.google.com' ) ; await this . signOut ( ) ; await this . signIn ( ( ) => this . GoogleSignIn ) ; await this . browser . waitAny ( [ pageHasLoaded ( GoogleSignInPage ) , pageHasLoaded ( HomePage ) , ] ) ; } public async signInWithFacebook ( ) { await this . browser . clearCookies ( 'https://facebook.com' ) ; await this . signOut ( ) ; await this . signIn ( ( ) => this . FacebookSignIn ) ; await this . browser . waitAny ( [ pageHasLoaded ( FacebookSignInPage ) , pageHasLoaded ( HomePage ) , ] ) ; } private async signIn ( locator ) { await this . UserMenu . click ( ) ; await this . browser . wait ( elementIsVisible ( locator ) ) ; await locator ( ) . click ( ) ; } }