Package org.xwiki.test.ui.appwithinminutes

Source Code of org.xwiki.test.ui.appwithinminutes.LiveTableEditorTest

/*
* 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.test.ui.appwithinminutes;

import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage;
import org.xwiki.appwithinminutes.test.po.ApplicationHomePage;
import org.xwiki.test.ui.AbstractAdminAuthenticatedTest;
import org.xwiki.test.ui.browser.IgnoreBrowser;
import org.xwiki.test.ui.browser.IgnoreBrowsers;
import org.xwiki.test.ui.po.LiveTableElement;

/**
* Tests the last step of the App Within Minutes wizard.
*
* @version $Id: dfe53e7a4e628429a7185d494d2935d8dc391e95 $
* @since 4.0M1
*/
public class LiveTableEditorTest extends AbstractAdminAuthenticatedTest
{
    /**
     * The page being tested.
     */
    private ApplicationHomeEditPage editPage;

    /**
     * The query string parameters passed to the edit action.
     */
    private final Map<String, String> editQueryStringParameters = new HashMap<String, String>();

    @Before
    @Override
    public void setUp() throws Exception
    {
        super.setUp();

        getUtil().deletePage(getTestClassName(), getTestMethodName());
        editQueryStringParameters.put("editor", "inline");
        editQueryStringParameters.put("template", "AppWithinMinutes.LiveTableTemplate");
        editQueryStringParameters.put("AppWithinMinutes.LiveTableClass_0_class", "XWiki.XWikiUsers");
        getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", editQueryStringParameters);
        editPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded();
    }

    /**
     * Adds, removes and reorders live table columns.
     */
    @Test
    @IgnoreBrowsers({
    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
    })
    public void testManageColumns()
    {
        editPage.addLiveTableColumn("First Name");
        Assert.assertTrue(editPage.hasLiveTableColumn("First Name"));
        editPage.moveLiveTableColumnBefore("First Name", "Update date");
        editPage.removeLiveTableColumn("Page name");
        Assert.assertFalse(editPage.hasLiveTableColumn("Page name"));
        LiveTableElement liveTable = ((ApplicationHomePage) editPage.clickSaveAndView()).getEntriesLiveTable();
        liveTable.waitUntilReady();
        // The column titles aren't translated because we haven't generated the document translation bundle.
        Assert.assertFalse(liveTable.hasColumn("xwikiusers.livetable.doc.name"));
        Assert.assertEquals(0, liveTable.getColumnIndex("xwikiusers.livetable.first_name"));
        Assert.assertEquals(1, liveTable.getColumnIndex("xwikiusers.livetable.doc.date"));
    }

    /**
     * Tests that Save & Continue works fine.
     */
    @Test
    @IgnoreBrowsers({
    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
    })
    public void testSaveAndContinue()
    {
        editPage.setDescription("wait for WYSIWYG to load");
        editPage.clickSaveAndContinue();
        ApplicationHomePage viewPage = editPage.clickCancel();
        LiveTableElement liveTable = viewPage.getEntriesLiveTable();
        liveTable.waitUntilReady();
        // The column title isn't translated because we haven't generated the document translation bundle.
        Assert.assertTrue(liveTable.hasColumn("xwikiusers.livetable.doc.name"));
    }

    /**
     * Tests how deprecated columns are handled.
     */
    @Test
    public void testDeprecatedColumns()
    {
        // Fake a deprecated column by using a column that doesn't exist.
        editQueryStringParameters.put("AppWithinMinutes.LiveTableClass_0_columns", "doc.name foo");
        getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", editQueryStringParameters);
        editPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded();

        Assert.assertTrue(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
        Assert.assertFalse(editPage.isLiveTableColumnDeprecated("Page name"));
        Assert.assertTrue(editPage.isLiveTableColumnDeprecated("foo"));

        // Keep deprecated columns.
        editPage.removeAllDeprecatedLiveTableColumns(false);
        Assert.assertFalse(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
        Assert.assertTrue(editPage.isLiveTableColumnDeprecated("foo"));
        ApplicationHomePage viewPage = editPage.clickSaveAndView();
        LiveTableElement liveTable = viewPage.getEntriesLiveTable();
        liveTable.waitUntilReady();
        // The column title isn't translated because we haven't generated the document translation bundle.
        Assert.assertTrue(liveTable.hasColumn("xwikiusers.livetable.foo"));

        // Edit again and remove the deprecated column.
        editPage = viewPage.editInline();
        Assert.assertTrue(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
        editPage.removeLiveTableColumn("foo");
        Assert.assertFalse(editPage.hasLiveTableColumn("foo"));
        // The warning must disappear if we remove the deprecated column.
        Assert.assertFalse(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());

        // Reload and remove all deprecated columns.
        getDriver().navigate().refresh();
        editPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded();
        editPage.removeAllDeprecatedLiveTableColumns(true);
        Assert.assertFalse(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
        Assert.assertTrue(editPage.hasLiveTableColumn("Page name"));
        Assert.assertFalse(editPage.hasLiveTableColumn("foo"));
    }

    /**
     * Tests that the live table isn't generated if the list of columns is empty.
     */
    @Test
    public void testNoColumns()
    {
        // Make sure the list of columns is empty.
        editQueryStringParameters.put("AppWithinMinutes.LiveTableClass_0_columns", "");
        getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", editQueryStringParameters);
        // Wait for the page to load before clicking on the save button to be sure the page layout is stable.
        ApplicationHomePage viewPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded().clickSaveAndView();
        Assert.assertFalse(viewPage.hasEntriesLiveTable());
        Assert.assertEquals("", viewPage.editWiki().getContent());
    }
}
TOP

Related Classes of org.xwiki.test.ui.appwithinminutes.LiveTableEditorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.