Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert LoginForm to use new TextField
Add basic tests for logging in and for changing caption Change-Id: I6dca2eedb5832db0eb409f0621092d0e723e0654
- Loading branch information
Showing
8 changed files
with
344 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
server/src/test/java/com/vaadin/tests/server/component/loginform/LoginFormTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.vaadin.tests.server.component.loginform; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.tests.util.MockUI; | ||
import com.vaadin.ui.Button; | ||
import com.vaadin.ui.Component; | ||
import com.vaadin.ui.HasComponents; | ||
import com.vaadin.ui.LoginForm; | ||
import com.vaadin.ui.NativeButton; | ||
import com.vaadin.ui.PasswordField; | ||
import com.vaadin.ui.TextField; | ||
import com.vaadin.ui.UI; | ||
|
||
public class LoginFormTest { | ||
|
||
private LoginForm loginForm; | ||
|
||
@Before | ||
public void setup() { | ||
loginForm = new LoginForm(); | ||
} | ||
|
||
@Test | ||
public void defaultCaptions() { | ||
Assert.assertEquals("Username", loginForm.getUsernameCaption()); | ||
Assert.assertEquals("Password", loginForm.getPasswordCaption()); | ||
Assert.assertEquals("Login", loginForm.getLoginButtonCaption()); | ||
} | ||
|
||
@Test | ||
public void changeCaptionsBeforeAttach() { | ||
loginForm.setUsernameCaption("u"); | ||
loginForm.setPasswordCaption("p"); | ||
loginForm.setLoginButtonCaption("l"); | ||
|
||
Assert.assertEquals("u", loginForm.getUsernameCaption()); | ||
Assert.assertEquals("p", loginForm.getPasswordCaption()); | ||
Assert.assertEquals("l", loginForm.getLoginButtonCaption()); | ||
} | ||
|
||
@Test | ||
public void changeCaptionsAfterAttach() { | ||
UI ui = new MockUI(); | ||
ui.setContent(loginForm); | ||
loginForm.setUsernameCaption("u"); | ||
loginForm.setPasswordCaption("p"); | ||
loginForm.setLoginButtonCaption("l"); | ||
|
||
Assert.assertEquals("u", loginForm.getUsernameCaption()); | ||
Assert.assertEquals("p", loginForm.getPasswordCaption()); | ||
Assert.assertEquals("l", loginForm.getLoginButtonCaption()); | ||
} | ||
|
||
@Test | ||
public void changeCaptionsBeforeAndAfterAttach() { | ||
loginForm.setUsernameCaption("a"); | ||
loginForm.setPasswordCaption("a"); | ||
loginForm.setLoginButtonCaption("a"); | ||
|
||
UI ui = new MockUI(); | ||
ui.setContent(loginForm); | ||
loginForm.setUsernameCaption("u"); | ||
loginForm.setPasswordCaption("p"); | ||
loginForm.setLoginButtonCaption("l"); | ||
|
||
Assert.assertEquals("u", loginForm.getUsernameCaption()); | ||
Assert.assertEquals("p", loginForm.getPasswordCaption()); | ||
Assert.assertEquals("l", loginForm.getLoginButtonCaption()); | ||
} | ||
|
||
@Test | ||
public void customizedFields() { | ||
LoginForm customForm = new LoginForm() { | ||
@Override | ||
protected Button createLoginButton() { | ||
return new NativeButton("Do it"); | ||
} | ||
|
||
@Override | ||
protected TextField createUsernameField() { | ||
TextField tf = new TextField("Username caption"); | ||
tf.setPlaceholder("Name goes here"); | ||
return tf; | ||
} | ||
|
||
@Override | ||
protected PasswordField createPasswordField() { | ||
PasswordField pf = new PasswordField("Password caption"); | ||
pf.setPlaceholder("Secret goes here"); | ||
return pf; | ||
} | ||
}; | ||
|
||
UI ui = new MockUI(); | ||
ui.setContent(customForm); | ||
Iterator<Component> i = ((HasComponents) customForm.iterator().next()) | ||
.iterator(); | ||
Assert.assertEquals("Username caption", i.next().getCaption()); | ||
Assert.assertEquals("Password caption", i.next().getCaption()); | ||
Assert.assertEquals("Do it", i.next().getCaption()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
uitest-common/src/main/java/com/vaadin/testbench/customelements/LoginFormElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.vaadin.testbench.customelements; | ||
|
||
import com.vaadin.testbench.elements.AbstractSingleComponentContainerElement; | ||
import com.vaadin.testbench.elementsbase.ServerClass; | ||
|
||
@ServerClass("com.vaadin.ui.LoginForm") | ||
public class LoginFormElement extends AbstractSingleComponentContainerElement { | ||
|
||
} |
29 changes: 22 additions & 7 deletions
29
...ts/loginform/CustomizedLoginFormTest.java → ...ents/loginform/CustomizedLoginFormUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 0 additions & 120 deletions
120
uitest/src/main/java/com/vaadin/tests/components/loginform/LoginFormTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.