package cz.moneta.test.harness.connectors.mobile;

import cz.moneta.test.harness.support.mobile.MobileLookup;
import org.openqa.selenium.WebElement;

import java.util.List;

public class WebElementsCheck {

    private final AppiumMobileConnector connector;

    public WebElementsCheck(AppiumMobileConnector connector) {
        this.connector = connector;
    }

    public void checkElementContent(String path, String content, MobileLookup mobileLookup) {
        List<WebElement> elements = connector.waitForLazyElements(path, mobileLookup);
        elements.stream()
                .map(WebElement::getText)
                .filter(text -> text.contains(content))
                .findFirst()
                .orElseThrow(() -> new AssertionError(String.format("Cannot find element that contains text %s", content)));
    }

    public void checkElementPresent(String path, MobileLookup mobileLookup) {
        connector.waitForLazyElement(path, mobileLookup);
    }
}
