/**
   * Test case :Delete Text signature using Delete button and verify toast msg throguh GUI @Steps:
   * Create signature through soap Delete signature using delete button. Verify signature toast msg
   *
   * @throws HarnessException
   */
  @Test(
      description = " Delete Text signature using Delete button and verify toast msg throguh GUI ",
      groups = {"smoke"})
  public void DeleteSignaturesToastMsg() throws HarnessException {

    // Click on Mail/signature
    app.zTreePreferences.zTreeItem(Action.A_LEFTCLICK, TreeItem.MailSignatures);

    // Signature is created
    SignatureItem signature = SignatureItem.importFromSOAP(app.zGetActiveAccount(), this.sigName);
    ZAssert.assertEquals(signature.getName(), this.sigName, "verified Text Signature is created");

    FormSignatureNew signew = new FormSignatureNew(app);

    // Select signature which is to be Delete
    signew.zClick(Locators.zSignatureListView);
    signew.zClick("//td[contains(text(),'" + signature.getName() + "')]");

    // click Delete button
    app.zPageSignature.zToolbarPressButton(Button.B_DELETE);
    // click Save
    signew.zSubmit();

    // Verifying the toaster message
    Toaster toast = app.zPageMain.zGetToaster();
    String toastMsg = toast.zGetToastMessage();
    ZAssert.assertStringContains(
        toastMsg, "Preferences Saved", "Verify toast message: Preferences Saved");
  }
  @Test(
      description =
          "Delete a task by selecting and typing 'delete' keyboard-Verify Toast message through GUI",
      groups = {"smoke"},
      dataProvider = "DataProviderDeleteKeys")
  public void DeleteTaskToastMsg_03(String name, int keyEvent) throws HarnessException {

    FolderItem taskFolder = FolderItem.importFromSOAP(app.zGetActiveAccount(), SystemFolder.Tasks);

    // Create a basic task to delete
    String subject = "task" + ZimbraSeleniumProperties.getUniqueString();

    app.zGetActiveAccount()
        .soapSend(
            "<CreateTaskRequest xmlns='urn:zimbraMail'>"
                + "<m >"
                + "<inv>"
                + "<comp name='"
                + subject
                + "'>"
                + "<or a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</comp>"
                + "</inv>"
                + "<su>"
                + subject
                + "</su>"
                + "<mp ct='text/plain'>"
                + "<content>content"
                + ZimbraSeleniumProperties.getUniqueString()
                + "</content>"
                + "</mp>"
                + "</m>"
                + "</CreateTaskRequest>");

    GeneralUtility.syncDesktopToZcsWithSoap(app.zGetActiveAccount());

    TaskItem task = TaskItem.importFromSOAP(app.zGetActiveAccount(), subject);
    ZAssert.assertNotNull(task, "Verify the task is created");

    // Refresh the tasks view
    app.zPageTasks.zToolbarPressButton(Button.B_REFRESH);
    app.zTreeTasks.zTreeItem(Action.A_LEFTCLICK, taskFolder);

    // Select the item
    app.zPageTasks.zListItem(Action.A_MAIL_CHECKBOX, subject);

    // Click delete keyboard
    logger.info("Typing shortcut key " + name + " KeyEvent: " + keyEvent);
    app.zPageMail.zKeyboardKeyEvent(keyEvent);

    // Verifying the toaster message
    Toaster toast = app.zPageMain.zGetToaster();
    String toastMsg = toast.zGetToastMessage();
    ZAssert.assertStringContains(
        toastMsg, "1 task moved to Trash", "Verify toast message: Task Moved To trash");
  }
  @Test(
      description =
          "Create task through SOAP - delete using Backspace Key & verify Toast message through GUI",
      groups = {"functional"})
  public void DeleteTaskToastMsg_07() throws HarnessException {

    FolderItem taskFolder = FolderItem.importFromSOAP(app.zGetActiveAccount(), SystemFolder.Tasks);

    // Create a basic task to delete
    String subject = "task" + ZimbraSeleniumProperties.getUniqueString();

    app.zGetActiveAccount()
        .soapSend(
            "<CreateTaskRequest xmlns='urn:zimbraMail'>"
                + "<m >"
                + "<inv>"
                + "<comp name='"
                + subject
                + "'>"
                + "<or a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</comp>"
                + "</inv>"
                + "<su>"
                + subject
                + "</su>"
                + "<mp ct='text/plain'>"
                + "<content>content"
                + ZimbraSeleniumProperties.getUniqueString()
                + "</content>"
                + "</mp>"
                + "</m>"
                + "</CreateTaskRequest>");

    GeneralUtility.syncDesktopToZcsWithSoap(app.zGetActiveAccount());

    TaskItem task = TaskItem.importFromSOAP(app.zGetActiveAccount(), subject);
    ZAssert.assertNotNull(task, "Verify the task is created");

    // Refresh the tasks view
    app.zPageTasks.zToolbarPressButton(Button.B_REFRESH);
    app.zTreeTasks.zTreeItem(Action.A_LEFTCLICK, taskFolder);

    // Select the item
    app.zPageTasks.zListItem(Action.A_MAIL_CHECKBOX, subject);

    // Use Backspace Keyboard Shortcut
    app.zPageTasks.zKeyboardShortcut(Shortcut.S_BACKSPACE);

    // Verifying the toaster message
    Toaster toast = app.zPageMain.zGetToaster();
    String toastMsg = toast.zGetToastMessage();
    ZAssert.assertStringContains(
        toastMsg, "1 task moved to Trash", "Verify toast message: Task Moved to Trash");
  }
  // verify contact tagged with tag and toasted message
  private void Verify(ContactItem contactItem, String tagName) throws HarnessException {
    // Make sure the tag was created on the server (get the tag ID)
    app.zGetActiveAccount().soapSend("<GetTagRequest xmlns='urn:zimbraMail'/>");
    ;
    String tagID =
        app.zGetActiveAccount()
            .soapSelectValue("//mail:GetTagResponse//mail:tag[@name='" + tagName + "']", "id");

    // Make sure the tag was applied to the contact
    app.zGetActiveAccount()
        .soapSend(
            "<GetContactsRequest xmlns='urn:zimbraMail'>"
                + "<cn id='"
                + contactItem.getId()
                + "'/>"
                + "</GetContactsRequest>");

    String contactTags =
        app.zGetActiveAccount().soapSelectValue("//mail:GetContactsResponse//mail:cn", "t");

    // if multi-tagged
    if (contactTags.contains(",")) {
      ZAssert.assertStringContains(
          contactTags, tagID, "Verify the tag appears on the contact id=" + contactItem.getId());
    } else {
      ZAssert.assertEquals(
          contactTags, tagID, "Verify the tag appears on the contact id=" + contactItem.getId());
    }
    // verify toasted message '1 contact tagged ...'
    Toaster toast = app.zPageMain.zGetToaster();
    String toastMsg = toast.zGetToastMessage();
    ZAssert.assertStringContains(
        toastMsg,
        "1 contact tagged \"" + tagName + "\"",
        "Verify toast message '" + "1 contact tagged \"" + tagName + "\"'");
  }
  @Test(
      description =
          "Delete multiple tasks (3) by select and toolbar delete : Verify Toast message through GUI",
      groups = {"functional"})
  public void DeleteTaskToastMsg_05() throws HarnessException {

    FolderItem taskFolder = FolderItem.importFromSOAP(app.zGetActiveAccount(), SystemFolder.Tasks);

    // Create the message data to be sent
    String subject1 = "task" + ZimbraSeleniumProperties.getUniqueString();
    String subject2 = "task" + ZimbraSeleniumProperties.getUniqueString();
    String subject3 = "task" + ZimbraSeleniumProperties.getUniqueString();

    app.zGetActiveAccount()
        .soapSend(
            "<CreateTaskRequest xmlns='urn:zimbraMail'>"
                + "<m >"
                + "<inv>"
                + "<comp name='"
                + subject1
                + "'>"
                + "<or a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</comp>"
                + "</inv>"
                + "<su>"
                + subject1
                + "</su>"
                + "<mp ct='text/plain'>"
                + "<content>content"
                + ZimbraSeleniumProperties.getUniqueString()
                + "</content>"
                + "</mp>"
                + "</m>"
                + "</CreateTaskRequest>");

    app.zGetActiveAccount()
        .soapSend(
            "<CreateTaskRequest xmlns='urn:zimbraMail'>"
                + "<m >"
                + "<inv>"
                + "<comp name='"
                + subject2
                + "'>"
                + "<or a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</comp>"
                + "</inv>"
                + "<su>"
                + subject2
                + "</su>"
                + "<mp ct='text/plain'>"
                + "<content>content"
                + ZimbraSeleniumProperties.getUniqueString()
                + "</content>"
                + "</mp>"
                + "</m>"
                + "</CreateTaskRequest>");

    app.zGetActiveAccount()
        .soapSend(
            "<CreateTaskRequest xmlns='urn:zimbraMail'>"
                + "<m >"
                + "<inv>"
                + "<comp name='"
                + subject3
                + "'>"
                + "<or a='"
                + app.zGetActiveAccount().EmailAddress
                + "'/>"
                + "</comp>"
                + "</inv>"
                + "<su>"
                + subject3
                + "</su>"
                + "<mp ct='text/plain'>"
                + "<content>content"
                + ZimbraSeleniumProperties.getUniqueString()
                + "</content>"
                + "</mp>"
                + "</m>"
                + "</CreateTaskRequest>");

    GeneralUtility.syncDesktopToZcsWithSoap(app.zGetActiveAccount());

    // Import each message into MailItem objects
    TaskItem task1 = TaskItem.importFromSOAP(app.zGetActiveAccount(), subject1);
    ZAssert.assertNotNull(task1, "Verify the task is created");

    TaskItem task2 = TaskItem.importFromSOAP(app.zGetActiveAccount(), subject2);
    ZAssert.assertNotNull(task2, "Verify the task is created");

    TaskItem task3 = TaskItem.importFromSOAP(app.zGetActiveAccount(), subject3);
    ZAssert.assertNotNull(task3, "Verify the task is created");

    // Refresh the tasks view
    app.zPageTasks.zToolbarPressButton(Button.B_REFRESH);
    app.zTreeTasks.zTreeItem(Action.A_LEFTCLICK, taskFolder);

    // Select the items
    app.zPageTasks.zListItem(Action.A_MAIL_CHECKBOX, subject1);
    app.zPageTasks.zListItem(Action.A_MAIL_CHECKBOX, subject2);
    app.zPageTasks.zListItem(Action.A_MAIL_CHECKBOX, subject3);

    // Click toolbar delete button
    app.zPageTasks.zToolbarPressButton(Button.B_DELETE);

    // Verifying the toaster message
    Toaster toast = app.zPageMain.zGetToaster();
    String toastMsg = toast.zGetToastMessage();
    ZAssert.assertStringContains(
        toastMsg, "3 tasks moved to Trash", "Verify toast message: N Tasks Moved to Trash");
  }