Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Nov 7, 2023
1 parent b5feca6 commit ef5b554
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public Component answer(InvocationOnMock invocation) throws Throwable {
when(mediaFormatHandler.getMediaFormat(SHOWROOM_STANDARD.getName())).thenReturn(SHOWROOM_STANDARD);
when(mediaFormatHandler.getMediaFormat(NONFIXED_RAW.getName())).thenReturn(NONFIXED_RAW);
}

@Test
@SuppressWarnings("null")
void testCustomIPEConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import java.util.Set;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
Expand All @@ -40,6 +42,9 @@
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.components.ComponentContext;
import com.day.cq.wcm.api.components.EditConfig;
import com.day.cq.wcm.api.components.EditContext;
import com.day.cq.wcm.api.components.InplaceEditingConfig;

import io.wcm.handler.commons.dom.Image;
import io.wcm.handler.media.Dimension;
Expand Down Expand Up @@ -71,6 +76,14 @@ class MediaMarkupBuilderUtilTest {
private SlingHttpServletRequest request;
@Mock
private ComponentContext componentContext;
@Mock
private Resource componentResource;
@Mock
private EditContext editContext;
@Mock
private EditConfig editConfig;
@Mock
private InplaceEditingConfig inplaceEditingConfig;

@BeforeEach
@SuppressWarnings("null")
Expand All @@ -80,6 +93,13 @@ void setUp() throws Exception {
when(request.getResource()).thenReturn(resource);
when(pageManager.getContainingPage(resource)).thenReturn(page);
when(request.getParameter(DiffService.REQUEST_PARAM_DIFF_TO)).thenReturn(VERSION_LABEL);
when(componentContext.getResource()).thenReturn(componentResource);
when(componentResource.getResourceResolver()).thenReturn(resolver);
when(componentContext.getEditContext()).thenReturn(editContext);
when(editContext.getEditConfig()).thenReturn(editConfig);
when(editConfig.getInplaceEditingConfig()).thenReturn(inplaceEditingConfig);
when(inplaceEditingConfig.getConfigPath()).thenReturn("/apps/components/comp1");
when(inplaceEditingConfig.getEditorType()).thenReturn("image");
}

@Test
Expand Down Expand Up @@ -149,4 +169,36 @@ void testCanApplyDragDropSupport_DragDropSupport_Auto() {
assertTrue(MediaMarkupBuilderUtil.canApplyDragDropSupport(mediaRequest, componentContext));
}

@Test
void testCanSetCustomIPECropRatios_ALWAYS() {
MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.ALWAYS));
assertTrue(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext));
}

@Test
void testCanSetCustomIPECropRatios_ALWAYS_CustomEditorType_Mismatch() {
when(inplaceEditingConfig.getEditorType()).thenReturn("custom");
MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.ALWAYS));
assertFalse(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext));
}

@Test
void testCanSetCustomIPECropRatios_ALWAYS_CustomEditorType_Match() {
when(inplaceEditingConfig.getEditorType()).thenReturn("custom");
MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.ALWAYS));
assertTrue(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext, Set.of("image", "custom")));
}

@Test
void testCanSetCustomIPECropRatios_NEVER() {
MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.NEVER));
assertFalse(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext));
}

@Test
void testCanSetCustomIPECropRatios_AUTO() {
MediaRequest mediaRequest = new MediaRequest("/content/dam/path", new MediaArgs().ipeRatioCustomize(IPERatioCustomize.AUTO));
assertTrue(MediaMarkupBuilderUtil.canSetCustomIPECropRatios(mediaRequest, componentContext));
}

}

0 comments on commit ef5b554

Please sign in to comment.