001/*
002    Licensed to the Apache Software Foundation (ASF) under one
003    or more contributor license agreements.  See the NOTICE file
004    distributed with this work for additional information
005    regarding copyright ownership.  The ASF licenses this file
006    to you under the Apache License, Version 2.0 (the
007    "License"); you may not use this file except in compliance
008    with the License.  You may obtain a copy of the License at
009
010       http://www.apache.org/licenses/LICENSE-2.0
011
012    Unless required by applicable law or agreed to in writing,
013    software distributed under the License is distributed on an
014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015    KIND, either express or implied.  See the License for the
016    specific language governing permissions and limitations
017    under the License.    
018 */
019package org.apache.wiki.pages.haddock;
020
021import org.apache.wiki.pages.Page;
022import org.openqa.selenium.By;
023
024import com.codeborne.selenide.Condition;
025import com.codeborne.selenide.Selenide;
026import com.codeborne.selenide.SelenideElement;
027
028/**
029 * Actions available on the View page.
030 */
031public class ViewWikiPage implements HaddockPage {
032
033    /**
034     * Open a given page for view.
035     *
036     * @param pageName Wiki page name to View.
037     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
038     */
039    public static ViewWikiPage open(final String pageName ) {
040        return Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=" + pageName ).openAs( new ViewWikiPage() );
041    }
042
043    /**
044     * Returns the authenticated user text.
045     *
046     * @return the authenticated user text.
047     */
048    public String authenticatedText() {
049        return Selenide.$( By.className( "wikipage" ) ).text().trim();
050    }
051
052    /**
053     * Clicks on the login button.
054     *
055     * @return {@link LoginPage} instance, to allow chaining of actions.
056     */
057    public LoginPage clickOnLogin() {
058        hoverLoginArea();
059        Selenide.$( By.className( "icon-signin" ) ).click(); 
060        return new LoginPage();
061    }
062
063    /**
064     * Clicks on the show reader view link.
065     *
066     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
067     */
068    public ViewWikiPage clickOnShowReaderView() {
069        Selenide.$( By.linkText( "Show Reader View" ) ).click();
070        return this;
071    }
072
073    /**
074     * Hover's the user's icon, so the login area gets visible.
075     *
076     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
077     */
078    public ViewWikiPage hoverLoginArea() {
079        Selenide.$( By.className( "icon-user" ) ).hover();
080        return this;
081    }
082
083    /**
084     * Hover's the More tab, making its associated pane visible.
085     *
086     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
087     */
088    public ViewWikiPage hoverMoreArea() {
089        Selenide.$( By.id( "more" ) ).hover();
090        return this;
091    }
092
093    /**
094     * Clicks the edit link.
095     *
096     * @return {@link EditWikiPage} instance, to allow chaining of actions.
097     */
098    public EditWikiPage editPage() {
099        Selenide.$( By.cssSelector( "li#edit a" ) ).waitUntil( Condition.visible, 1_000L ).click();
100        return new EditWikiPage();
101    }
102
103    /**
104     * Searches for a given text.
105     *
106     * @param text text to search for.
107     * @return {@link SearchResultsPage} instance, to allow chaining of actions.
108     */
109    public SearchResultsPage searchFor( final String text ) {
110        Selenide.$( By.id( "searchForm" ) ).hover();
111        Selenide.$( By.id( "query" ) ).click();
112        Selenide.$( By.id( "query" ) ).val( text );
113        Selenide.$( By.id( "searchSubmit" ) ).click();
114        return new SearchResultsPage();
115    }
116
117    /**
118     * Logs the user out.
119     *
120     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
121     */
122    public ViewWikiPage clickOnLogout() {
123        hoverLoginArea();
124        Selenide.$( By.linkText( "Log out" ) ).click();
125        Selenide.$( By.className( "btn-success" ) ).waitUntil( Condition.visible, 1_000L ).click();
126        return this;
127    }
128
129    /**
130     * Navigates to a given view page.
131     *
132     * @param wikiPageName wikipage name to navigate to.
133     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
134     */
135    public ViewWikiPage navigateTo(final String wikiPageName ) {
136        Selenide.$( By.linkText( wikiPageName ) ).click(); 
137        return this;
138    }
139
140    /**
141     * Returns the sidebar element.
142     *
143     * @return the sidebar element.
144     */
145    public SelenideElement sidebar() {
146        return Selenide.$( By.className( "sidebar" ) );
147    }
148
149}