/**
 * File: LoginEndUserSteps.java 27.05.2014, 12:42:39, author: mreinhardt
 * 
 * Project: OwnCloud
 *
 * https://www.martinreinhardt-online.de/apps
 */
package de.martinreinhardt.owncloud.webtest.steps;

import static org.hamcrest.MatcherAssert.assertThat;
import net.thucydides.core.annotations.Step;
import net.thucydides.core.pages.Pages;

import org.apache.log4j.Logger;
import org.openqa.selenium.JavascriptExecutor;

import de.martinreinhardt.owncloud.webtest.pages.PortalPage;
import de.martinreinhardt.owncloud.webtest.pages.UserSettingsPage;

/**
 * @author mreinhardt
 * 
 */
public class LoggedInUserSteps extends PortalUserSteps {

	/**
	 * Serial ID
	 */
	private static final long serialVersionUID = 1000463057264545156L;

	// Logger
	protected static final Logger LOG = Logger.getLogger(LoggedInUserSteps.class);

	/**
	 * @param pages
	 */
	public LoggedInUserSteps(final Pages pages) {
		super(pages);
	}

	// PAGE STEPS

	@Step
	public void go_to_roundcube_view() {
		LOG.info("Going to rouncube page");
		onPortalPage().go_to_roundcube_app();
		LOG.info("Done going to rouncube page");
	}

	@Step
	public void go_to_storagecharts_view() {
		LOG.info("Going to storagecharts page");
		onPortalPage().go_to_storage_charts_app();
		LOG.info("Done going to storagecharts page");
	}

	@Step
	public void go_to_adminsettings_view() {
		LOG.info("Going to admin settings page");
		onPortalPage().go_to_admin_settings();
		LOG.info("Done going to admin settings page");
	}

	@Step
	public void go_to_user_settings() {
		LOG.info("Going to user settings page");
		onPortalPage().go_to_user_settings();
		LOG.info("Done going to user settings page");
	}

	@Step
	public void update_roundcube_login_and_save(final String pLogin, final String pPassword) {
		onUserSettingsPage().set_rc_credentials(pLogin, pPassword);
		assertThat("No status message is displayed", onUserSettingsPage().save_roundcube_settings());
        ((JavascriptExecutor)getDriver()).executeScript("window.scrollTo(0, 100);");
		assertThat("No errors are displayed", !onUserSettingsPage().error_displayed());
	}

	@Step
	public void logout() {
		LOG.info("Starting logout");
		onPortalPage().do_logout();
		LOG.info("Logout done.");
	}

	private PortalPage onPortalPage() {
		return getPages().currentPageAt(PortalPage.class);
	}

	private UserSettingsPage onUserSettingsPage() {
		return getPages().currentPageAt(UserSettingsPage.class);
	}

}

@@ -298,16 +298,66 @@
 s.Step;%0A
+import net.thucydides.core.annotations.StepGroup;%0A
 import n
@@ -1701,33 +1701,34 @@
 ings page%22);%0A%09%7D%0A
+%09
 %0A
-
 %09@Step%0A%09public v
@@ -1757,17 +1757,8 @@
 ogin
-_and_save
 (fin
@@ -1963,16 +1963,74 @@
 ));%0A
-   
+%09%7D%0A%09%0A%09@Step%0A%09public void save_roundcube_login_details() %7B%0A
      
+   
 ((Ja
@@ -2093,17 +2093,17 @@
 llTo(0, 
-1
+2
 00);%22);%0A
@@ -2184,24 +2184,211 @@
 yed());%0A%09%7D%0A%0A
+%09@StepGroup%0A%09public void update_roundcube_login_and_save(final String pLogin, final String pPassword) %7B%0A%09%09update_roundcube_login(pLogin, pPassword);%0A%09%09save_roundcube_login_details();%0A%09%7D%0A%0A
 %09@Step%0A%09publ

Update manual login test