001/*
002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Gabriel Barata
018 *     Yannis JULIENNE
019 */
020package org.nuxeo.functionaltests.pages.tabs;
021
022import java.util.List;
023
024import org.nuxeo.functionaltests.AbstractTest;
025import org.nuxeo.functionaltests.Required;
026import org.nuxeo.functionaltests.contentView.ContentViewElement;
027import org.nuxeo.functionaltests.pages.DocumentBasePage;
028import org.nuxeo.functionaltests.pages.forms.TopicCreationFormPage;
029import org.openqa.selenium.By;
030import org.openqa.selenium.NoSuchElementException;
031import org.openqa.selenium.WebDriver;
032import org.openqa.selenium.WebElement;
033import org.openqa.selenium.support.FindBy;
034
035/**
036 * @since 8.3
037 */
038public class ForumTabSubPage extends DocumentBasePage {
039
040    @FindBy(xpath = "//a[@id='nxw_newForumThread_form:nxw_newForumThread']")
041    public WebElement newTopicButtonLink;
042
043    @Required
044    @FindBy(id = "forum_content")
045    WebElement forumContentForm;
046
047    public ForumTabSubPage(WebDriver driver) {
048        super(driver);
049    }
050
051    protected ContentViewElement getElement() {
052        return AbstractTest.getWebFragment(By.id("cv_forum_content_0_panel"), ContentViewElement.class);
053    }
054
055    public List<WebElement> getChildTopicRows() {
056        return getElement().getItems();
057    }
058
059    public TopicCreationFormPage getTopicCreatePage() {
060        // Create a Topic
061        newTopicButtonLink.click();
062        return asPage(TopicCreationFormPage.class);
063    }
064
065    public TopicTabSubPage createTopic(String topicTitle, String topicDescription, Boolean moderated,
066            String... usersOrGroups) {
067        // Create a Topic
068        return getTopicCreatePage().createTopicDocument(topicTitle, topicDescription, moderated, usersOrGroups);
069    }
070
071    public boolean hasTopicLink(String title) {
072        try {
073            WebElement element = forumContentForm.findElement(By.linkText(title));
074            return element != null;
075        } catch (NoSuchElementException e) {
076            return false;
077        }
078    }
079
080    public boolean hasNewTopicButton() {
081        try {
082            return newTopicButtonLink.isDisplayed();
083        } catch (NoSuchElementException e) {
084            return false;
085        }
086    }
087
088}