Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from Cognifide/core-components-image-tests
Browse files Browse the repository at this point in the history
Add Image Component tests
  • Loading branch information
kaczymuczy authored Oct 7, 2019
2 parents 22cda17 + aa45792 commit 308bfca
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aem65/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def profiles = [
]

task loadProperties {
System.setProperty("bobcat.config", "yaml");
System.setProperty("bobcat.config", "yaml")
def profile = System.getProperty('profile', 'default')
if (!profile.equals('default')) {
System.setProperty("bobcat.config.contexts", profiles[profile])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.cognifide.qa.bb.constants.HtmlTags.Attributes;
import com.cognifide.qa.bb.qualifier.CurrentScope;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.google.inject.Inject;

@PageObject(css = ".cmp-image__image")
public class ImageComponent {

@Inject
@CurrentScope
private WebElement component;

@FindBy(xpath = "../span[contains(@class,'cmp-image__title')]")
private WebElement caption;

@FindBy(xpath = "..")
private WebElement link;

public String getSrc() {
return component.getAttribute(Attributes.SRC);
}

public String getAlt() {
return component.getAttribute(Attributes.ALT);
}

public String getCaption() {
return caption.getText();
}

public String getLink() {
return link.getAttribute(Attributes.HREF);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.cognifide.qa.bb.aem65.tests.corecomponents;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.cognifide.qa.bb.aem.core.api.AemActions;
import com.cognifide.qa.bb.aem.core.component.actions.ConfigureComponentData;
import com.cognifide.qa.bb.aem.core.component.configuration.ResourceFileLocation;
import com.cognifide.qa.bb.aem.core.pages.sling.SlingDataXMLBuilder;
import com.cognifide.qa.bb.aem.core.pages.sling.SlingPageData;
import com.cognifide.qa.bb.aem65.tests.AbstractAemAuthorTest;
import com.cognifide.qa.bb.aem65.tests.pageobjects.corecomponents.ImageComponent;
import com.cognifide.qa.bb.aem65.tests.pages.TestPage;
import com.cognifide.qa.bb.api.actions.ActionException;
import com.cognifide.qa.bb.junit5.guice.Modules;
import com.cognifide.qa.bb.modules.BobcatRunModule;

import io.qameta.allure.Epic;
import io.qameta.allure.Feature;

@Modules(BobcatRunModule.class)
@Epic("Core Components authoring tests")
@Feature("Image Component configuration")
@DisplayName("Author can configure for Image Component the...")
public class ImageComponentTest extends AbstractAemAuthorTest {

private static final String TEST_PAGE_PATH = "/content/we-retail/us/en/image-component-test-page";

private TestPage page;
private ImageComponent component;

@BeforeEach
public void setup() throws ActionException {
controller.execute(AemActions.CREATE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH,
SlingDataXMLBuilder.buildFromFile("testpages/core-components/imageComponentTestPage.xml")));
page = bobcatPageFactory.create("/editor.html" + TEST_PAGE_PATH + ".html", TestPage.class);
page.open();
}

@Test
@DisplayName("asset")
public void configureAsset() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Image", 1,
new ResourceFileLocation("component-configs/core-components/image/asset.yaml")));
component = page.getContent(ImageComponent.class, 1);
assertThat(component.getSrc()).as("Check if the img src is configured")
.matches(String.format(".*%s.*majestic-rainbow.jpeg", TEST_PAGE_PATH));
}

@Test
@DisplayName("decorative image metadata")
public void configureDecorativeImage() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Image", 0, new ResourceFileLocation(
"component-configs/core-components/image/decorative-image.yaml")));
component = page.getContent(ImageComponent.class, 0);
assertThat(component.getAlt()).as("Check if the alt attribute is empty").isEmpty();
}

@Test
@DisplayName("alternative text metadata")
public void configureAlternativeText() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Image", 0, new ResourceFileLocation(
"component-configs/core-components/image/alt-text.yaml")));
component = page.getContent(ImageComponent.class, 0);
assertThat(component.getAlt()).as("Check if the alt text is configured")
.matches("Custom alt text");

}

@Test
@DisplayName("caption metadata")
public void configureCaption() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Image", 0,
new ResourceFileLocation("component-configs/core-components/image/caption.yaml")));
component = page.getContent(ImageComponent.class, 0);
assertThat(component.getCaption()).as("Check if the caption text is configured")
.matches("Custom caption");
}

@Test
@DisplayName("link metadata")
public void configureLink() throws ActionException {
controller.execute(AemActions.CONFIGURE_COMPONENT,
new ConfigureComponentData("container", "Image", 0,
new ResourceFileLocation("component-configs/core-components/image/link.yaml")));
component = page.getContent(ImageComponent.class, 0);
assertThat(component.getLink()).as("Check if the link is configured")
.endsWith("/content/we-retail/us/en.html");
}

@AfterEach
public void cleanup() throws ActionException {
controller.execute(AemActions.DELETE_PAGE_VIA_SLING, new SlingPageData(TEST_PAGE_PATH));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Metadata:
- label: Get alternative text from DAM
type: CHECKBOX
value: false
- label: Alternative Text *
type: TEXTFIELD
value: Custom alt text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Asset:
- type: IMAGE
value: majestic-rainbow.jpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Metadata:
- label: Get caption from DAM
type: CHECKBOX
value: false
- label: Caption
type: TEXTFIELD
value: Custom caption
- label: Display caption as pop-up
type: CHECKBOX
value: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Metadata:
- label: Image is decorative
type: CHECKBOX
value: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Metadata:
- label: Link
type: PATHBROWSER
value: /content/we-retail/us/en
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:template="/conf/we-retail/settings/wcm/templates/content-page"
jcr:primaryType="cq:PageContent"
jcr:title="Image Component Test Page"
sling:resourceType="weretail/components/structure/page"
navTitle="Image Component Test Page"
pageTitle="Image Component Test Page">
<root
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm/foundation/components/responsivegrid">
<responsivegrid
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm/foundation/components/responsivegrid">
<image
jcr:primaryType="nt:unstructured"
sling:resourceType="weretail/components/content/image"
altValueFromDAM="true"
displayPopupTitle="true"
fileReference="/content/dam/we-retail/en/experiences/arctic-surfing-in-lofoten/northern-lights.jpg"
isDecorative="false"
titleValueFromDAM="true"/>
<image_642178494
jcr:primaryType="nt:unstructured"
sling:resourceType="weretail/components/content/image"/>
</responsivegrid>
</root>
</jcr:content>
</jcr:root>

0 comments on commit 308bfca

Please sign in to comment.