Search in sources :

Example 11 with UIContext

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));
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) GroupedDiagnositcs(com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 12 with UIContext

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());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 13 with UIContext

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());
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment) Test(org.junit.Test)

Example 14 with UIContext

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();
    }
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 15 with UIContext

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();
    }
}
Also used : SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Aggregations

UIContext (com.github.bordertech.wcomponents.UIContext)114 Test (org.junit.Test)47 WComponent (com.github.bordertech.wcomponents.WComponent)18 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)15 SystemException (com.github.bordertech.wcomponents.util.SystemException)14 WApplication (com.github.bordertech.wcomponents.WApplication)13 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)11 WText (com.github.bordertech.wcomponents.WText)11 PrintWriter (java.io.PrintWriter)11 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)9 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)7 WDropdown (com.github.bordertech.wcomponents.WDropdown)7 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)7 StringWriter (java.io.StringWriter)7 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)6 Environment (com.github.bordertech.wcomponents.Environment)6 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)6