<commit_before>require 'rails_helper'

describe 'creating a group_template', type: :feature do
  context "successfully" do
    before do
      @first_post = Post.create
      visit bp_custom_fields.group_templates_path
      expect(page).to have_content "Custom Field Groups"
      click_link "New Group"
      expect(page).to have_content "Create a New Custom Field Group"
    end
    
    it "without fields" do
      within('form.new_group_template') do
        fill_in 'group_template_name', with: "Main Content"
        expect(page).to have_content "Choose a Resource/Model"
        select 'Post', from: 'group_template_appearances_attributes_0_resource'
        click_button "Create Group"
      end

      within("form.edit_group_template") do
        expect(page).to have_field("group_template_appearances_attributes_0_resource", with: "Post")
      end
    end
  
    it "with multiple Appearances but without fields", js: true do 
      within('form.new_group_template') do
        fill_in 'group_template_name', with: "Main Content"
        expect(page).to have_content "Choose a Resource/Model"
        
        select 'Post', from: 'group_template_appearances_attributes_0_resource'
        click_link "Add Appearance"
        expect(page).to have_content "Choose a Resource/Model"
        last_select = all('.appearance-fields select').last
        select "Post", from: last_select[:name]
        last_text_input = all('.appearance-fields input[type="text"]').last
        fill_in last_text_input[:name], with: @first_post.id
        click_button "Create Group"
      end

      within("form.edit_group_template") do
        expect(page).to have_field("group_template_appearances_attributes_0_resource", with: "Post")
        expect(page).to have_field("group_template_appearances_attributes_1_resource", with: "Post")
        expect(page).to have_field("group_template_appearances_attributes_1_resource_id", with: "1")
      end
    end

    it "with Appearances and custom fields", js: true do
      within('form.new_group_template') do
        fill_in 'group_template_name', with: "Main Content"
        expect(page).to have_content "Choose a Resource/Model"
        

        select 'Post', from: 'group_template_appearances_attributes_0_resource'
        click_link "Add Appearance"
        expect(page).to have_content "Choose a Resource/Model"
        last_select = all('.appearance-fields select').last
        select "Post", from: last_select[:name]
        last_text_input = all('.appearance-fields input[type="text"]').last
        fill_in last_text_input[:name], with: @first_post.id
        
        select 'String', from: "group_template_field_templates_attributes_0_field_type"
        fill_in "group_template_field_templates_attributes_0_name", with: "Title"
        fill_in "group_template_field_templates_attributes_0_label", with: "Title"
        
        click_link "Add Field"
        
        expect(page).to have_content "Field Type: "
        last_field_type_select = all('.field-template-select-field-type').last
        last_text_input = all('.field_template-fields .field_template-name').last  <commit_msg>feature specs back to green<commit_after>require 'rails_helper'

describe 'creating a group_template', type: :feature do
  context "successfully" do
    before do
      @first_post = Post.create
      visit bp_custom_fields.group_templates_path
      expect(page).to have_content "Custom Field Groups"
      click_link "New Group"
      expect(page).to have_content "Create a New Custom Field Group"
    end
    
    it "without fields" do
      within('form.new_group_template') do
        fill_in 'group_template_name', with: "Main Content"
        expect(page).to have_content "Choose a Resource/Model"
        select 'Post', from: 'group_template_appearances_attributes_0_resource'
        click_button "Create Group"
      end

      within("form.edit_group_template") do
        expect(page).to have_field("group_template_appearances_attributes_0_resource", with: "Post")
      end
    end
  
    it "with multiple Appearances but without fields", js: true do 
      within('form.new_group_template') do
        fill_in 'group_template_name', with: "Main Content"
        expect(page).to have_content "Choose a Resource/Model"
        
        select 'Post', from: 'group_template_appearances_attributes_0_resource'
        click_link "Add Appearance"
        expect(page).to have_content "Choose a Resource/Model"
        last_select = all('.appearance-fields .resource-select select').last
        select "Post", from: last_select[:name]
        last_text_input = all('.appearance-fields input[type="text"]').last
        fill_in last_text_input[:name], with: @first_post.id
        click_button "Create Group"
      end

      within("form.edit_group_template") do
        expect(page).to have_field("group_template_appearances_attributes_0_resource", with: "Post")
        expect(page).to have_field("group_template_appearances_attributes_1_resource", with: "Post")
        expect(page).to have_field("group_template_appearances_attributes_1_resource_id", with: "1")
      end
    end

    it "with Appearances and custom fields", js: true do
      within('form.new_group_template') do
        fill_in 'group_template_name', with: "Main Content"
        expect(page).to have_content "Choose a Resource/Model"
        

        select 'Post', from: 'group_template_appearances_attributes_0_resource'
        click_link "Add Appearance"
        expect(page).to have_content "Choose a Resource/Model"
        last_select = all('.appearance-fields .resource-select select').last
        select "Post", from: last_select[:name]
        last_text_input = all('.appearance-fields input[type="text"]').last
        fill_in last_text_input[:name], with: @first_post.id
        
        select 'String', from: "group_template_field_templates_attributes_0_field_type"
        fill_in "group_template_field_templates_attributes_0_name", with: "Title"
        fill_in "group_template_field_templates_attributes_0_label", with: "Title"
        
        click_link "Add Field"
        
        expect(page).to have_content "Field Type: "
        last_field_type_select = all('.field-template-select-field-type').last
        last_text_input = all('.field_template-fields .field_template-name').last  
{'fraction_non_alphanumeric': 0.0946073793755913, 'fraction_numerical': 0.003468937243771681, 'mean_word_length': 3.438768369489153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3859868', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1826, 'n_words': 418}