<commit_before>require "spec_helper"

feature "Managing enterprise images" do
  include AuthenticationWorkflow
  include WebHelper

  context "as an Enterprise user", js: true do
    let(:enterprise_user) { create_enterprise_user(enterprise_limit: 1) }
    let(:distributor) { create(:distributor_enterprise, name: "<NAME>") }

    before do
      enterprise_user.enterprise_roles.build(enterprise: distributor).save!

      quick_login_as enterprise_user
      visit edit_admin_enterprise_path(distributor)
    end

    describe "images for an enterprise", js: true do
      def go_to_images
        within(".side_menu") do
          click_link "Images"
        end
      end

      before do
        go_to_images
      end

      scenario "editing logo" do
        # Adding image
        attach_file "enterprise[logo]", Rails.root.join("app", "assets", "images", "logo-white.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__logo-field-group" do
          expect_preview_image "logo-white.png"
        end

        # Replacing image
        attach_file "enterprise[logo]", Rails.root.join("app", "assets", "images", "logo-black.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__logo-field-group" do
          expect_preview_image "logo-black.png"
        end

        # Removing image
        within ".page-admin-enterprises-form__logo-field-group" do
          click_on "Remove Image"
          accept_js_alert
        end

        expect(page).to have_content("Logo removed successfully")

        within ".page-admin-enterprises-form__logo-field-group" do
          expect(page).to have_no_selector(".image-field-group__preview-image")
        end
      end

      scenario "editing promo image" do
        # Adding image
        attach_file "enterprise[promo_image]", Rails.root.join("app", "assets", "images", "logo-white.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__promo-image-field-group" do
          expect_preview_image "logo-white.jpg"
        end

        # Replacing image
        attach_file "enterprise[promo_image]", Rails.root.join("app", "assets", "images", "logo-black.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__promo-image-field-group" do
          expect_preview_image "logo-black.jpg"
        end

        # Removing image
        within ".page-admin-enterprises-form__promo-image-field-group" do
          click_on "Remove Image"
          accept_js_alert
        end

        expect(page).to have_content("Promo image removed successfully")

        within ".page-admin-enterprises-form__promo-image-field-group" do
          expect(page).to have_no_selector(".image-field-group__preview-image")
        end
      end
    end
  end

  def expect_preview_image(file_name)
    expect(page).to have_selector(".image-field-group__preview-image[src*='#{file_name}']")
  end
end<commit_msg>Refactor checking no preview image in specs<commit_after>require "spec_helper"

feature "Managing enterprise images" do
  include AuthenticationWorkflow
  include WebHelper

  context "as an Enterprise user", js: true do
    let(:enterprise_user) { create_enterprise_user(enterprise_limit: 1) }
    let(:distributor) { create(:distributor_enterprise, name: "First Distributor") }

    before do
      enterprise_user.enterprise_roles.build(enterprise: distributor).save!

      quick_login_as enterprise_user
      visit edit_admin_enterprise_path(distributor)
    end

    describe "images for an enterprise", js: true do
      def go_to_images
        within(".side_menu") do
          click_link "Images"
        end
      end

      before do
        go_to_images
      end

      scenario "editing logo" do
        # Adding image
        attach_file "enterprise[logo]", Rails.root.join("app", "assets", "images", "logo-white.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__logo-field-group" do
          expect_preview_image "logo-white.png"
        end

        # Replacing image
        attach_file "enterprise[logo]", Rails.root.join("app", "assets", "images", "logo-black.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__logo-field-group" do
          expect_preview_image "logo-black.png"
        end

        # Removing image
        within ".page-admin-enterprises-form__logo-field-group" do
          click_on "Remove Image"
          accept_js_alert
        end

        expect(page).to have_content("Logo removed successfully")

        within ".page-admin-enterprises-form__logo-field-group" do
          expect_no_preview_image
        end
      end

      scenario "editing promo image" do
        # Adding image
        attach_file "enterprise[promo_image]", Rails.root.join("app", "assets", "images", "logo-white.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__promo-image-field-group" do
          expect_preview_image "logo-white.jpg"
        end

        # Replacing image
        attach_file "enterprise[promo_image]", Rails.root.join("app", "assets", "images", "logo-black.png")
        click_button "Update"

        expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")

        go_to_images
        within ".page-admin-enterprises-form__promo-image-field-group" do
          expect_preview_image "logo-black.jpg"
        end

        # Removing image
        within ".page-admin-enterprises-form__promo-image-field-group" do
          click_on "Remove Image"
          accept_js_alert
        end

        expect(page).to have_content("Promo image removed successfully")

        within ".page-admin-enterprises-form__promo-image-field-group" do
          expect_no_preview_image
        end
      end
    end
  end

  def expect_preview_image(file_name)
    expect(page).to have_selector(".image-field-group__preview-image[src*='#{file_name}']")
  end

  def expect_no_preview_image
    expect(page).to have_no_selector(".image-field-group__preview-image")
  end
end
{'fraction_non_alphanumeric': 0.10366028024020589, 'fraction_numerical': 0.00028595939376608524, 'mean_word_length': 2.7790383576445166, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '7549869', 'n_tokens_mistral': 2077, 'n_tokens_neox': 2008, 'n_words': 431}