use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WValidationErrors_Test method testGetGroupedErrors.
@Test
public void testGetGroupedErrors() {
wValidationErrors.setLocked(true);
UIContext uic = createUIContext();
setActiveContext(uic);
errors.clear();
List<GroupedDiagnositcs> groupedErrors = wValidationErrors.getGroupedErrors();
Assert.assertTrue("Should not have any groups by default", groupedErrors.isEmpty());
WComponent component1 = new WTextField();
WComponent component2 = new WTextField();
Diagnostic component1Error1 = new DiagnosticImpl(Diagnostic.ERROR, component1, "Error 1");
Diagnostic component2Error1 = new DiagnosticImpl(Diagnostic.ERROR, component2, "Error 2");
Diagnostic component2Error2 = new DiagnosticImpl(Diagnostic.ERROR, component2, "Error 3");
errors.add(component1Error1);
errors.add(component2Error1);
errors.add(component2Error2);
wValidationErrors.setErrors(errors);
groupedErrors = wValidationErrors.getGroupedErrors();
Assert.assertEquals("Incorrect number of groups", 2, groupedErrors.size());
GroupedDiagnositcs group1 = groupedErrors.get(0);
GroupedDiagnositcs group2 = groupedErrors.get(1);
Assert.assertEquals("Incorrect number of errors for group 1", 1, group1.getDiagnostics().size());
Assert.assertSame("Incorrect diagnostic in group 1", component1Error1, group1.getDiagnostics().get(0));
Assert.assertEquals("Incorrect number of errors for group 2", 2, group2.getDiagnostics().size());
Assert.assertSame("Incorrect diagnostic in group 2", component2Error1, group2.getDiagnostics().get(0));
Assert.assertSame("Incorrect diagnostic in group 2", component2Error2, group2.getDiagnostics().get(1));
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class Validation_Test method testMandatorySpecificToUser.
@Test
public void testMandatorySpecificToUser() {
UIContext uic1 = new UIContextImpl();
UIContext uic2 = new UIContextImpl();
List<Diagnostic> diags = new ArrayList<>();
// uic 1 has mandatory check
// uic 2 does not.
WTextField textField = new WTextField();
textField.setLocked(true);
setActiveContext(uic1);
textField.setMandatory(true);
textField.validate(diags);
Assert.assertEquals("UIC 1 should have a validation error", 1, diags.size());
diags.clear();
setActiveContext(uic2);
textField.validate(diags);
Assert.assertEquals("UIC 2 should not have a validation error", 0, diags.size());
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class InfoDump_Test method testExample.
@Test
public void testExample() {
// Launch the web browser to the LDE
SeleniumWComponentsWebDriver driver = getDriver();
Assert.assertEquals("Incorrect default text", "", driver.findWTextArea(byWComponentPath("WTextArea")).getText());
driver.findElement(byWComponentPath("WButton[1]")).click();
String text = driver.findWTextArea(byWComponentPath("WTextArea")).getText();
Assert.assertTrue("Text should contain dump info", text.contains("WEnvironment"));
UIContext uic = getUserContextForSession();
UIContextHolder.pushContext(uic);
try {
Environment env = getUi().getEnvironment();
Assert.assertTrue("Incorrect AppId", text.contains("AppId: " + env.getAppId()));
} finally {
UIContextHolder.popContext();
}
driver.findElement(byWComponentPath("WButton[0]")).click();
Assert.assertEquals("Text should have been cleared", "", driver.findWTextArea(byWComponentPath("WTextArea")).getText());
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WDropdownOptionsExample_Test method testExampleSubmitOnChange.
/**
* submit on change test.
*/
@Test
public void testExampleSubmitOnChange() {
WDropdownOptionsExample example = (WDropdownOptionsExample) getUi();
// Launch the web browser to the LDE
SeleniumWComponentsWebDriver driver = getDriver();
WDropdown.DropdownType type = WDropdown.DropdownType.NATIVE;
configureDropDown(driver, type, 4);
UIContext uic = getUserContextForSession();
UIContextHolder.pushContext(uic);
try {
WDropdown dropdown = (WDropdown) TreeUtil.findWComponent(example, new String[] { "WDropdown" }).getComponent();
List<?> options = dropdown.getOptions();
for (Object option : options) {
driver.findElement(byWComponent(dropdown, option)).click();
Assert.assertEquals("Incorrect option selected", option, dropdown.getSelected());
Assert.assertEquals("Incorrect text field text", option, driver.findElement(byWComponentPath("WDropdownOptionsExample/WPanel[1]")).getText());
}
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WDropdownSpecialCharHandlingExample_Test method testExample.
@Test
public void testExample() {
WDropdownSpecialCharHandlingExample example = (WDropdownSpecialCharHandlingExample) getUi();
// Launch the web browser to the LDE
SeleniumWComponentsWebDriver driver = getDriver();
UIContext uic = getUserContextForSession();
UIContextHolder.pushContext(uic);
try {
WDropdown dropdown = (WDropdown) TreeUtil.findWComponent(example, new String[] { "WDropdown" }).getComponent();
List<?> options = dropdown.getOptions();
for (Object option : options) {
driver.findElement(byWComponent(dropdown, option)).click();
driver.findElement(byWComponentPath("WButton")).click();
Assert.assertEquals("Incorrect option selected", option, dropdown.getSelected());
Assert.assertEquals("Incorrect text field text", (option == null ? "" : option), driver.findWTextField(byWComponentPath("WTextField")).getValue());
}
} finally {
UIContextHolder.popContext();
}
}
Aggregations