/*
   * CaseId 77703: Post an activity with "Connections" filter selected
   * CaseId 77708: Comment from "Connections"
   * Pre-Condition: john and demo must be connected each other before tests started
   */
  @Test
  public void test04_ActivityComment_ConnectionsFilter() {
    String activity = "Connections filter: Post an activity by demo.";
    String comment = "Connections filter: Comment for an activity by john.";

    // Create data for Pre-Conditions
    naviToolbar.goToConnectionPage();
    conn.connectPeople(fullname_demo);
    magAc.userSignIn(userType.DEVELOPER);
    naviToolbar.goToConnectionPage();
    conn.acceptInvitation(fullname_john);
    magAc.userSignIn(userType.ADMIN);

    // Start test case
    naviToolbar.goToHomePage();

    // Step1: Connections filter is displayed
    selectFileter("Connections");

    // sign-in by demo. Add an activity
    magAc.userSignIn(userType.DEVELOPER);
    naviToolbar.goToHomePage();
    addActivity(true, activity, false, "");

    // sign-in by john. Select Connections filter
    magAc.userSignIn(userType.ADMIN);
    naviToolbar.goToHomePage();
    selectFileter("Connections");

    // Step2: Add a comment. Select All Activities filter.
    addComment(activity, comment);
    selectFileter("All Activities");

    // Select Connections filter
    selectFileter("Connections");

    // Delete activity before exit test cases
    magAc.userSignIn(userType.DEVELOPER);
    naviToolbar.goToHomePage();
    hpActivity.deleteActivity(activity);
    naviToolbar.goToConnectionPage();
    conn.removeConnection(fullname_john);
  }
  /*
   * https://jira.exoplatform.org/browse/CAL-1117
   * Id test :104241
   * Name: Private events should only be searchable by their owner
   * Step 1 : User James search "SEARCH_EVENT_05".
   */
  @Test(groups = "pending")
  public void test05_PrivateEventsShouldOnlyBeSearchableByTheirOwner() {
    String eventDescription = "SEARCH_EVENT_05";
    String eventName1 = "Private shared" + getRandomNumber();
    String eventName2 = "Public shared" + getRandomNumber();
    String eventName3 = "Unset shared" + getRandomNumber();
    String eventName4 = "Private group" + getRandomNumber();
    String eventName5 = "Public group" + getRandomNumber();
    String eventName6 = "Unset group" + getRandomNumber();
    String spaceName = "Engineering" + getRandomNumber();
    String calendarNameShare = "CalShared" + getRandomNumber();
    String[] nomShare = {"james"};
    boolean[] edit = {false};

    goToCalendarPage();

    info("Create a share calendar with James");
    addCalendar(calendarNameShare, "", "pink");
    shareCalendar(calendarNameShare, nomShare, edit, 1);

    //		 * pre conditions

    info("Add event1 with private privacy");
    evt.addQuickEvent(
        eventName1,
        eventDescription,
        getDate(1, "MM/dd/yyyy 02:00"),
        getDate(1, "MM/dd/yyyy 03:00"),
        false,
        calendarNameShare);
    evt.goToEditEventForm(eventName1);
    click(evt.ELEMENT_PARTICIPANTS_TAB);
    check(evt.ELEMENT_PARTICIPANT_PRIVATE_RADIO, 2);
    waitForAndGetElement(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);
    click(ELEMENT_BUTTON_EVENT_SAVE_EDIT);
    waitForElementNotPresent(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);

    info("Add event2 with public shared");
    evt.addQuickEvent(
        eventName2,
        eventDescription,
        getDate(1, "MM/dd/yyyy 06:00"),
        getDate(1, "MM/dd/yyyy 07:00"),
        false,
        calendarNameShare);
    evt.goToEditEventForm(eventName2);
    click(evt.ELEMENT_PARTICIPANTS_TAB);
    check(evt.ELEMENT_PARTICIPANT_PUBLIC_RADIO, 2);
    waitForAndGetElement(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);
    click(ELEMENT_BUTTON_EVENT_SAVE_EDIT);
    waitForElementNotPresent(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);

    info("add event3 with unset privacy");
    evt.addQuickEvent(
        eventName3,
        eventDescription,
        getDate(1, "MM/dd/yyyy 08:00"),
        getDate(1, "MM/dd/yyyy 09:00"),
        false,
        calendarNameShare);

    magMember.goToMySpacePage();
    magMember.addNewSpace(spaceName, "");
    info("New space added : " + spaceName);
    click(spaceMag.ELEMENT_SPACE_CALENDAR_PORTLET);

    info("Add event3 with private privacy");
    evt.addQuickEvent(
        eventName4,
        eventDescription,
        getDate(1, "MM/dd/yyyy 10:00"),
        getDate(1, "MM/dd/yyyy 11:00"),
        false);
    evt.goToEditEventForm(eventName4);
    click(evt.ELEMENT_PARTICIPANTS_TAB);
    check(evt.ELEMENT_PARTICIPANT_PRIVATE_RADIO, 2);
    waitForAndGetElement(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);
    click(ELEMENT_BUTTON_EVENT_SAVE_EDIT);
    waitForElementNotPresent(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);

    info("Add event4 with public privacy");
    evt.addQuickEvent(
        eventName5,
        eventDescription,
        getDate(1, "MM/dd/yyyy 12:00"),
        getDate(1, "MM/dd/yyyy 13:00"),
        false);
    evt.goToEditEventForm(eventName5);
    click(evt.ELEMENT_PARTICIPANTS_TAB);
    check(evt.ELEMENT_PARTICIPANT_PUBLIC_RADIO, 2);
    waitForAndGetElement(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);
    click(ELEMENT_BUTTON_EVENT_SAVE_EDIT);
    waitForElementNotPresent(ELEMENT_BUTTON_EVENT_SAVE_EDIT, DEFAULT_TIMEOUT, 1);

    driver.navigate().refresh();
    Utils.pause(2000);

    info("Add event5 with unset privacy");
    evt.addQuickEvent(
        eventName6,
        eventDescription,
        getDate(1, "MM/dd/yyyy 14:00"),
        getDate(1, "MM/dd/yyyy 15:00"),
        false);

    info("Invit user James in space engineering ");
    click(magMember.ELEMENT_SPACE_SETTING_PORTLET);
    click(magMember.ELEMENT_MEMBER_TAB);
    magMember.inviteSingleUser("James");

    /*
     * step 1 search for  "SEARCH_EVENT_05 "
     */
    info("Log with user James");
    magAcc.userSignIn(userType.AUTHOR);
    info("Accept invitation");
    hGadget.acceptSpaceInvitationGadget(spaceName);
    driver.navigate().refresh();
    info("Search event : " + eventDescription);
    qsPage.quickSearch(eventDescription);
    qsPage.searchInSearchPage(eventDescription);
    info("Check the results");
    waitForElementNotPresent(qsPage.ELEMENT_RESULT_ITEM.replace("${keySearch}", eventName1));
    waitForAndGetElement(qsPage.ELEMENT_RESULT_ITEM.replace("${keySearch}", eventName2));
    waitForAndGetElement(qsPage.ELEMENT_RESULT_ITEM.replace("${keySearch}", eventName3));
    waitForElementNotPresent(qsPage.ELEMENT_RESULT_ITEM.replace("${keySearch}", eventName4));
    waitForAndGetElement(qsPage.ELEMENT_RESULT_ITEM.replace("${keySearch}", eventName5));
    waitForAndGetElement(qsPage.ELEMENT_RESULT_ITEM.replace("${keySearch}", eventName6));

    magAcc.signIn(DATA_USER1, DATA_PASS);
    info("Delete all events and tasks");
    goToCalendarPage();
    goToView(selectViewOption.LIST);
    deleteAllTaskEvent();
  }
  /**
   * Case ID:107032. Test Case Name: Move Post of normal users by Administrator. Pre-Condition:
   * Post-Condition: Done with OSs and browsers : Generated by phuongdt at 2014/01/22 10:24:54
   */
  @Test
  public void test01_MovePostOfNormalUsersByAdministrator() {
    String titleCat = "Category " + getRandomNumber();
    String titleForum = "Forum " + getRandomNumber();
    String titleTop1 = "Topic " + getRandomNumber();
    String titleTop2 = "Topic " + getRandomNumber();
    String post1 = "Post " + getRandomNumber();

    info("Test 01 Move Post of normal users by Administrator");
    /*Step Number: 1
    *Step Name: Step 1: Create topic
    *Step Description:
    	- Login as administrator to create a new category, forum, 2 topics"Topic A.1.1" and "To move demo's post"
    *Input Data:

    *Expected Outcome:
    	- Categories, forums, topics are created*/
    mngFru.addCategoryForum(titleCat, titleForum);
    click(mngTopic.ELEMENT_START_TOPIC_BUTTON);
    mngTopic.startTopic(titleTop1, titleTop1, "", 0, null, true, true);
    click(mngTopic.ELEMENT_START_TOPIC_BUTTON);
    mngTopic.startTopic(titleTop2, titleTop2, "", 0, null, true, true);

    /*Step number: 2
    *Step Name: Step 2: Add post(s) by normal users
    *Step Description:
    	- Log in as demo
    	- Post a reply to "Topic A.1.1"
    *Input Data:

    *Expected Outcome:
    	- Post(s) is created*/
    magAc.signIn(DATA_USER4, DATA_PASS1);
    goToForums();
    click(By.linkText(titleForum));
    click(By.linkText(titleTop1));
    mngPost.postReply(post1, post1, "", "");

    /*Step number: 3
    *Step Name: Step 3: Move post by Admin
    *Step Description:
    	- Login as admin
    	- Move demo's post from "Topic A.1.1" to "To move demo's post"
    *Input Data:

    *Expected Outcome:
    	This post is removed from "Topic A.1.1" and move to "To move demo's post"*/
    magAc.userSignIn(userType.ADMIN);
    goToForums();
    click(By.linkText(titleForum));
    click(By.linkText(titleTop1));
    mngPost.movePost(post1, titleCat + "/" + titleForum + "/" + titleTop2);

    /*Step number: 4
    *Step Name: Step 4: Move to Other topic
    *Step Description:
    	- Move again demo's post from "To move demo's post" to another topic
    *Input Data:

    *Expected Outcome:
    	Move successfully and no Ui error no exception in console*/
    click(By.linkText(titleCat));
    click(By.linkText(titleForum));
    click(By.linkText(titleTop2));
    mngPost.movePost(post1, titleCat + "/" + titleForum + "/" + titleTop1);

    // Clear data
    info("Clear data");
    click(By.linkText(titleCat));
    mngCat.deleteCategoryInForum(titleCat, true);
  }