1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.widget;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.krad.datadictionary.validation.Employee;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.container.CollectionGroup;
24 import org.kuali.rice.krad.uif.field.DataField;
25 import org.kuali.rice.krad.uif.layout.TableLayoutManager;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.web.form.UifFormBase;
28
29 import java.util.ArrayList;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Set;
33
34 import static org.junit.Assert.assertEquals;
35
36
37
38
39
40 public class RichTableTest {
41
42 public static final String S_TYPE = "{\"sType\" : \"numeric\", \"aTargets\": [0]}";
43 public static final String S_SORT_DATA_TARGETS_1 = "{\"sSortDataType\" : \"dom-text\" , \"sType\" : \"string\", \"aTargets\": [1]}";
44 public static final String S_SORT_DATA_TARGETS_2 = S_SORT_DATA_TARGETS_1.replace("1", "2");
45 public static final String S_SORT_DATA_TARGETS_3 = S_SORT_DATA_TARGETS_1.replace("1", "3");
46
47 public static final String EXPECTED = S_TYPE + ", " +
48 S_SORT_DATA_TARGETS_1 + " , " +
49 S_SORT_DATA_TARGETS_2 + " , " +
50 S_SORT_DATA_TARGETS_3;
51
52 public static final String B_VISIBLE_FALSE_TARGETS_1 = "{bVisible: false, \"aTargets\": [1]}";
53 public static final String B_SORTABLE_FALSE_TARGETS_3 = "{'bSortable': false, \"aTargets\": [3]}";
54
55 private RichTable richTable;
56 private CollectionGroup group;
57
58
59 @Before
60 public void setup() {
61
62 richTable = new RichTable();
63
64 group = new CollectionGroup();
65 group.setCollectionObjectClass(Employee.class);
66 TableLayoutManager layoutManager = new TableLayoutManager();
67 layoutManager.setRenderSequenceField(true);
68 group.setLayoutManager(layoutManager);
69 group.setIncludeLineSelectionField(false);
70 group.setRenderLineActions(false);
71
72 List<Component> items = new ArrayList<Component>(1);
73 DataField name = new DataField();
74 name.setPropertyName("employeeId");
75 items.add(name);
76 DataField number = new DataField();
77 number.setPropertyName("positionTitle");
78 items.add(number);
79 DataField contactEmail = new DataField();
80 contactEmail.setPropertyName("contactEmail");
81 items.add(contactEmail);
82
83 group.setItems(items);
84 }
85
86 @Test
87
88
89
90 public void testComponentOptionsDefault() throws Exception {
91 assertRichTableComponentOptions(null, "[" + EXPECTED + " ]", UifConstants.TableToolsKeys.AO_COLUMN_DEFS);
92 }
93
94 @Test
95
96
97
98 public void testComponentOptionsAoColumnsJSOptions() throws Exception {
99 String innerColValues = "{bVisible: false}, null, null";
100 assertRichTableComponentOptions("[" + innerColValues + "]", "[" + EXPECTED + " ," + innerColValues + "]", UifConstants.TableToolsKeys.AO_COLUMN_DEFS);
101 }
102
103 @Test
104
105
106
107 public void testComponentOptionsHideColumnOnRichTable() {
108 Set<String> hiddenColumns = new HashSet<String>();
109 hiddenColumns.add("employeeId");
110 Set<String> sortableColumns = new HashSet<String>();
111 sortableColumns.add("positionTitle");
112 richTable.setSortableColumns(sortableColumns);
113 richTable.setHiddenColumns(hiddenColumns);
114 String expected = "[" + S_TYPE + ", " +
115 B_VISIBLE_FALSE_TARGETS_1 + ", " +
116 S_SORT_DATA_TARGETS_2 +", " +
117 B_SORTABLE_FALSE_TARGETS_3 + "]";
118 assertRichTableComponentOptions(null, expected, UifConstants.TableToolsKeys.AO_COLUMN_DEFS);
119 }
120
121 @Test
122
123
124
125 public void testComponentOptionsHideColumnOnLayoutManager() {
126
127 Set<String> richTableHiddenColumns = new HashSet<String>();
128 richTableHiddenColumns.add("employeeId");
129 Set<String> sortableColumns = new HashSet<String>();
130 sortableColumns.add("positionTitle");
131 richTable.setSortableColumns(sortableColumns);
132 richTable.setHiddenColumns(richTableHiddenColumns);
133
134 Set<String> lmHiddenColumns = new HashSet<String>();
135 lmHiddenColumns.add("contactEmail");
136 Set<String> lmSortableColumns = new HashSet<String>();
137 lmSortableColumns.add("employeeId");
138 ((TableLayoutManager) group.getLayoutManager()).setSortableColumns(lmSortableColumns);
139 ((TableLayoutManager) group.getLayoutManager()).setHiddenColumns(lmHiddenColumns);
140
141 String expected = "[" + EXPECTED.replace(S_SORT_DATA_TARGETS_1 + " ,", B_VISIBLE_FALSE_TARGETS_1 + ",") + "]";
142 expected = expected.replace(S_SORT_DATA_TARGETS_2 + " ,", S_SORT_DATA_TARGETS_2 + ",");
143 expected = expected.replace(S_SORT_DATA_TARGETS_3, B_SORTABLE_FALSE_TARGETS_3);
144 assertRichTableComponentOptions(null, expected, UifConstants.TableToolsKeys.AO_COLUMN_DEFS);
145 }
146
147
148
149
150
151
152
153
154 private void assertRichTableComponentOptions(String optionsOnGroup, String optionsOnRichTable, String optionKey) {
155 richTable.getTemplateOptions().put(optionKey, optionsOnGroup);
156 richTable.performFinalize(new View(), new UifFormBase(), group);
157 assertEquals(optionsOnRichTable, richTable.getTemplateOptions().get(optionKey));
158 }
159 }