import { expect } from "chai"
import CreatePerson from "../pages/createNewPerson.page"
import CreateTask from "../pages/createNewTask.page"
import CreateReport from "../pages/createReport.page"

const inValidInput = "-10"
const validInput = "10"
const TESTED_BUTTON_NAME = "train"

describe("When working with custom fields for different anet objects", () => {
  describe("For report's custom fields", () => {
    it("Should open a create new report page", () => {
      CreateReport.openAsAdminUser()
      CreateReport.form.waitForExist()
      CreateReport.form.waitForDisplayed()
    })

    it("Should toggle the correct invisible fields", () => {
      const button = CreateReport.getEngagementTypesButtonByName(
        TESTED_BUTTON_NAME
      )
      button.waitForExist()
      button.waitForDisplayed()
      button.click()
      CreateReport.fieldsToggledVisibilityByTrainButton.forEach(
        nowVisisbleField => {
          nowVisisbleField.waitForExist()
          nowVisisbleField.waitForDisplayed()
        }
      )

      CreateReport.fieldsNotToggledVisibilityByTrainButton.forEach(
        stillInvisField => {
          expect(stillInvisField.isExisting()).to.equal(false)
        }
      )
    })

    it("Should persist previous valid data when toggling field's visibility", () => {
      CreateReport.numberTrainedField.setValue(validInput)
      const button = CreateReport.getEngagementTypesButtonByName(
        TESTED_BUTTON_NAME
      )
      button.click()
      CreateReport.numberTrainedFormGroup.waitForExist({ reverse: true })

      button.click()
      CreateReport.numberTrainedFormGroup.waitForExist()

      expect(CreateReport.numberTrainedField.getValue()).to.equal(validInput)
    })

    it("Should not persist previous invalid data when toggling field's visibility", () => {
      CreateReport.numberTrainedField.setValue(inValidInput)
      CreateReport.numberTrainedHelpText.waitForExist()
      // Actually see the validation warning
      expect(CreateReport.numberTrainedHelpText.getText()).to.equal(
        "Number trained must be greater than or equal to 1"
      )
      const button = CreateReport.getEngagementTypesButtonByName(
        TESTED_BUTTON_NAME
      )
      button.click()
      CreateReport.numberTrainedFormGroup.waitForExist({ reverse: true })

      button.click()
      CreateReport.numberTrainedFormGroup.waitForExist()

      expect(CreateReport.numberTrainedField.getValue()).not.be.equal(
        inValidInput
      )
      expect(CreateReport.numberTrainedField.getValue()).not.be.equal("")
    })
  })

  describe("For person's custom fields", () => {
    it("Should open create new person page", () => {
      CreatePerson.openAsAdminUser()
      CreatePerson.form.waitForExist()
      CreatePerson.form.waitForDisplayed()
    })
  })

  describe("For task's custom fields", () => {
    it("Should open create new task page", () => {
      CreateTask.openAsAdminUser()
      CreateTask.form.waitForExist()
      CreateTask.form.waitForDisplayed()
    })
  })
})

@@ -2551,23 +2551,946 @@
 ()).
-not.be.equal(%22%22
+to.be.equal(%22%22)%0A    %7D)%0A%0A    it(%22Should validate visible field%22, () =%3E %7B%0A      CreateReport.numberTrainedField.setValue(inValidInput)%0A      CreateReport.numberTrainedHelpText.waitForExist()%0A      CreateReport.submitForm()%0A      CreateReport.waitForAlertToLoad()%0A%0A      expect(CreateReport.alert.getText()).to.include(%0A        %22Number trained must be greater than or equal to 1%22%0A      )%0A    %7D)%0A%0A    it(%22Should not validate invisible field%22, () =%3E %7B%0A      CreateReport.editButton.click()%0A      CreateReport.form.waitForExist()%0A      CreateReport.form.waitForDisplayed()%0A%0A      const button = CreateReport.getEngagementTypesButtonByName(%0A        TESTED_BUTTON_NAME%0A      )%0A      // make the trained number field invisible%0A      button.click()%0A%0A      CreateReport.submitForm()%0A      CreateReport.waitForAlertToLoad()%0A%0A      expect(CreateReport.alert.getText()).to.not.include(%0A        %22Number trained must be greater than or equal to 1%22%0A      
 )%0A  

Add invisible/visible field validation test case