Search in sources :

Example 66 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class ThemeUtil_Test method testGetThemeXslt.

@Test
public void testGetThemeXslt() {
    String themePath = "/testGetThemeXslt";
    Config.getInstance().setProperty(ConfigurationProperties.THEME_CONTENT_PATH, themePath);
    String build = ThemeUtil.getThemeBuild();
    String themeName = ThemeUtil.getThemeName();
    String versionSuffix = "?build=" + WebUtilities.escapeForUrl(build) + "&theme=" + WebUtilities.escapeForUrl(themeName);
    UIContext uic = createUIContext();
    Assert.assertEquals("Incorrect theme path", themePath + "/xslt/all.xsl" + versionSuffix, ThemeUtil.getThemeXslt(uic));
    // We used to fetch a different XSL file based on locale, this is no longer the case.
    uic.setLocale(Locale.ENGLISH);
    Assert.assertEquals("Incorrect theme path", themePath + "/xslt/all.xsl" + versionSuffix, ThemeUtil.getThemeXslt(uic));
    // We used to fetch a different XSL file based on locale, this is no longer the case.
    uic.setLocale(Locale.CANADA_FRENCH);
    Assert.assertEquals("Incorrect theme path", themePath + "/xslt/all.xsl" + versionSuffix, ThemeUtil.getThemeXslt(uic));
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 67 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class TreeUtil_Test method testFindWComponent.

@Test
public void testFindWComponent() {
    UIContext uic = UIContextHolder.getCurrent();
    ComponentWithContext result = TreeUtil.findWComponent(root, new String[] { "WApplication" });
    Assert.assertSame("Incorrect component returned for find WApplication", root, result.getComponent());
    Assert.assertSame("Incorrect context returned for find WApplication", uic, result.getContext());
    result = TreeUtil.findWComponent(root, new String[] { "WTextArea" });
    Assert.assertSame("Incorrect component returned for find WTextArea", grandChild, result.getComponent());
    Assert.assertSame("Incorrect context returned for find WTextArea", uic, result.getContext());
    result = TreeUtil.findWComponent(root, new String[] { "WContainer", "WTextArea" });
    Assert.assertSame("Incorrect component returned for find WContainer/WTextArea", grandChild, result.getComponent());
    Assert.assertSame("Incorrect context returned for find WContainer/WTextArea", uic, result.getContext());
    result = TreeUtil.findWComponent(root, new String[] { "WText[1]" });
    Assert.assertSame("Incorrect component returned for find WText[1]", repeatedComponent, result.getComponent());
    UIContext row2Context = repeaterChild.getRowContext("2");
    Assert.assertSame("Incorrect context returned for find WText[1]", row2Context, result.getContext());
    result = TreeUtil.findWComponent(root, new String[] { "WApplication", "WText[1]" });
    Assert.assertSame("Incorrect component returned for find WApplication/WText[1]", repeatedComponent, result.getComponent());
    row2Context = repeaterChild.getRowContext("2");
    Assert.assertSame("Incorrect context returned for find WApplication/WText[1]", row2Context, result.getContext());
    result = TreeUtil.findWComponent(root, new String[] { "WContainer", "WRepeater" });
    Assert.assertNull("Should not have a result for an invalid path", result);
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext) Test(org.junit.Test)

Example 68 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class TreeUtil_Test method testGetComponentWithId.

@Test
public void testGetComponentWithId() {
    Assert.assertSame("Incorrect component returned for root", root, TreeUtil.getComponentWithId(root, root.getId()));
    Assert.assertSame("Incorrect component returned for containerChild", containerChild, TreeUtil.getComponentWithId(root, containerChild.getId()));
    Assert.assertSame("Incorrect component returned for simpleChild", simpleChild, TreeUtil.getComponentWithId(root, simpleChild.getId()));
    Assert.assertSame("Incorrect component returned for repeaterChild", repeaterChild, TreeUtil.getComponentWithId(root, repeaterChild.getId()));
    Assert.assertSame("Incorrect component returned for grandChild", grandChild, TreeUtil.getComponentWithId(root, grandChild.getId()));
    UIContext row2Context = repeaterChild.getRowContext("2");
    setActiveContext(row2Context);
    Assert.assertSame("Incorrect component returned for repeatedComponent row 2", repeatedComponent, TreeUtil.getComponentWithId(root, repeatedComponent.getId()));
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 69 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class TreeUtil_Test method testGetContextForId.

@Test
public void testGetContextForId() {
    UIContext uic = UIContextHolder.getCurrent();
    Assert.assertSame("Incorrect context returned for root", uic, TreeUtil.getContextForId(root, root.getId()));
    Assert.assertSame("Incorrect context returned for containerChild", uic, TreeUtil.getContextForId(root, containerChild.getId()));
    Assert.assertSame("Incorrect context returned for simpleChild", uic, TreeUtil.getContextForId(root, simpleChild.getId()));
    Assert.assertSame("Incorrect context returned for repeaterChild", uic, TreeUtil.getContextForId(root, repeaterChild.getId()));
    Assert.assertSame("Incorrect context returned for grandChild", uic, TreeUtil.getContextForId(root, grandChild.getId()));
    UIContext row2Context = repeaterChild.getRowContext("2");
    setActiveContext(row2Context);
    Assert.assertSame("Incorrect context returned for repeatedComponent row 2", row2Context, TreeUtil.getContextForId(root, repeatedComponent.getId()));
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 70 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class DiagnosticImpl_Test method testGetDescription.

@Test
public void testGetDescription() {
    final UIContext uic = new UIContextImpl();
    final WTextField input = new WTextField();
    final String noArgsMessage = "The field is required";
    final String fieldArgMessage = "The field ''{0}'' is required";
    // Test with no formatting
    DiagnosticImpl diag = new DiagnosticImpl(Diagnostic.INFO, uic, input, noArgsMessage);
    Assert.assertEquals("Incorrect description text", noArgsMessage, diag.getDescription());
    // Test with formatting, but missing label text should default to empty String
    diag = new DiagnosticImpl(Diagnostic.INFO, uic, input, fieldArgMessage, input);
    Assert.assertEquals("Incorrect description text", "The field '' is required", diag.getDescription());
    // Test with formatting with accessible text set
    input.setAccessibleText("a");
    Assert.assertEquals("Incorrect description text", "The field 'a' is required", diag.getDescription());
    // Test with formatting with toolTip
    input.setAccessibleText(null);
    input.setToolTip("a tooltip");
    Assert.assertEquals("Incorrect description text", "The field 'a tooltip' is required", diag.getDescription());
    // Test with label set
    WLabel label = new WLabel("bc", input);
    Assert.assertEquals("Incorrect description text", "The field 'bc' is required", diag.getDescription());
    // Test with label set, with a colon at the end
    label.setText("def:");
    Assert.assertEquals("Incorrect description text", "The field 'def' is required", diag.getDescription());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WTextField(com.github.bordertech.wcomponents.WTextField) WLabel(com.github.bordertech.wcomponents.WLabel) 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