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