<commit_before>describe DialogFieldTextBox do
  describe "#initial_values" do
    let(:dialog_field) { described_class.new }

    it "returns a blank string" do
      expect(dialog_field.initial_values).to eq("")
    end
  end

  context "dialog field text box without options hash" do
    before do
      @df = FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field')
    end

    it "#protected?" do
      expect(@df).not_to be_protected
    end

    it "#protected=" do
      @df.protected = true
      expect(@df).to be_protected
    end

    describe "#initialize_with_values" do
      it "decrypts protected automate dialog values" do
        password = "<PASSWORD>"
        @df.protected = true
        @df.initialize_with_values(@df.automate_key_name => MiqPassword.encrypt(password))
        expect(@df.value).to eq(password)
      end
    end
  end

  context "dialog field text box without protected field" do
    before do
      @df = FactoryGirl.build(
        :dialog_field_text_box,
        :label   => 'test field',
        :name    => 'test field',
        :options => {:protected => false}
      )
    end

    it "#protected?" do
      expect(@df).not_to be_protected
    end

    it "#automate_key_name" do
      expect(@df.automate_key_name).to eq("dialog_test field")
    end
  end

  context "dialog field text box with protected field" do
    before do
      @df = FactoryGirl.build(
        :dialog_field_text_box,
        :label   => 'test field',
        :name    => 'test field',
        :options => {:protected => true}
      )
    end

    it "#protected?" do
      expect(@df).to be_protected
    end

    it "#automate_output_value" do
      @df.value = "test string"

      expect(@df.automate_output_value).to be_encrypted("test string")
    end

    it "#protected? with reset" do
      @df.value = "test string"

      @df.options[:protected] = false
      expect(@df).not_to be_protected
      expect(@df.automate_output_value).to eq("test string")
    end

    it "#automate_key_name" do
      expect(@df.automate_key_name).to eq("password::dialog_test field")
    end
  end

  context "validation" do
    let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') }

    describe "#validate_field_data" do
      let(:dt) { double('DialogTab', :label => 'tab') }
      let(:dg) { double('DialogGroup', :label => 'group') }

      context "when validation rule is present" do
        before do
          df.validator_type = 'regex'
          df.validator_rule = '[aA]bc'
          df.required = true<commit_msg>change in dialog_field_text_box_spec.rb, change variables to let<commit_after>describe DialogFieldTextBox do
  describe "#initial_values" do
    let(:dialog_field) { described_class.new }

    it "returns a blank string" do
      expect(dialog_field.initial_values).to eq("")
    end
  end

  context "dialog field text box without options hash" do
    let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') }
	  
    it "#protected?" do
      expect(df).not_to be_protected
    end

    it "#protected=" do
      df.protected = true
      expect(df).to be_protected
    end

    describe "#initialize_with_values" do
      it "decrypts protected automate dialog values" do
        password = "<PASSWORD>"
        df.protected = true
        df.initialize_with_values(df.automate_key_name => MiqPassword.encrypt(password))
        expect(df.value).to eq(password)
      end
    end
  end

  context "dialog field text box without protected field" do
    let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field', :options => {:protected => false}) }

    it "#protected?" do
      expect(df).not_to be_protected
    end

    it "#automate_key_name" do
      expect(df.automate_key_name).to eq("dialog_test field")
    end
  end

  context "dialog field text box with protected field" do
    let(:df) { FactoryGirl.build(:dialog_field_text_box, :label   => 'test field', :name    => 'test field', :options => {:protected => true}) }

    it "#protected?" do
      expect(df).to be_protected
    end

    it "#automate_output_value" do
      df.value = "test string"

      expect(df.automate_output_value).to be_encrypted("test string")
    end

    it "#protected? with reset" do
      df.value = "test string"

      df.options[:protected] = false
      expect(df).not_to be_protected
      expect(df.automate_output_value).to eq("test string")
    end

    it "#automate_key_name" do
      expect(df.automate_key_name).to eq("password::dialog_test field")
    end
  end

  context "validation" do
    let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') }

    describe "#validate_field_data" do
      let(:dt) { double('DialogTab', :label => 'tab') }
      let(:dg) { double('DialogGroup', :label => 'group') }

      context "when validation rule is present" do
        before do
          df.validator_type = 'regex'
          df.validator_rule = '[aA]bc'
          df.required = true
{'fraction_non_alphanumeric': 0.11821893836282325, 'fraction_numerical': 0.0, 'mean_word_length': 2.8618618618618616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '239784', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1549, 'n_words': 418}