/*
 * Copyright (C) 2016 the original author or authors.
 *
 * This file is part of jBB Application Project.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 */

package org.jbb.qa.pages;

import net.serenitybdd.core.pages.PageObject;
import net.thucydides.core.annotations.DefaultUrl;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;

import static org.assertj.core.api.Assertions.assertThat;

@DefaultUrl("/register")
public class RegistrationPage extends PageObject {
    @FindBy(id = "login")
    WebElement loginTextField;

    @FindBy(id = "displayedName")
    WebElement displayedNameField;

    @FindBy(id = "email")
    WebElement emailFIeld;

    @FindBys({@FindBy(xpath = "//button[contains(text(),'Send')]")})
    WebElement registerButton;

    public void typeLogin(String login) {
        loginTextField.sendKeys(login);
    }

    public void typeDisplayedName(String displayedName) {
        displayedNameField.sendKeys(displayedName);
    }

    public void typeEmail(String email) {
        emailFIeld.sendKeys(email);
    }

    public void sendRegistrationForm() {
        registerButton.click();
    }

    public void containsConfirmation() {
        assertThat(containsText("Registration completed!"));
    }

    public void containsInfoAboutIncorrectLoginLength() {
        assertThat(containsText("size must be between 3 and 20"));
    }

    public void containsInfoAboutWhiteCharactersInLogin() {
        assertThat(containsText("Login cannot contain spaces and other white characters"));
    }

    public void containsInfoAboutIncorrectDisplayedNameLength() {
        assertThat(containsText("size must be between 3 and 64"));
    }

    public void containsInfoAboutIncorrectEmail() {
        assertThat(containsText("not a well-formed email address"));
    }

    public void containsInfoAboutBusyLogin() {
        assertThat(containsText("This login is already taken"));
    }

    public void containsInfoAboutBusyDisplayedName() {
        assertThat(containsText("This displayed name is already taken"));
    }

    public void containsInfoAboutBusyEmail() {
        assertThat(containsText("This e-mail is already used by another member"));
    }
}

@@ -1416,16 +1416,25 @@
 eted!%22))
+.isTrue()
 ;%0A    %7D%0A
@@ -1557,16 +1557,25 @@
 nd 20%22))
+.isTrue()
 ;%0A    %7D%0A
@@ -1721,24 +1721,33 @@
 haracters%22))
+.isTrue()
 ;%0A    %7D%0A%0A   
@@ -1874,16 +1874,25 @@
 nd 64%22))
+.isTrue()
 ;%0A    %7D%0A
@@ -2011,16 +2011,25 @@
 dress%22))
+.isTrue()
 ;%0A    %7D%0A
@@ -2131,32 +2131,41 @@
 already taken%22))
+.isTrue()
 ;%0A    %7D%0A%0A    pub
@@ -2284,16 +2284,25 @@
 taken%22))
+.isTrue()
 ;%0A    %7D%0A
@@ -2430,16 +2430,25 @@
 ember%22))
+.isTrue()
 ;%0A    %7D%0A

Fix assertions in e2e registration tests (cherry picked from commit d7fe6c6)