/*
 * 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.selenium.framework;

import org.junit.Assert;

/**
 * Implementation of skin-related actions for the Flamingo skin.
 *
 * @version $Id$
 * @since 6.2M2
 */
public class FlamingoSkinExecutor extends ColibriSkinExecutor
{
    public FlamingoSkinExecutor(AbstractXWikiTestCase test)
    {
        super(test);
    }

    @Override
    public boolean isAuthenticated(String username)
    {
        return getTest().isElementPresent(
                "//a[@id='tmUser' and contains(@href, '/xwiki/bin/view/XWiki/" + username + "')]");
    }

    @Override
    public boolean isAuthenticationMenuPresent()
    {
        return getTest().isElementPresent("//a[@id='tmLogin']") || getTest().isElementPresent("//li[@id='tmUser']");
    }

    @Override
    public void clickShowComments()
    {
        getTest().clickLinkWithLocator("//a[@id = 'Commentslink']", false);
    }

    @Override
    public void clickShowAttachments()
    {
        getTest().clickLinkWithLocator("//a[@id = 'Attachmentslink']", false);
    }

    @Override
    public void clickShowHistory()
    {
        getTest().clickLinkWithLocator("//a[@id = 'Historylink']", false);
    }

    @Override
    public void clickShowInformation()
    {
        getTest().clickLinkWithLocator("//a[@id = 'Informationlink']", false);
    }

    @Override
    public void logout()
    {
        Assert.assertTrue("User wasn't authenticated.", isAuthenticated());
        getTest().clickLinkWithLocator("//li[@id='tmUser']//a[contains(@class, 'dropdown-toggle')]");
        getTest().clickLinkWithLocator("//a[@id='tmLogout']");
        Assert.assertFalse("The user is still authenticated after a logout.", isAuthenticated());
    }

    @Override
    public void clickLogin()
    {
        getTest().clickLinkWithLocator("//a[@id='tmLogin']");
        assertIsLoginPage();
    }

    @Override
    public void clickRegister()
    {
        getTest().clickLinkWithLocator("//a[@id='tmRegister']");
        assertIsRegisterPage();
    }

    @Override
    protected void clickEditMenuItem(String menuItemId)
    {
        // Click on the arrow in the edit button
        getTest().clickLinkWithLocator("//div[@id='tmEdit']//button[contains(@class, 'dropdown-toggle')]");
        getTest().clickLinkWithLocator(menuItemId);
    }

    @Override
    public void clickCopyPage()
    {
        // Click on the arrow near the page name on the top menu
        getTest().clickLinkWithLocator("//li[@id='tmPage']//a[contains(@class, 'dropdown-toggle')]");
        getTest().clickLinkWithLocator("tmActionCopy");
    }
}

@@ -1355,29 +1355,28 @@
     
-    
 %22//
-a
+li
 %5B@id
-=
+ = 
 'tmUser'
  and
@@ -1375,13 +1375,12 @@
 ser'
- and 
+%5D/a%5B
 cont
@@ -1555,33 +1555,35 @@
 Present(%22//a%5B@id
-=
+ = 
 'tmLogin'%5D%22) %7C%7C 
@@ -1610,33 +1610,35 @@
 resent(%22//li%5B@id
-=
+ = 
 'tmUser'%5D%22);%0A   
@@ -2376,17 +2376,19 @@
 //li%5B@id
-=
+ = 
 'tmUser'
@@ -2389,17 +2389,16 @@
 mUser'%5D/
-/
 a%5Bcontai
@@ -2410,38 +2410,43 @@
 lass, 'dropdown-
-toggle
+split-right
 ')%5D%22);%0A        g
@@ -2479,25 +2479,27 @@
 tor(%22//a%5B@id
-=
+ = 
 'tmLogout'%5D%22
@@ -2702,17 +2702,19 @@
 %22//a%5B@id
-=
+ = 
 'tmLogin
@@ -2854,17 +2854,19 @@
 %22//a%5B@id
-=
+ = 
 'tmRegis
@@ -3087,17 +3087,19 @@
 /div%5B@id
-=
+ = 
 'tmEdit'
@@ -3100,17 +3100,16 @@
 mEdit'%5D/
-/
 button%5Bc
@@ -3371,17 +3371,19 @@
 //li%5B@id
-=
+ = 
 'tmPage'
@@ -3384,17 +3384,16 @@
 mPage'%5D/
-/
 a%5Bcontai
@@ -3405,38 +3405,43 @@
 lass, 'dropdown-
-toggle
+split-right
 ')%5D%22);%0A        g

Enable default actions for the Flamingo top menu entries * Update test page objects.