<commit_before># frozen_string_literal: true

require 'system_helper'

describe 'Shops', js: true do
  include AuthenticationHelper
  include UIComponentHelper
  include WebHelper

  let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }
  let!(:profile) { create(:distributor_enterprise, sells: 'none') }
  let!(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let!(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let!(:order_cycle) {
    create(:simple_order_cycle, distributors: [distributor],
                                coordinator: create(:distributor_enterprise))
  }
  let!(:producer) { create(:supplier_enterprise) }
  let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) }

  before do
    producer.set_producer_property 'Organic', 'NASAA 12345'
  end

  it "searches by URL" do
    visit shops_path(anchor: "/?query=xyzzy")
    expect(page).to have_content "Sorry, no results found for xyzzy"
  end

  describe "listing shops" do
    before do
      visit shops_path
    end

    it "shows hubs" do
      expect(page).to have_content distributor.name
      expand_active_table_node distributor.name
      expect(page).to have_content "OUR PRODUCERS"
    end

    it "does not show invisible hubs" do
      expect(page).not_to have_content invisible_distributor.name
    end

    it "does not show hubs that are not in an order cycle" do
      expect(page).to have_no_selector 'hub.inactive'
      expect(page).to have_no_selector 'hub',   text: d2.name
    end

    it "does not show profiles" do
      expect(page).not_to have_content profile.name
    end
<commit_msg>Splits tests into existing/non-existing shops<commit_after># frozen_string_literal: true

require 'system_helper'

describe 'Shops', js: true do
  include AuthenticationHelper
  include UIComponentHelper
  include WebHelper

  let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }
  let!(:profile) { create(:distributor_enterprise, sells: 'none') }
  let!(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let!(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) }
  let!(:order_cycle) {
    create(:simple_order_cycle, distributors: [distributor],
                                coordinator: create(:distributor_enterprise))
  }
  let!(:producer) { create(:supplier_enterprise) }
  let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) }

  before do
    producer.set_producer_property 'Organic', 'NASAA 12345'
  end

  context "searching enterprises" do
    context "which exist" do
      it "by URL" do
        visit shops_path(anchor: "/?query=Enterprise")
        expect(page).to have_content "Did you mean? #{distributor.name}"
      end

      it "by typing in the search field" do
        visit shops_path
        find('input').set("Enterprise")
        expect(current_url).to have_content("/shops#/?query=Enterprise")
        expect(page).to have_content "Did you mean? #{distributor.name}"
      end
    end

    context "which do not exist" do
      it "by URL" do
        pending("#9649")
        visit shops_path(anchor: "/?query=xyzzy")
        expect(page).not_to have_content distributor.name
        expect(page).to have_content "Sorry, no results found for xyzzy. Try another search?"
      end

      it "by typing in the search field" do
        pending("#5467")
        visit shops_path
        find('input').set("xyzzy")
        expect(current_url).to have_content("/shops#/?query=xyzzy")
        expect(page).not_to have_content distributor.name
        expect(page).to have_content "Sorry, no results found for xyzzy. Try another search?"
      end
    end
  end

  describe "listing shops" do
    before do
      visit shops_path
    end

    it "shows hubs" do
      expect(page).to have_content distributor.name
      expand_active_table_node distributor.name
      expect(page).to have_content "OUR PRODUCERS"
    end

    it "does not show invisible hubs" do
      expect(page).not_to have_content invisible_distributor.name
    end

    it "does not show hubs that are not in an order cycle" do
      expect(page).to have_no_selector 'hub.inactive'
      expect(page).to have_no_selector 'hub',   text: d2.name
    end

    it "does not show profiles" do
      expect(page).not_to have_content profile.name
    end

{'fraction_non_alphanumeric': 0.09863724853990916, 'fraction_numerical': 0.005191434133679429, 'mean_word_length': 3.5964214711729623, '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': '6520866', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1396, 'n_words': 370}