/**
   * Test - AONE-13000:Combination - Account and Case
   *
   * <ul>
   *   <li>Login
   *   <li>From My Dashboard, access the Advance Search CRM form
   *   <li>In the Account Identifier Search text of the CRM search form, enter 001b0000009aPo1AAE
   *   <li>In the Account Name Search text of the CRM search form, enter helloaccount
   *   <li>In the Case Number Search text of the CRM search form, enter 00001006
   *   <li>In the Case Name Search text of the CRM search form, enter 00001006
   *   <li>Validate the search results is same for all combinations of search and any one of the
   *       result item should be from helloaccountoppor folder.
   * </ul>
   */
  @Test
  public void AONE_13881() throws PageException, Exception {
    // Login
    ShareUser.login(drone, salesforceUserName, salesforcePassword);

    // Advance CRM Search with Account Name and Contract Number
    keyWordSearchText.clear();
    keyWordSearchText.put(SearchKeys.ACCOUNT_NAME.getSearchKeys(), accountName);
    keyWordSearchText.put(SearchKeys.CASE_NUMBER.getSearchKeys(), caseNameOrNumber);

    List<SearchResult> results = ShareUserSearchPage.advanceSearchForCRM(drone, keyWordSearchText);
    Assert.assertTrue(results.size() > 0);
    Assert.assertTrue(results.size() == 1);
    Assert.assertTrue(results.get(0).getTitle().equalsIgnoreCase(case_Content));

    // Advance CRM Search with Account Name, Identifier, Case Number and Case Name.
    keyWordSearchText.clear();
    keyWordSearchText.put(SearchKeys.ACCOUNT_NAME.getSearchKeys(), accountName);
    keyWordSearchText.put(SearchKeys.CASE_NAME.getSearchKeys(), caseNameOrNumber);
    keyWordSearchText.put(SearchKeys.CASE_NUMBER.getSearchKeys(), caseNameOrNumber);
    keyWordSearchText.put(SearchKeys.ACCOUNT_IDENTIFIER.getSearchKeys(), accountIdentifier);

    results = ShareUserSearchPage.advanceSearchForCRM(drone, keyWordSearchText);
    Assert.assertTrue(results.size() > 0);
    Assert.assertTrue(results.size() == 1);
    Assert.assertTrue(results.get(0).getTitle().equalsIgnoreCase(case_Content));

    // Retrieving the folderNames from folderPath of the first resultItem.
    List<String> folders = ((SearchResultItem) results.get(0)).getFolderNamesFromContentPath();

    Assert.assertTrue(folders.get(0).equalsIgnoreCase(attachments_Folder));
    Assert.assertTrue(folders.get(1).equalsIgnoreCase(caseNameOrNumber));

    // Advance CRM Search with Account Identifier and Case Name.
    keyWordSearchText.clear();
    keyWordSearchText.put(SearchKeys.CASE_NAME.getSearchKeys(), caseNameOrNumber);
    keyWordSearchText.put(SearchKeys.ACCOUNT_IDENTIFIER.getSearchKeys(), accountIdentifier);

    results = ShareUserSearchPage.advanceSearchForCRM(drone, keyWordSearchText);
    Assert.assertTrue(results.size() > 0);
    Assert.assertTrue(results.size() == 1);
    Assert.assertTrue(results.get(0).getTitle().equalsIgnoreCase(case_Content));

    // Advance CRM Search with Account Identifier and Case Number.
    keyWordSearchText.clear();
    keyWordSearchText.put(SearchKeys.CASE_NUMBER.getSearchKeys(), caseNameOrNumber);
    keyWordSearchText.put(SearchKeys.ACCOUNT_IDENTIFIER.getSearchKeys(), accountIdentifier);

    results = ShareUserSearchPage.advanceSearchForCRM(drone, keyWordSearchText);
    Assert.assertTrue(results.size() > 0);
    Assert.assertTrue(results.size() == 1);
    Assert.assertTrue(results.get(0).getTitle().equalsIgnoreCase(case_Content));
  }
  /**
   * Test - Cloud-310:Account Search based on both name and identifier
   *
   * <ul>
   *   <li>Login
   *   <li>From My Dashboard, access the Advance Search CRM form
   *   <li>In the Account Identifier Search text of the CRM search form, enter 001b0000009aPo1AAE
   *   <li>In the Account Name Search text of the CRM search form enter helloaccount
   *   <li>Validate the search results are returned 4 rows of results
   *   <li>Validate the search results, any one of the result item should be from helloaccount
   *       folder.
   * </ul>
   */
  @Test
  public void AONE_13871() throws PageException, Exception {
    // Login
    ShareUser.login(drone, salesforceUserName, salesforcePassword);

    // Advance CRM Search with Account Identifier and Account Name
    keyWordSearchText.clear();
    keyWordSearchText.put(SearchKeys.ACCOUNT_IDENTIFIER.getSearchKeys(), accountIdentifier);
    keyWordSearchText.put(SearchKeys.ACCOUNT_NAME.getSearchKeys(), accountName);

    List<SearchResult> results = ShareUserSearchPage.advanceSearchForCRM(drone, keyWordSearchText);
    Assert.assertTrue(results.size() == 4);

    List<String> folders = new LinkedList<String>();

    // Finding the specific result item.
    for (SearchResult searchItem : results) {
      if (searchItem.getTitle().equalsIgnoreCase(account_Content)) {
        // Retrieving the folderNames from folderPath of the first resultItem.
        folders = ((SearchResultItem) searchItem).getFolderNamesFromContentPath();
      }
    }
    Assert.assertTrue(folders.size() > 0);
    Assert.assertTrue(folders.get(0).equalsIgnoreCase(attachments_Folder));
    Assert.assertTrue(folders.get(1).equalsIgnoreCase(accountName));
  }