/*
 * 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!")).isTrue();
    }

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

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

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

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

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

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

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

@@ -531,67 +531,8 @@
 s;%0A%0A
-import static org.assertj.core.api.Assertions.assertThat;%0A%0A
 @Def
@@ -543,19 +543,28 @@
 Url(
-%22/r
+R
 egist
-er%22
+rationPage.URL
 )%0Apu
@@ -612,16 +612,67 @@
 bject %7B%0A
+    public static final String URL = %22/register%22;%0A%0A
     @Fin
@@ -838,17 +838,147 @@
 t emailF
-I
+ield;%0A%0A    @FindBy(id = %22password%22)%0A    WebElement passwordField;%0A%0A    @FindBy(id = %22passwordAgain%22)%0A    WebElement passwordAgainFi
 eld;%0A%0A  
@@ -1338,17 +1338,17 @@
   emailF
-I
+i
 eld.send
@@ -1359,32 +1359,246 @@
 (email);%0A    %7D%0A%0A
+    public void typePassword(String password) %7B%0A        passwordField.sendKeys(password);%0A    %7D%0A%0A    public void typePasswordAgain(String passwordAgain) %7B%0A        passwordAgainField.sendKeys(passwordAgain);%0A    %7D%0A%0A
     public void 
@@ -1710,35 +1710,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22Re
@@ -1754,26 +1754,16 @@
 leted!%22)
-).isTrue()
 ;%0A    %7D%0A
@@ -1829,35 +1829,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22si
@@ -1879,26 +1879,16 @@
 and 20%22)
-).isTrue()
 ;%0A    %7D%0A
@@ -1956,35 +1956,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22Lo
@@ -2031,26 +2031,16 @@
 acters%22)
-).isTrue()
 ;%0A    %7D%0A
@@ -2114,35 +2114,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22si
@@ -2164,26 +2164,16 @@
 and 64%22)
-).isTrue()
 ;%0A    %7D%0A
@@ -2233,35 +2233,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22no
@@ -2285,26 +2285,16 @@
 ddress%22)
-).isTrue()
 ;%0A    %7D%0A
@@ -2349,35 +2349,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22Th
@@ -2393,34 +2393,24 @@
 eady taken%22)
-).isTrue()
 ;%0A    %7D%0A%0A   
@@ -2469,35 +2469,29 @@
         
-assertThat(c
+shouldC
 ontain
-s
 Text(%22Th
@@ -2526,26 +2526,16 @@
  taken%22)
-).isTrue()
 ;%0A    %7D%0A
@@ -2594,27 +2594,21 @@
     
-assertThat(c
+shouldC
 ontain
-s
 Text
@@ -2660,17 +2660,254 @@
 er%22)
-).isTrue(
+;%0A    %7D%0A%0A    public void containsInfoAboutIncorrectLengthOfPassword() %7B%0A        shouldContainText(%22Password has incorrect length%22);%0A    %7D%0A%0A    public void containsInfoAboutNotMatchingPasswords() %7B%0A        shouldContainText(%22Passwords don't match%22
 );%0A 

Fix merge from develop