Search in sources :

Example 1 with ClientLibraries

use of com.adobe.cq.wcm.core.components.models.ClientLibraries in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ClientLibrariesImplTest method testGetCategoriesForComponent.

@Test
void testGetCategoriesForComponent() {
    Resource accordionResource = context.currentResource(ACCORDION_PATH);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ClientLibraries.OPTION_RESOURCE_TYPES, Utils.getResourceTypes(accordionResource, context.request(), mock(ModelFactory.class)));
    ClientLibraries clientlibs = getClientLibrariesUnderTest(ACCORDION_PATH, attributes);
    Set<String> categories = new HashSet<>();
    categories.add(TEASER_CATEGORY);
    categories.add(ACCORDION_CATEGORY);
    assertEquals(categories, ((ClientLibrariesImpl) clientlibs).getCategoriesFromComponents());
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) ClientLibraries(com.adobe.cq.wcm.core.components.models.ClientLibraries) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with ClientLibraries

use of com.adobe.cq.wcm.core.components.models.ClientLibraries in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ClientLibrariesImplTest method testGetCategoriesWithInjectedResourceTypesAndInheritance.

@Test
void testGetCategoriesWithInjectedResourceTypesAndInheritance() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("resourceTypes", new HashSet<String>() {

        {
            add("core/wcm/components/accordion/v1/accordion");
            add("core/wcm/components/carousel/v3/carousel");
        }
    });
    ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes);
    StringBuilder includes = new StringBuilder();
    includes.append(jsIncludes.get(ACCORDION_CATEGORY));
    includes.append(jsIncludes.get(CAROUSEL_CATEGORY));
    includes.append(cssIncludes.get(ACCORDION_CATEGORY));
    includes.append(cssIncludes.get(CAROUSEL_CATEGORY));
    assertEquals(includes.toString(), clientlibs.getJsAndCssIncludes());
}
Also used : HashMap(java.util.HashMap) ClientLibraries(com.adobe.cq.wcm.core.components.models.ClientLibraries) Test(org.junit.jupiter.api.Test)

Example 3 with ClientLibraries

use of com.adobe.cq.wcm.core.components.models.ClientLibraries in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ClientLibrariesImplTest method testJsInline.

@Test
void testJsInline() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("categories", TEASER_CATEGORY + "," + ACCORDION_CATEGORY + "," + CAROUSEL_CATEGORY);
    ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes);
    StringBuilder jsInline = new StringBuilder();
    jsInline.append(jsInlines.get(TEASER_CATEGORY));
    jsInline.append(jsInlines.get(ACCORDION_CATEGORY));
    jsInline.append(jsInlines.get(CAROUSEL_CATEGORY));
    assertEquals(jsInline.toString(), clientlibs.getJsInline());
}
Also used : HashMap(java.util.HashMap) ClientLibraries(com.adobe.cq.wcm.core.components.models.ClientLibraries) Test(org.junit.jupiter.api.Test)

Example 4 with ClientLibraries

use of com.adobe.cq.wcm.core.components.models.ClientLibraries in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ClientLibrariesImplTest method testGetCategoriesWithInjectedFilter.

@Test
void testGetCategoriesWithInjectedFilter() {
    PageManager pageManager = context.resourceResolver().adaptTo(PageManager.class);
    Page page = pageManager.getPage(ROOT_PAGE);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ClientLibraries.OPTION_RESOURCE_TYPES, Utils.getPageResourceTypes(page, context.request(), mock(ModelFactory.class)));
    attributes.put("filter", ".*teaser.*");
    ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes);
    Set<String> categories = new HashSet<>();
    categories.add(TEASER_CATEGORY);
    assertEquals(categories, ((ClientLibrariesImpl) clientlibs).getCategoriesFromComponents());
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) HashMap(java.util.HashMap) Page(com.day.cq.wcm.api.Page) ClientLibraries(com.adobe.cq.wcm.core.components.models.ClientLibraries) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with ClientLibraries

use of com.adobe.cq.wcm.core.components.models.ClientLibraries in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ClientLibrariesImplTest method testGetCssInline.

@Test
void testGetCssInline() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("categories", TEASER_CATEGORY + "," + ACCORDION_CATEGORY + "," + CAROUSEL_CATEGORY);
    ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes);
    StringBuilder cssInline = new StringBuilder();
    cssInline.append(cssInlines.get(TEASER_CATEGORY));
    cssInline.append(cssInlines.get(ACCORDION_CATEGORY));
    cssInline.append(cssInlines.get(CAROUSEL_CATEGORY));
    assertEquals(cssInline.toString(), clientlibs.getCssInline());
}
Also used : HashMap(java.util.HashMap) ClientLibraries(com.adobe.cq.wcm.core.components.models.ClientLibraries) Test(org.junit.jupiter.api.Test)

Aggregations

ClientLibraries (com.adobe.cq.wcm.core.components.models.ClientLibraries)13 HashMap (java.util.HashMap)13 Test (org.junit.jupiter.api.Test)13 HashSet (java.util.HashSet)2 Page (com.day.cq.wcm.api.Page)1 PageManager (com.day.cq.wcm.api.PageManager)1 Resource (org.apache.sling.api.resource.Resource)1