Feature: Leave a feedback

    Background:
        Given visit "Home" page
        # clear input fields persistence mechanism (just speeds up the test)
        Given clear browser storages
        When press "Feedback" button at "Page content"
        Then modal of "Some feedback form example" dialog opened


    # Path of success

    Scenario: Fulfill feedback form for user support

        When enter "John Doe" in "Your name" input at "Feedback form"
        * enter "test@example.com" in "Email" input at "Feedback form"
        * choose "User support" in "Section" radio group at "Feedback form"
        * set "Consulting on product" in "Required types of support" checkbox group at "Feedback form"
        * enter "test" in "Message" textarea at "Feedback form"
        Then button "Send" at "Feedback form" is enabled
        When press "Send" button at "Feedback form"
        Then wait for "0.5" seconds
        * modal of "Some feedback form example" dialog closed
        * modal of "Data submitted from the form" dialog opened
        # technical field names are used
        * jsonView field "user_name" contains "John Doe"
        * jsonView field "email" contains "test@example.com"
        * jsonView field "section" contains "users"
        * jsonView field "support_type" contains row "0" => "product"
        * jsonView field "message" contains "test"
        * see "recaptcha" at "jsonView"



    # Validations testing

    Scenario: Feedback form validations

        # prepare state of success
        Given enter "John Doe" in "Your name" input at "Feedback form"
        * enter "test@example.com" in "Email" input at "Feedback form"
        * choose "Partnership" in "Section" radio group at "Feedback form"
        * enter "test" in "Message" textarea at "Feedback form"
        Then button "Send" at "Feedback form" is enabled

        # do not see any error message
        Then not see "Required" at "Error message"
        * not see "Must be a valid email address" at "Error message"
        * not see "Please fill all necessary form fields" at "Error message"

        # Your name
        When enter "" in "Your name" input at "Feedback form"
        Then see "Required" at "Error message"
        * button "Send" at "Feedback form" is disabled
        When enter "Jane Doe" in "Your name" input at "Feedback form"
        Then not see "Required" at "Error message"
        * button "Send" at "Feedback form" is enabled

        # Email
        When enter "" in "Email" input at "Feedback form"
        Then see "Required" at "Error message"
        * button "Send" at "Feedback form" is disabled
        When enter "test" in "Email" input at "Feedback form"
        Then see "Must be a valid email address" at "Error message"
        * button "Send" at "Feedback form" is disabled
        When enter "test@example.com" in "Email" input at "Feedback form"
        Then not see "Must be a valid email address" at "Error message"
        * button "Send" at "Feedback form" is enabled

        # Section (can not be unselected)
        * not see "Required types of support" at "Feedback form"
        When choose "User support" in "Section" radio group at "Feedback form"
        Then see "Required types of support" at "Feedback form"
        * not see "Required" at "Error message"
        * button "Send" at "Feedback form" is disabled

        # Required types of support (visible and required only if Section is User support)
        When set "Consulting on product" in "Required types of support" checkbox group at "Feedback form"
        Then not see "Required" at "Error message"
        * button "Send" at "Feedback form" is enabled

        When unset "Consulting on product" in "Required types of support" checkbox group at "Feedback form"
        Then see "Required" at "Error message"
        * button "Send" at "Feedback form" is disabled

        When set "Technical support" in "Required types of support" checkbox group at "Feedback form"
        Then not see "Required" at "Error message"
        Then button "Send" at "Feedback form" is enabled

        When unset "Technical support" in "Required types of support" checkbox group at "Feedback form"
        Then see "Required" at "Error message"
        * button "Send" at "Feedback form" is disabled

        When set "Legal support" in "Required types of support" checkbox group at "Feedback form"
        Then not see "Required" at "Error message"
        * button "Send" at "Feedback form" is enabled

        When set "Technical support" in "Required types of support" checkbox group at "Feedback form"
        Then not see "Required" at "Error message"
        Then button "Send" at "Feedback form" is enabled

        * set "Consulting on product" in "Required types of support" checkbox group at "Feedback form"
        Then not see "Required" at "Error message"
        Then button "Send" at "Feedback form" is enabled

        When unset "Technical support" in "Required types of support" checkbox group at "Feedback form"
        Then not see "Required" at "Error message"
        * button "Send" at "Feedback form" is enabled

        # Message
        When enter "" in "Message" input at "Feedback form"
        Then see "Required" at "Error message"
        * button "Send" at "Feedback form" is disabled
        When enter "The test message" in "Message" input at "Feedback form"
        Then not see "Required" at "Error message"
        * button "Send" at "Feedback form" is enabled

        # reCaptcha badge replacement warning
        * see "This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply." at "Feedback form"
