|
7 | 7 |
|
8 | 8 | import static org.junit.Assert.assertEquals; |
9 | 9 | import static org.junit.Assert.assertFalse; |
| 10 | +import static org.junit.Assert.assertTrue; |
10 | 11 |
|
11 | 12 | public class DashboardExporterTest { |
12 | 13 |
|
| 14 | + private static class TestableDashboardExporter extends DashboardExporter { |
| 15 | + |
| 16 | + private TestableDashboardExporter() { |
| 17 | + super("test-user", null); |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + protected String getInternationalizedHeader(String columnName) { |
| 22 | + return columnName; |
| 23 | + } |
| 24 | + |
| 25 | + private String resolveColumnDisplayName(JSONObject settings, JSONObject column, JSONArray variables) throws JSONException { |
| 26 | + return getDashboardColumnDisplayName(settings, column, variables); |
| 27 | + } |
| 28 | + |
| 29 | + private void copyWidgetLikeSelections(JSONObject dashboardSelections, JSONObject widget) throws JSONException { |
| 30 | + addWidgetLikeSelections(dashboardSelections, widget); |
| 31 | + } |
| 32 | + } |
| 33 | + |
13 | 34 | @Test |
14 | 35 | public void shouldPreserveOrderBySummaryPathInPivotAggregations() throws JSONException { |
15 | 36 | DashboardExporter exporter = new DashboardExporter("test-user", null); |
@@ -101,4 +122,69 @@ public void shouldPreserveRowSummaryPathWhenSortingPivotColumns() throws JSONExc |
101 | 122 | assertFalse(categories.getJSONObject(1).has("orderBySummaryPath")); |
102 | 123 | assertFalse(categories.getJSONObject(2).has("orderBySummaryPath")); |
103 | 124 | } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void shouldResolveVariablePlaceholderInCustomHeaderLabel() throws JSONException { |
| 128 | + TestableDashboardExporter exporter = new TestableDashboardExporter(); |
| 129 | + |
| 130 | + JSONObject settings = new JSONObject() |
| 131 | + .put("configuration", new JSONObject() |
| 132 | + .put("headers", new JSONObject() |
| 133 | + .put("custom", new JSONObject() |
| 134 | + .put("enabled", true) |
| 135 | + .put("rules", new JSONArray() |
| 136 | + .put(new JSONObject() |
| 137 | + .put("action", "setLabel") |
| 138 | + .put("value", "$V{QQ}") |
| 139 | + .put("target", new JSONArray().put("quarter-column"))))))); |
| 140 | + JSONObject column = new JSONObject() |
| 141 | + .put("id", "quarter-column") |
| 142 | + .put("alias", "Quarter"); |
| 143 | + JSONArray variables = new JSONArray() |
| 144 | + .put(new JSONObject() |
| 145 | + .put("name", "QQ") |
| 146 | + .put("value", "Q1 2026")); |
| 147 | + |
| 148 | + assertEquals("Q1 2026", exporter.resolveColumnDisplayName(settings, column, variables)); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void shouldResolveDirectVariableNameInCustomHeaderLabel() throws JSONException { |
| 153 | + TestableDashboardExporter exporter = new TestableDashboardExporter(); |
| 154 | + |
| 155 | + JSONObject settings = new JSONObject() |
| 156 | + .put("configuration", new JSONObject() |
| 157 | + .put("headers", new JSONObject() |
| 158 | + .put("custom", new JSONObject() |
| 159 | + .put("enabled", true) |
| 160 | + .put("rules", new JSONArray() |
| 161 | + .put(new JSONObject() |
| 162 | + .put("action", "setLabel") |
| 163 | + .put("value", "QQ") |
| 164 | + .put("target", new JSONArray().put("quarter-column"))))))); |
| 165 | + JSONObject column = new JSONObject() |
| 166 | + .put("id", "quarter-column") |
| 167 | + .put("alias", "Quarter"); |
| 168 | + JSONArray variables = new JSONArray() |
| 169 | + .put(new JSONObject() |
| 170 | + .put("name", "QQ") |
| 171 | + .put("value", "Q1 2026")); |
| 172 | + |
| 173 | + assertEquals("Q1 2026", exporter.resolveColumnDisplayName(settings, column, variables)); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void shouldCopyIncomingWidgetLikeSelections() throws JSONException { |
| 178 | + TestableDashboardExporter exporter = new TestableDashboardExporter(); |
| 179 | + JSONObject dashboardSelections = new JSONObject(); |
| 180 | + JSONObject widget = new JSONObject() |
| 181 | + .put("likeSelections", new JSONObject() |
| 182 | + .put("sales", new JSONObject() |
| 183 | + .put("COUNTRY,REGION", "it"))); |
| 184 | + |
| 185 | + exporter.copyWidgetLikeSelections(dashboardSelections, widget); |
| 186 | + |
| 187 | + assertTrue(dashboardSelections.has("likeSelections")); |
| 188 | + assertEquals("it", dashboardSelections.getJSONObject("likeSelections").getJSONObject("sales").getString("COUNTRY,REGION")); |
| 189 | + } |
104 | 190 | } |
0 commit comments