|
28 | 28 | import org.junit.jupiter.api.extension.ExtendWith; |
29 | 29 |
|
30 | 30 | import com.adobe.cq.export.json.SlingModelFilter; |
| 31 | +import com.adobe.cq.forms.core.components.internal.constants.ThemeConstants; |
31 | 32 | import com.adobe.cq.forms.core.components.internal.form.FormConstants; |
32 | 33 | import com.adobe.cq.forms.core.components.models.form.*; |
33 | 34 | import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext; |
@@ -179,6 +180,67 @@ public void containsFormContainer_should_return_false() { |
179 | 180 | assertFalse(result); |
180 | 181 | } |
181 | 182 |
|
| 183 | + @Test |
| 184 | + void testGetThemeClientLibRefFromFormContainer() { |
| 185 | + String path = CONTENT_ROOT + "/myTestPage"; |
| 186 | + FormStructureParser formStructureParser = getFormStructureParserUnderTest(path); |
| 187 | + String themeClientLibRef = formStructureParser.getThemeClientLibRefFromFormContainer(); |
| 188 | + assertEquals("fdtheme.test-theme", themeClientLibRef); |
| 189 | + } |
| 190 | + |
| 191 | + @Test |
| 192 | + void testGetThemeClientLibRefWithRequestAttribute() { |
| 193 | + String path = CONTENT_ROOT + "/myTestPage"; |
| 194 | + context.currentResource(path); |
| 195 | + MockSlingHttpServletRequest request = context.request(); |
| 196 | + request.setAttribute(ThemeConstants.THEME_OVERRIDE, "/content/dam/formsanddocuments-themes/test-theme"); |
| 197 | + FormStructureParser formStructureParser = request.adaptTo(FormStructureParser.class); |
| 198 | + String themeClientLibRef = formStructureParser.getThemeClientLibRefFromFormContainer(); |
| 199 | + assertEquals("fdtheme.test-theme", themeClientLibRef); |
| 200 | + } |
| 201 | + |
| 202 | + @Test |
| 203 | + void testGetThemeClientLibRefWithRequestParameter() { |
| 204 | + String path = CONTENT_ROOT + "/myTestPage"; |
| 205 | + context.currentResource(path); |
| 206 | + MockSlingHttpServletRequest request = context.request(); |
| 207 | + request.setParameterMap(Collections.singletonMap(ThemeConstants.THEME_OVERRIDE, |
| 208 | + "/content/dam/formsanddocuments-themes/test-theme")); |
| 209 | + FormStructureParser formStructureParser = request.adaptTo(FormStructureParser.class); |
| 210 | + String themeClientLibRef = formStructureParser.getThemeClientLibRefFromFormContainer(); |
| 211 | + assertEquals("fdtheme.test-theme", themeClientLibRef); |
| 212 | + } |
| 213 | + |
| 214 | + @Test |
| 215 | + void testGetThemeClientLibRefWithInvalidThemePath() { |
| 216 | + String path = CONTENT_ROOT + "/myTestPage"; |
| 217 | + context.currentResource(path); |
| 218 | + MockSlingHttpServletRequest request = context.request(); |
| 219 | + request.setAttribute(ThemeConstants.THEME_OVERRIDE, "/content/dam/formsanddocuments-themes/invalid-theme"); |
| 220 | + FormStructureParser formStructureParser = request.adaptTo(FormStructureParser.class); |
| 221 | + String themeClientLibRef = formStructureParser.getThemeClientLibRefFromFormContainer(); |
| 222 | + assertNull(themeClientLibRef); |
| 223 | + } |
| 224 | + |
| 225 | + @Test |
| 226 | + void testGetThemeClientLibRefWithNonExistentTheme() { |
| 227 | + String path = CONTENT_ROOT + "/myTestPage"; |
| 228 | + context.currentResource(path); |
| 229 | + MockSlingHttpServletRequest request = context.request(); |
| 230 | + request.setAttribute(ThemeConstants.THEME_OVERRIDE, "/content/dam/formsanddocuments-themes/non-existent"); |
| 231 | + FormStructureParser formStructureParser = request.adaptTo(FormStructureParser.class); |
| 232 | + String themeClientLibRef = formStructureParser.getThemeClientLibRefFromFormContainer(); |
| 233 | + assertNull(themeClientLibRef); |
| 234 | + } |
| 235 | + |
| 236 | + @Test |
| 237 | + void testGetThemeClientLibRefWithoutTheme() { |
| 238 | + String path = FORM_CONTAINER_PATH + "/container1"; |
| 239 | + FormStructureParser formStructureParser = getFormStructureParserUnderTest(path); |
| 240 | + String themeClientLibRef = formStructureParser.getThemeClientLibRefFromFormContainer(); |
| 241 | + assertNull(themeClientLibRef); |
| 242 | + } |
| 243 | + |
182 | 244 | private FormStructureParser getFormStructureParserUnderTest(String resourcePath) { |
183 | 245 | context.currentResource(resourcePath); |
184 | 246 | MockSlingHttpServletRequest request = context.request(); |
|
0 commit comments