1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui.appwithinminutes

File StaticListClassFieldTest.java

 

Code metrics

0
44
3
1
169
83
3
0.07
14.67
3
1

Classes

Class Line # Actions
StaticListClassFieldTest 37 44 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.ui.appwithinminutes;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.xwiki.appwithinminutes.test.po.StaticListClassFieldEditPane;
27    import org.xwiki.appwithinminutes.test.po.StaticListItemsEditor;
28    import org.xwiki.test.ui.browser.IgnoreBrowser;
29    import org.xwiki.test.ui.browser.IgnoreBrowsers;
30   
31    /**
32    * Special class editor tests that address only the Static List class field type.
33    *
34    * @version $Id: e570669bd85ad4f54747549c5b032533e5fe8b02 $
35    * @since 4.0M1
36    */
 
37    public class StaticListClassFieldTest extends AbstractClassEditorTest
38    {
39    /**
40    * Tests that the field preview is properly updated when the display type is changed. Currently selected items must
41    * be preserved.
42    */
 
43  1 toggle @Test
44    @IgnoreBrowsers({
45    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
46    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
47    })
48    public void testDisplayType()
49    {
50    // Add a new static list field.
51  1 StaticListClassFieldEditPane staticListField =
52    new StaticListClassFieldEditPane(editor.addField("Static List").getName());
53    // By default the list is displayed using check boxes.
54  1 Assert.assertEquals("checkbox", staticListField.getPreviewInputType());
55   
56    // Enable multiple selection.
57  1 staticListField.openConfigPanel();
58  1 staticListField.getMultipleSelectionCheckBox().click();
59   
60    // Select the first and third options.
61  1 staticListField.getItemByValue("value1").click();
62  1 staticListField.getItemByValue("value3").click();
63   
64    // Change the display type to 'select'.
65  1 staticListField.getDisplayTypeSelect().selectByVisibleText("select");
66  1 staticListField.closeConfigPanel();
67   
68    // Assert that the field preview has been updated.
69  1 Assert.assertEquals("select", staticListField.getPreviewInputType());
70    // Assert that the selected values were preserved.
71  1 Assert.assertEquals(Arrays.asList("value1", "value3"), staticListField.getDefaultSelectedValues());
72   
73    // Select only the second option.
74  1 staticListField.setDefaultValue("value2");
75   
76    // Change the display type to 'radio'.
77  1 staticListField.openConfigPanel();
78  1 staticListField.getDisplayTypeSelect().selectByVisibleText("radio");
79  1 staticListField.closeConfigPanel();
80    // Assert that the field preview has been updated.
81  1 Assert.assertEquals("radio", staticListField.getPreviewInputType());
82    // Assert that the selected value was preserved.
83  1 Assert.assertEquals("value2", staticListField.getDefaultValue());
84    }
85   
86    /**
87    * Tests that multiple select state is synchronized with the rest of the meta properties.
88    */
 
89  1 toggle @Test
90    @IgnoreBrowsers({
91    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
92    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
93    })
94    public void testMultipleSelect()
95    {
96    // Add a new static list field.
97  1 StaticListClassFieldEditPane staticListField =
98    new StaticListClassFieldEditPane(editor.addField("Static List").getName());
99   
100    // Open the configuration panel and play with the multiple selection option.
101  1 staticListField.openConfigPanel();
102   
103    // Radio display type should disable multiple selection.
104  1 staticListField.getMultipleSelectionCheckBox().click();
105  1 Assert.assertTrue(staticListField.getMultipleSelectionCheckBox().isSelected());
106  1 staticListField.getDisplayTypeSelect().selectByVisibleText("radio");
107  1 Assert.assertFalse(staticListField.getMultipleSelectionCheckBox().isSelected());
108   
109    // Enabling multiple selection when display type is radio should change display type to check box.
110  1 staticListField.getMultipleSelectionCheckBox().click();
111  1 Assert.assertEquals("checkbox",
112    staticListField.getDisplayTypeSelect().getFirstSelectedOption().getAttribute("value"));
113   
114    // 'select' display type supports properly multiple selection only if size is greater than 1.
115  1 Assert.assertEquals("1", staticListField.getSizeInput().getAttribute("value"));
116  1 staticListField.getDisplayTypeSelect().selectByVisibleText("select");
117  1 Assert.assertEquals("3", staticListField.getSizeInput().getAttribute("value"));
118    }
119   
120    /**
121    * Tests the ability to add, edit and remove list items.
122    */
 
123  1 toggle @Test
124    @IgnoreBrowsers({
125    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
126    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
127    })
128    public void testItemsEditor()
129    {
130    // Add a new static list field.
131  1 StaticListClassFieldEditPane staticListField =
132    new StaticListClassFieldEditPane(editor.addField("Static List").getName());
133   
134    // Open the configuration panel and edit the list items.
135  1 staticListField.openConfigPanel();
136  1 StaticListItemsEditor itemsEditor = staticListField.getItemsEditor();
137   
138    // Remove the second option.
139  1 itemsEditor.remove("value2");
140   
141    // Add two new items.
142  1 itemsEditor.add("foo", "bar");
143    // Leave the value empty for the second item: it should fall back on the label.
144  1 itemsEditor.add("", "XWiki");
145   
146    // Change the label of the last added item.
147  1 itemsEditor.setLabel("XWiki", "XWiki Enterprise");
148   
149    // Move the last item before the first.
150  1 itemsEditor.moveBefore("XWiki", "value1");
151   
152  1 Assert.assertEquals(4, itemsEditor.size());
153   
154    // Enable multiple selection and change display type to 'select' to check the value of the size property.
155  1 staticListField.getDisplayTypeSelect().selectByVisibleText("select");
156  1 staticListField.getMultipleSelectionCheckBox().click();
157  1 Assert.assertEquals("4", staticListField.getSizeInput().getAttribute("value"));
158   
159    // Apply configuration changes and assert the result.
160  1 staticListField.closeConfigPanel();
161    // The initial second item was removed.
162  1 Assert.assertNull(staticListField.getItemByValue("value2"));
163    // We should have a new item with value "XWiki".
164  1 staticListField.getItemByValue("XWiki").click();
165    // Assert the order of the items.
166  1 staticListField.getItemByValue("value1").click();
167  1 Assert.assertEquals(Arrays.asList("XWiki", "value1"), staticListField.getDefaultSelectedValues());
168    }
169    }