Skip to content

Commit

Permalink
KYAN-306 Add Accordion Component
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
andrechern committed Jan 8, 2025
1 parent 44eef27 commit e0c3a42
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AccordionItemComponent {
private String size;

@Getter
List<String> classList = new ArrayList<>();
private List<String> classList = new ArrayList<>();

@PostConstruct
private void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2025 Dynamic Solutions
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.ds.kyanite.common.components.models;

import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.junit5.SlingContext;
import org.apache.sling.testing.mock.sling.junit5.SlingContextExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(SlingContextExtension.class)
public class AccordionComponentTest {

private static final String PATH = "/content/accordion";

private final SlingContext context = new SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK);

@BeforeEach
public void init() {
context.addModelsForClasses(AccordionComponent.class);
context.addModelsForClasses(AccordionItemComponent.class);
context.addModelsForClasses(ContentComponent.class);
context.load().json(requireNonNull(
Thread.currentThread().getContextClassLoader().getResourceAsStream("accordion.json")), PATH);
}

@Test
void defaultAccordionComponentModelTest() {
AccordionComponent model = context.resourceResolver().getResource(PATH + "/default")
.adaptTo(AccordionComponent.class);
assertThat(model).isNotNull();
List<Resource> childrenComponents = model.getChildrenComponents();
assertEquals(2, childrenComponents.size());
AccordionItemComponent accordionItemComponent = childrenComponents.get(1).adaptTo(AccordionItemComponent.class);
assertThat(accordionItemComponent).isNotNull();
assertEquals(List.of("is-5"), accordionItemComponent.getClassList());
assertEquals("is-5", accordionItemComponent.getSize());
assertEquals("Title2", accordionItemComponent.getTitle());
Resource content = childrenComponents.get(0).getChild("content");
ContentComponent contentComponent = content.adaptTo(ContentComponent.class);
assertEquals("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>", contentComponent.getText());
}
}
35 changes: 35 additions & 0 deletions applications/common/backend/src/test/resources/accordion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"default": {
"sling:resourceType": "kyanite/common/components/accordion",
"jcr:primaryType": "nt:unstructured",
"cell_1": {
"sling:resourceType": "kyanite/common/components/accordion/accordionitem",
"jcr:primaryType": "nt:unstructured",
"size": "is-4",
"title": "Title",
"content": {
"sling:resourceType": "kyanite/common/components/content",
"jcr:primaryType": "nt:unstructured",
"size": "is-normal",
"text": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
"textWeight": "has-text-weight-normal"
}
},
"cell_2": {
"sling:resourceType": "kyanite/common/components/accordion/accordionitem",
"jcr:primaryType": "nt:unstructured",
"size": "is-5",
"title": "Title2",
"content": {
"sling:resourceType": "kyanite/common/components/content",
"jcr:primaryType": "nt:unstructured",
"size": "is-normal",
"text": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit2.</p>",
"textWeight": "has-text-weight-normal"
}
},
"text": {
"title": "Title2"
}
}
}

0 comments on commit e0c3a42

Please sign in to comment.