<commit_before>require "spec_helper"

describe "Explore meetings", type: :feature do
  include_context "feature"
  let(:manifest_name) { "meetings" }

  let(:meetings_count) { 5 }
  let!(:meetings) do
    create_list(:meeting, meetings_count, feature: feature)
  end

  before do
    visit_feature
  end

  context "index" do
    it "shows all meetings for the given process" do
      expect(page).to have_selector("article.card", count: meetings_count)

      meetings.each do |meeting|
        expect(page).to have_content(translated(meeting.title))
      end
    end

    context "filtering" do
      it "allows searching by text" do
        within ".filters" do
          fill_in :filter_search_text, with: translated(meetings.first.title)
        end

        expect(page).to have_css(".card--meeting", count: 1)
        expect(page).to have_content(translated(meetings.first.title))
      end

      it "allows filtering by date" do
        past_meeting = create(:meeting, feature: feature, start_time: 1.day.ago)
        visit_feature

        within ".filters" do
          choose "Past"
        end

        expect(page).to have_css(".card--meeting", count: 1)
        expect(page).to have_content(translated(past_meeting.title))

        within ".filters" do
          choose "Upcoming"
        end

        expect(page).to have_css(".card--meeting", count: 5)
      end

      it "allows fitlering by scope" do
        scope = create(:scope, organization: organization)
        meeting = meetings.first
        meeting.scope = scope
        meeting.save

        visit_feature

        within ".filters" do
          check scope.name
        end

        expect(page).to have_css(".card--meeting", count: 1)
      end
    end
  end

  context "show" do
    let(:meetings_count) { 1 }
    let(:meeting) { meetings.first }

    before do
      meeting.update_attributes(
        start_time: DateTime.new(Time.current.year + 1, 12, 13, 14, 15),
        end_time: DateTime.new(Time.current.year + 1, 12, 13, 16, 17)
      )
      click_link translated(meeting.title)
    end

    it "shows all meeting info" do
      expect(page).to have_i18n_content(meeting.title)
      expect(page).to have_i18n_content(meeting.description)
      expect(page).to have_i18n_content(meeting.location)
      expect(page).to have_i18n_content(meeting.location_hints)
      expect(page).to have_content(meeting.address)

      within ".section.view-side" do
        expect(page).to have_content(13)
        expect(page).to have_content(/December/i)
        expect(page).to have_content("14:15 - 16:17")
      end
    end

    context "without category or scope" do
      it "does not show any tag" do
        expect(page).not_to have_selector("ul.tags.tags--meeting")
      end
    end

    context "with a category" do
      let(:meeting) do
        meeting = meetings.first
        meeting.category = create(:category, participatory_process: participatory_process)
        meeting.save
        meeting
      end<commit_msg>Fix meeting specs<commit_after>require "spec_helper"

describe "Explore meetings", type: :feature do
  include_context "feature"
  let(:manifest_name) { "meetings" }

  let(:meetings_count) { 5 }
  let!(:meetings) do
    create_list(:meeting, meetings_count, feature: feature)
  end

  before do
    visit_feature
  end

  context "index" do
    it "shows all meetings for the given process" do
      expect(page).to have_selector("article.card", count: meetings_count)

      meetings.each do |meeting|
        expect(page).to have_content(translated(meeting.title))
      end
    end

    context "filtering" do
      it "allows searching by text" do
        within ".filters" do
          fill_in :filter_search_text, with: translated(meetings.first.title)
        end

        expect(page).to have_css(".card--meeting", count: 1)
        expect(page).to have_content(translated(meetings.first.title))
      end

      it "allows filtering by date" do
        past_meeting = create(:meeting, feature: feature, start_time: 1.day.ago)
        visit_feature

        within ".filters" do
          choose "Past"
        end

        expect(page).to have_css(".card--meeting", count: 1)
        expect(page).to have_content(translated(past_meeting.title))

        within ".filters" do
          choose "Upcoming"
        end

        expect(page).to have_css(".card--meeting", count: 5)
      end

      it "allows fitlering by scope" do
        scope = create(:scope, organization: organization)
        meeting = meetings.first
        meeting.scope = scope
        meeting.save

        visit_feature

        within ".filters" do
          check scope.name
        end

        expect(page).to have_css(".card--meeting", count: 1)
      end
    end
  end

  context "show" do
    let(:meetings_count) { 1 }
    let(:meeting) { meetings.first }
    let(:date) { 10.days.from_now }

    before do
      meeting.update_attributes(
        start_time: date.beginning_of_day,
        end_time: date.end_of_day
      )

      visit decidim_meetings.meeting_path(participatory_process_id: participatory_process.id, feature_id: feature.id, id: meeting.id)
    end

    it "shows all meeting info" do
      expect(page).to have_i18n_content(meeting.title)
      expect(page).to have_i18n_content(meeting.description)
      expect(page).to have_i18n_content(meeting.location)
      expect(page).to have_i18n_content(meeting.location_hints)
      expect(page).to have_content(meeting.address)

      within ".section.view-side" do
        expect(page).to have_content(date.day)
        expect(page).to have_content("00:00 - 23:59")
      end
    end

    context "without category or scope" do
      it "does not show any tag" do
        expect(page).not_to have_selector("ul.tags.tags--meeting")
      end
    end

    context "with a category" do
      let(:meeting) do
        meeting = meetings.first
        meeting.category = create(:category, participatory_process: participatory_process)
        meeting.save
        meeting
      end
{'fraction_non_alphanumeric': 0.10036375661375661, 'fraction_numerical': 0.011243386243386243, 'mean_word_length': 2.5624263839811543, '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': '5996761', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1814, 'n_words': 446}