/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.livedata.test.po;

import org.xwiki.test.ui.po.BaseElement;

/**
 * Live Data page object. Provides the operations to obtain the page objects for the different live data layouts, and to
 * switch between them.
 *
 * @version $Id$
 * @since 13.4RC1
 */
public class LiveDataElement extends BaseElement
{
    // TODO: add the operations to switch between the layouts.

    private final String id;

    /**
     * Default constructor. Initializes a Live Data page object by its id.
     *
     * @param id the live data id
     */
    public LiveDataElement(String id)
    {
        this.id = id;
    }

    /**
     * @return a table layout page object for the live data
     */
    public TableLayoutElement getTableLayout()
    {
        TableLayoutElement tableLayoutElement = new TableLayoutElement(this.id);
        tableLayoutElement.waitUntilReady();
        return tableLayoutElement;
    }

    /**
     * @return a cart layout page object for the live data
     */
    public CardLayoutElement getCardLayout()
    {
        return new CardLayoutElement(this.id);
    }
}

@@ -924,16 +924,73 @@
 st.po;%0A%0A
+import java.util.Arrays;%0A%0Aimport org.openqa.selenium.By;%0A
 import o
@@ -1022,16 +1022,16 @@
 lement;%0A
-
 %0A/**%0A * 
@@ -1557,16 +1557,42 @@
 d = id;%0A
+        waitUntilReady();%0A
     %7D%0A%0A 
@@ -2005,32 +2005,32 @@
 dLayout()%0A    %7B%0A
-
         return n
@@ -2065,11 +2065,875 @@
 );%0A    %7D
+%0A%0A    private void waitUntilReady()%0A    %7B%0A        // First the Live Data macro displays a simple div with the loading class.%0A        // This div is replaced by the Live Data Vue template once vue is loaded.%0A        getDriver().waitUntilCondition(%0A            input -%3E %7B%0A                String%5B%5D classes = getDriver().findElement(By.id(this.id)).getAttribute(%22class%22).split(%22%5C%5Cs+%22);%0A                return !Arrays.asList(classes).contains(%22loading%22);%0A            %7D);%0A%0A        // Then, once the Vue template is loaded, a div with the loading class is inserted until the rest of the data %0A        // and components required to display the Live Data are loaded too. %0A        getDriver().waitUntilCondition(%0A            input -%3E getDriver().findElement(By.id(this.id)).findElements(By.cssSelector(%22.xwiki-livedata .loading%22))%0A                .isEmpty()%0A        );%0A    %7D
 %0A%7D%0A

Introduce LiveDataElement wait until ready