-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../backend/src/test/java/pl/ds/kyanite/common/components/models/AccordionComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
applications/common/backend/src/test/resources/accordion.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |