diff --git a/spec/requests/faqs_spec.rb b/spec/requests/faqs_spec.rb index 3ffd5cf06..4454905b5 100644 --- a/spec/requests/faqs_spec.rb +++ b/spec/requests/faqs_spec.rb @@ -70,6 +70,11 @@ expect(response.body).to include("Unpublished FAQ") end + it "shows the New FAQ admin control" do + get faqs_path + expect(response.body).to include("New FAQ") + end + it "filters by unpublished param" do get faqs_path, params: { published: "false" } # needs to be string param expect(response.body).to include("Unpublished FAQ") @@ -109,6 +114,12 @@ expect(response.body).to include("Published FAQ") expect(response.body).not_to include("Unpublished FAQ") end + + it "hides admin controls" do + get faqs_path + expect(response.body).not_to include("New FAQ") + expect(response.body).not_to include(edit_faq_path(published_faq)) + end end context "as a guest" do @@ -124,6 +135,12 @@ expect(response.body).not_to include("Published FAQ") expect(response.body).not_to include("Unpublished FAQ") end + + it "hides admin controls" do + get faqs_path + expect(response.body).not_to include("New FAQ") + expect(response.body).not_to include(edit_faq_path(public_faq)) + end end end diff --git a/spec/requests/home_spec.rb b/spec/requests/home_spec.rb index 559190844..2030ab82a 100644 --- a/spec/requests/home_spec.rb +++ b/spec/requests/home_spec.rb @@ -20,6 +20,20 @@ end end + describe "GET / (signed in)" do + it "shows the Upcoming Events and Community News sections" do + user = create(:user) + create(:person, user: user) + sign_in user + + get root_path + + expect(response).to have_http_status(:ok) + expect(response.body).to include("Upcoming Events") + expect(response.body).to include("Community News") + end + end + describe "GET /home/* (turbo frame lazy loading)" do %w[workshops resources events community_news stories video_recordings].each do |section| it "#{section} returns 200 for visitors" do diff --git a/spec/requests/login_spec.rb b/spec/requests/login_spec.rb new file mode 100644 index 000000000..6c9a0a834 --- /dev/null +++ b/spec/requests/login_spec.rb @@ -0,0 +1,45 @@ +require "rails_helper" + +RSpec.describe "User login", type: :request do + let(:password) { "MyString" } + let(:generic_error) { "Invalid email or password. Please email us or fill out our Contact Us form for assistance." } + + def log_in(email, password) + post user_session_path, params: { user: { email: email, password: password } } + end + + context "when user is inactive" do + let(:user) { create(:user, password: password, inactive: true) } + + it "does not allow login and shows the generic error" do + log_in(user.email, password) + + expect(response).to redirect_to(new_user_session_path) + follow_redirect! + expect(response.body).to include(generic_error) + end + end + + context "when credentials are wrong" do + let(:user) { create(:user, password: password) } + + it "shows the generic error" do + log_in(user.email, "wrong_password") + + expect(response).to have_http_status(:unprocessable_content) + expect(response.body).to include(generic_error) + end + end + + context "when user is active and unlocked" do + let(:user) { create(:user, password: password) } + + it "logs in successfully" do + log_in(user.email, password) + + expect(response).to redirect_to(root_path) + follow_redirect! + expect(response.body).not_to include(generic_error) + end + end +end diff --git a/spec/requests/organizations_spec.rb b/spec/requests/organizations_spec.rb index 8a7ca16e0..5b2b033cd 100644 --- a/spec/requests/organizations_spec.rb +++ b/spec/requests/organizations_spec.rb @@ -67,6 +67,57 @@ end end + describe "sector displays" do + let!(:organization_with_sectors) do + affiliated_sector_1 = create(:sector, name: "Affiliated Sector 1") + affiliated_sector_2 = create(:sector, name: "Affiliated Sector 2") + person_1 = create(:person) + person_2 = create(:person) + create(:sectorable_item, sector: affiliated_sector_1, sectorable: person_1) + create(:sectorable_item, sector: affiliated_sector_2, sectorable: person_2) + + org = create(:organization, organization_status: organization_status) + create(:sectorable_item, sector: create(:sector, name: "Direct Sector 1"), sectorable: org) + create(:sectorable_item, sector: create(:sector, name: "Direct Sector 2"), sectorable: org) + create(:affiliation, organization: org, person: person_1, position: :default) + create(:affiliation, organization: org, person: person_2, position: :default) + org + end + + it "truncates sectors to the first 3 with a 'more' indicator on the show page" do + get organization_url(organization_with_sectors) + + page = Capybara.string(response.body) + all_sector_names = organization_with_sectors.all_sectors.map(&:name).sort + expect(all_sector_names.length).to be > 3 + all_sector_names.first(3).each { |name| expect(page).to have_content(name) } + expect(page).not_to have_content(all_sector_names[3]) + expect(page).to have_content(/\+?[0-9]+ more|\.\.\./i) + end + + it "lists all sectors with per-sector people counts on the populations served page" do + get populations_served_organization_url(organization_with_sectors) + + page = Capybara.string(response.body) + expect(page).to have_content("Sector Distribution") + expect(page).to have_content(organization_with_sectors.name) + + organization_with_sectors.all_sectors.map(&:name).each do |name| + expect(page).to have_content(name) + end + + people = organization_with_sectors.users.includes(person: :sectors).map(&:person).compact + expected_counts = Hash.new(0) + people.each do |person| + primary_sector = person.sectors.first + expected_counts[primary_sector.name] += 1 if primary_sector + end + expected_counts.each do |_sector_name, count| + expect(page).to have_content("#{count} #{count == 1 ? 'person' : 'people'}") + end + end + end + describe "GET /new" do it "renders a successful response" do get new_organization_url diff --git a/spec/requests/sectors_spec.rb b/spec/requests/sectors_spec.rb index 1b9e96b0e..75e49d581 100644 --- a/spec/requests/sectors_spec.rb +++ b/spec/requests/sectors_spec.rb @@ -27,6 +27,44 @@ get sectors_url expect(response).to be_successful end + + context "filtering" do + let!(:sectors) do + [ + create(:sector, name: "Sector1", published: true), + create(:sector, name: "Sector2", published: true), + create(:sector, name: "Sector3", published: false), + create(:sector, name: "Sector4", published: false) + ] + end + + it "returns all sectors without filters" do + get sectors_url + sectors.each { |sector| expect(response.body).to include(sector.name) } + end + + it "returns only published sectors when published=true" do + get sectors_url, params: { published: "true" } + expect(response.body).to include("Sector1", "Sector2") + expect(response.body).not_to include("Sector3") + expect(response.body).not_to include("Sector4") + end + + it "returns only unpublished sectors when published=false" do + get sectors_url, params: { published: "false" } + expect(response.body).to include("Sector3", "Sector4") + expect(response.body).not_to include("Sector1") + expect(response.body).not_to include("Sector2") + end + + it "filters by name" do + get sectors_url, params: { sector_name: "Sector1" } + expect(response.body).to include("Sector1") + expect(response.body).not_to include("Sector2") + expect(response.body).not_to include("Sector3") + expect(response.body).not_to include("Sector4") + end + end end describe "GET /show" do diff --git a/spec/requests/stories_spec.rb b/spec/requests/stories_spec.rb index 2fbc28c11..263d7c825 100644 --- a/spec/requests/stories_spec.rb +++ b/spec/requests/stories_spec.rb @@ -66,6 +66,23 @@ expect(response.body).not_to include(story_in_other_org.title) end + it "shows the empty-state message when no stories match" do + get stories_url(title: "no-such-story-zzz"), headers: { "Turbo-Frame" => "story_results" } + expect(response.body).to include("No stories found") + end + + it "filters by title and body query together" do + match = Story.create!(base_attributes.merge(title: "Best Story Match", rhino_body: "healing through art", published: true)) + title_only = Story.create!(base_attributes.merge(title: "Best Story Other", rhino_body: "something else", published: true)) + body_only = Story.create!(base_attributes.merge(title: "Unrelated Tale", rhino_body: "healing through art", published: true)) + + get stories_url(title: "Best Story", query: "healing"), headers: { "Turbo-Frame" => "story_results" } + + expect(response.body).to include(match.title) + expect(response.body).not_to include(title_only.title) + expect(response.body).not_to include(body_only.title) + end + describe "external link handling" do let(:turbo_headers) { { "Turbo-Frame" => "story_results" } } diff --git a/spec/requests/story_ideas_spec.rb b/spec/requests/story_ideas_spec.rb index 7ab5bd697..9106dfaa7 100644 --- a/spec/requests/story_ideas_spec.rb +++ b/spec/requests/story_ideas_spec.rb @@ -59,6 +59,19 @@ get story_idea_url(create(:story_idea)) expect(response).to be_successful end + + it "renders the organization and creator as links" do + creator = create(:user) + creator_person = create(:person, user: creator) + org = create(:organization, name: "Community Arts Project") + story_idea = create(:story_idea, created_by: creator, organization: org) + + get story_idea_url(story_idea) + + page = Capybara.string(response.body) + expect(page).to have_link(org.name, href: organization_path(org)) + expect(page).to have_link(creator.name, href: person_path(creator_person)) + end end describe "GET /new" do @@ -228,6 +241,29 @@ get story_idea_url(story_idea) expect(response).to be_successful end + + it "renders the organization as plain text and the creator as a link" do + person = create(:person, user: regular_user) + org = create(:organization, name: "Community Arts Project") + story_idea = create(:story_idea, created_by: regular_user, organization: org) + + get story_idea_url(story_idea) + + page = Capybara.string(response.body) + expect(page).to have_text(org.name) + expect(page).not_to have_link(org.name) + expect(page).to have_link(regular_user.name, href: person_path(person)) + end + + it "renders the creator as plain text when they have no person record" do + story_idea = create(:story_idea, created_by: regular_user) + + get story_idea_url(story_idea) + + page = Capybara.string(response.body) + expect(page).to have_text(regular_user.name) + expect(page).not_to have_link(regular_user.name) + end end end diff --git a/spec/requests/workshop_logs_spec.rb b/spec/requests/workshop_logs_spec.rb index b562cae99..6acd80a8e 100644 --- a/spec/requests/workshop_logs_spec.rb +++ b/spec/requests/workshop_logs_spec.rb @@ -54,6 +54,79 @@ clear_enqueued_jobs end + describe "GET /show" do + it "renders the organization as plain text and the creator as a link (non-admin)" do + person = create(:person, user: user) + create(:affiliation, person: person, organization: organization) + workshop_log = create(:workshop_log, created_by: user, organization: organization, + workshop: workshop, windows_type: windows_type, workshop_held_on: 1.day.ago) + + get workshop_log_path(workshop_log) + + page = Capybara.string(response.body) + expect(page).to have_text(organization.name) + expect(page).not_to have_link(organization.name) + expect(page).to have_link(user.name, href: person_path(person)) + end + + it "renders the creator as plain text when they have no person record" do + workshop_log = create(:workshop_log, created_by: user, organization: organization, + workshop: workshop, windows_type: windows_type, workshop_held_on: 1.day.ago) + + get workshop_log_path(workshop_log) + + page = Capybara.string(response.body) + expect(page).to have_text(user.name) + expect(page).not_to have_link(user.name) + end + + it "shows the external title in the heading and beside the Workshop label when there is no workshop" do + workshop_log = create(:workshop_log, created_by: user, organization: organization, + workshop: nil, windows_type: windows_type, + external_workshop_title: "Community Mural Project", workshop_held_on: 1.day.ago) + + get workshop_log_path(workshop_log) + + page = Capybara.string(response.body) + expect(page).to have_css("h1", text: "Community Mural Project") + workshop_div = page.find("span", text: "Workshop:").ancestor("div", match: :first) + expect(workshop_div).to have_text("Community Mural Project") + end + + it "shows the workshop name in the heading and both the workshop and external title when both are present" do + titled_workshop = create(:workshop, :published, title: "Healing Through Art", windows_type: windows_type) + workshop_log = create(:workshop_log, created_by: user, organization: organization, + workshop: titled_workshop, windows_type: windows_type, + external_workshop_title: "Guest-led Session", workshop_held_on: 1.day.ago) + + get workshop_log_path(workshop_log) + + page = Capybara.string(response.body) + expect(page).to have_css("h1", text: "Healing Through Art") + workshop_div = page.find("span", text: "Workshop:").ancestor("div", match: :first) + expect(workshop_div).to have_text("Healing Through Art") + expect(workshop_div).to have_text("Guest-led Session") + end + + context "as an admin" do + let(:admin) { create(:user, :admin) } + before { sign_in admin } + + it "renders the organization and creator as links" do + person = create(:person, user: user) + create(:affiliation, person: person, organization: organization) + workshop_log = create(:workshop_log, created_by: user, organization: organization, + workshop: workshop, windows_type: windows_type, workshop_held_on: 1.day.ago) + + get workshop_log_path(workshop_log) + + page = Capybara.string(response.body) + expect(page).to have_link(organization.name, href: organization_path(organization)) + expect(page).to have_link(user.name, href: person_path(person)) + end + end + end + describe "GET /index" do it "loads the index page successfully" do get workshop_logs_path diff --git a/spec/requests/workshop_variation_ideas_spec.rb b/spec/requests/workshop_variation_ideas_spec.rb index 2787421b6..1577c0de9 100644 --- a/spec/requests/workshop_variation_ideas_spec.rb +++ b/spec/requests/workshop_variation_ideas_spec.rb @@ -55,6 +55,18 @@ get workshop_variation_idea_path(idea) expect(response).to have_http_status(:ok) end + + it "renders the organization and creator as links" do + creator_person = create(:person, user: regular_user) + org = create(:organization, name: "Community Arts Project") + idea = create(:workshop_variation_idea, valid_attributes.merge(organization_id: org.id)) + + get workshop_variation_idea_path(idea) + + page = Capybara.string(response.body) + expect(page).to have_link(org.name, href: organization_path(org)) + expect(page).to have_link(regular_user.name, href: person_path(creator_person)) + end end describe "GET /new" do @@ -184,6 +196,29 @@ expect(response).to have_http_status(:ok) end + it "renders the organization as plain text and the creator as a link" do + person = create(:person, user: regular_user) + org = create(:organization, name: "Community Arts Project") + idea = create(:workshop_variation_idea, valid_attributes.merge(organization_id: org.id)) + + get workshop_variation_idea_path(idea) + + page = Capybara.string(response.body) + expect(page).to have_text(org.name) + expect(page).not_to have_link(org.name) + expect(page).to have_link(regular_user.name, href: person_path(person)) + end + + it "renders the creator as plain text when they have no person record" do + idea = create(:workshop_variation_idea, valid_attributes) + + get workshop_variation_idea_path(idea) + + page = Capybara.string(response.body) + expect(page).to have_text(regular_user.name) + expect(page).not_to have_link(regular_user.name) + end + it "redirects from another's workshop_variation_idea to root" do idea = create(:workshop_variation_idea, valid_attributes.merge(created_by_id: admin.id)) get workshop_variation_idea_path(idea) diff --git a/spec/system/event_registrations_test.rb b/spec/system/event_registrations_test.rb deleted file mode 100644 index 7bd80da07..000000000 --- a/spec/system/event_registrations_test.rb +++ /dev/null @@ -1,64 +0,0 @@ -require "rails_helper" - -RSpec.describe "Event Registration form", type: :system do - let(:admin) { create(:user, :admin, :with_person) } - let(:person_to_register) { create(:person, first_name: "Jane", last_name: "Smith", email: "jane@example.com") } - let!(:event) { create(:event, :published, title: "Test Workshop", start_date: 2.days.from_now) } - - describe "GET /event_registrations/new" do - context "when admin is logged in" do - before do - sign_in admin - visit new_event_registration_path - end - - it "shows the new event registration form" do - expect(page).to have_content("New event registration") - expect(page).to have_selector("select#event_registration_event_id") - expect(page).to have_selector("select#event_registration_registrant_id") - end - end - end - - describe "GET /event_registrations/:id/edit" do - let!(:event_registration) { create(:event_registration, event: event, registrant: person_to_register) } - - context "when admin is logged in" do - before do - sign_in admin - visit edit_event_registration_path(event_registration) - end - - it "shows the edit event registration form" do - expect(page).to have_content("Edit event registration") - expect(page).to have_selector("select#event_registration_event_id") - expect(page).to have_selector("select#event_registration_registrant_id") - end - end - end - - describe "person search (remote select)", js: true do - let!(:person1) { create(:person, first_name: "Alice", last_name: "Wonder", email: "alice@test.com") } - let!(:person2) { create(:person, first_name: "Bob", last_name: "Builder", email: "bob@test.com") } - - before do - sign_in admin - visit new_event_registration_path - end - - it "selects a person from search results and creates an event registration" do - find(".ts-control").click - fill_in "Registrant", with: "Alice" - - within(".ts-dropdown") do - find(".option", text: "Alice Wonder").click - end - - expect(find(".ts-control")).to have_content("Alice Wonder") - find("#event_registration_event_id option[value='#{event.id}']").select_option - click_button "Submit" - - expect(page).to have_content("Registration created") - end - end -end diff --git a/spec/system/faq_spec.rb b/spec/system/faq_spec.rb deleted file mode 100644 index d3c670c9a..000000000 --- a/spec/system/faq_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require "rails_helper" - -RSpec.describe "FAQ visibility", type: :system do - let!(:published_faq) { create(:faq, :published) } - let!(:unpublished_faq) { create(:faq) } - let!(:public_faq) { create(:faq, :publicly_visible, :published) } - - describe "index page" do - context "as a regular user" do - before do - sign_in create(:user) - visit faqs_path - end - - it "shows only published FAQs" do - expect(page).to have_text(published_faq.question) - expect(page).not_to have_text(unpublished_faq.question) - end - - it "does not show admin controls" do - expect(page).not_to have_link("New FAQ") - end - end - - context "as an admin" do - before do - sign_in create(:user, :admin) - visit faqs_path - end - - it "shows all FAQs" do - expect(page).to have_text(published_faq.question) - expect(page).to have_text(unpublished_faq.question) - end - - it "shows admin controls" do - expect(page).to have_link("New FAQ") - end - end - - context "as a guest" do - before do - visit faqs_path - end - - it "shows only public FAQs" do - expect(page).to have_text(public_faq.question) - expect(page).not_to have_text(published_faq.question) - expect(page).not_to have_text(unpublished_faq.question) - end - - it "does not show admin controls" do - expect(page).not_to have_link("Edit") - end - end - end -end diff --git a/spec/system/login_spec.rb b/spec/system/login_spec.rb deleted file mode 100644 index fe4f1fee0..000000000 --- a/spec/system/login_spec.rb +++ /dev/null @@ -1,80 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "User login", type: :system do - let(:password) { "MyString" } - let(:generic_error) { "Invalid email or password. Please email us or fill out our Contact Us form for assistance." } - - def fill_in_login(email, password) - visit new_user_session_path - fill_in "user_email", with: email - fill_in "user_password", with: password - click_button "Log in" - end - - context "when user is locked" do - let(:user) { create(:user, :locked, password: password) } - - xit "does not allow login and shows locked message" do - fill_in_login(user.email, password) - - expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content("Please email us or fill out our Contact Us form for assistance.") - end - end - - context "when user is inactive" do - let(:user) { create(:user, password: password, inactive: true) } - - it "does not allow login and shows generic error" do - fill_in_login(user.email, password) - - expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content(generic_error) - end - end - - context "when user exceeds maximum failed login attempts" do - let(:user) { create(:user, password: password) } - let(:last_attempt_warning) { "You have one more attempt before your account is locked" } - - xit "warns on the last attempt then locks the account" do # TODO flaky test - 9.times do - fill_in_login(user.email, "wrong_password") - end - - expect(page).to have_content(last_attempt_warning) - - fill_in_login(user.email, "wrong_password") - - fill_in_login(user.email, password) - - expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content("Please email us or fill out our Contact Us form for assistance.") - expect(user.reload.locked_at).to be_present - end - end - - context "when credentials are wrong" do - let(:user) { create(:user, password: password) } - - it "shows generic error" do - fill_in_login(user.email, "wrong_password") - - expect(page).to have_current_path(new_user_session_path) - expect(page).to have_content(generic_error) - end - end - - context "when user is active and unlocked" do - let(:user) { create(:user, password: password) } - - it "allows login successfully" do - fill_in_login(user.email, password) - - expect(page).not_to have_content(generic_error) - expect(page).to have_css("#avatar") - end - end -end diff --git a/spec/system/organization_sectors_spec.rb b/spec/system/organization_sectors_spec.rb deleted file mode 100644 index 8f65c98c5..000000000 --- a/spec/system/organization_sectors_spec.rb +++ /dev/null @@ -1,89 +0,0 @@ -require "rails_helper" - -RSpec.describe "Organization sector displays", type: :system do - let!(:organization) do - direct_sector_1 = create(:sector, name: "Direct Sector 1") - direct_sector_2 = create(:sector, name: "Direct Sector 2") - affiliated_sector_1 = create(:sector, name: "Affiliated Sector 1") - affiliated_sector_2 = create(:sector, name: "Affiliated Sector 2") - - person_1 = create(:person) - person_2 = create(:person) - - create(:sectorable_item, sector: affiliated_sector_1, sectorable: person_1) - create(:sectorable_item, sector: affiliated_sector_2, sectorable: person_2) - - org = create( - :organization, - organization_status: create(:organization_status, name: "Active") - ) - - create(:sectorable_item, sector: direct_sector_1, sectorable: org) - create(:sectorable_item, sector: direct_sector_2, sectorable: org) - - create(:affiliation, organization: org, person: person_1, position: :default) - create(:affiliation, organization: org, person: person_2, position: :default) - - org - end - - let(:user) { create(:user, :admin) } - - before do - sign_in user - end - - context "organization show page" do - it "displays sectors with truncation when there are more than 3" do - visit organization_path(organization) - - expect(page).to have_content(organization.name) - expect(page).to have_content("Sectors") - - all_sector_names = organization.all_sectors.map(&:name).sort - - if all_sector_names.length > 3 - all_sector_names.first(3).each do |sector_name| - expect(page).to have_content(sector_name) - end - - expect(page).not_to have_content(all_sector_names[3]) - - expect(page).to have_content(/\+?[0-9]+ more|\.\.\./i) - else - all_sector_names.each do |sector_name| - expect(page).to have_content(sector_name) - end - end - end - end - - context "population served page" do - it "displays all sectors with correct counts for affiliated sectors only" do - visit populations_served_organization_path(organization) - - expect(page).to have_content("Sector Distribution") - expect(page).to have_content(organization.name) - expect(page).to have_content("Sectors") - - all_sector_names = organization.all_sectors.map(&:name).sort - - all_sector_names.each do |sector_name| - expect(page).to have_content(sector_name) - end - - people = organization.users.includes(person: :sectors).map(&:person).compact - - expected_counts = Hash.new(0) - people.each do |person| - primary_sector = person.sectors.first - expected_counts[primary_sector.name] += 1 if primary_sector - end - - expected_counts.each do |sector_name, count| - expected_text = "#{count} #{count == 1 ? 'person' : 'people'}" - expect(page).to have_content(expected_text) - end - end - end -end diff --git a/spec/system/person_adds_event_to_calendar_test.rb b/spec/system/person_adds_event_to_calendar_test.rb deleted file mode 100644 index b8b9ea064..000000000 --- a/spec/system/person_adds_event_to_calendar_test.rb +++ /dev/null @@ -1,111 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can register for an event" do - describe "Person signs in, views the events and register for the events" do - context "When Person is logged in" do - before do - user = create(:user) - create(:person, user: user) - - @event = create(:event, - title: "Upcoming Workshop", - start_date: 1.day.from_now, - end_date: 2.days.from_now, - registration_close_date: 1.day.from_now, - published: true, - featured: true - ) - create(:event, - title: "Another Event", - start_date: 2.days.from_now, - end_date: 3.days.from_now, - registration_close_date: 1.day.from_now, - published: true, - featured: true, - created_by: user - ) - - sign_in user - visit events_path - - # Register for the event - within("#card_event_#{@event.id}") do - click_button 'Register' - end - end - - describe "Calendar links after registration" do - let(:title_encoded) { ERB::Util.url_encode(@event.title) } - let(:start_time) { @event.start_date.utc.strftime("%Y%m%dT%H%M%SZ") } - let(:end_time) { @event.end_date.utc.strftime("%Y%m%dT%H%M%SZ") } - - before do - visit events_path - end - - it "shows calendar options" do - within("#card_event_#{@event.id}") do - expect(page).to have_link("Google") - apple_link = find('a', text: "Apple") - expect(apple_link[:download]).to end_with(".ics") - expect(page).to have_link("Office 365") - expect(page).to have_link("Yahoo") - expect(page).to have_link("Outlook") - end - end - - it "provides Google Calendar link" do - google_link = find_link("Google") - expect(google_link[:href]).to include("https://calendar.google.com/calendar/render") - expect(google_link[:href]).to include("action=TEMPLATE") - expect(google_link[:href]).to include("text=#{title_encoded}") - expect(google_link[:href]).to include("dates=#{start_time}/#{end_time}") - end - - it "provides Outlook link" do - outlook_link = find_link("Outlook") - expect(outlook_link[:href]).to include("https://outlook.live.com/owa/") - expect(outlook_link[:href]).to include("subject=#{title_encoded}") - expect(outlook_link[:href]).to include("startdt=#{start_time}") - expect(outlook_link[:href]).to include("enddt=#{end_time}") - end - - it "provides Office 365 link" do - office_link = find_link("Office 365") - expect(office_link[:href]).to include("https://outlook.office.com/owa/") - expect(office_link[:href]).to include("subject=#{title_encoded}") - expect(office_link[:href]).to include("startdt=#{start_time}") - expect(office_link[:href]).to include("enddt=#{end_time}") - end - - it "provides Yahoo Calendar link" do - yahoo_link = find_link("Yahoo") - expect(yahoo_link[:href]).to include("https://calendar.yahoo.com/") - expect(yahoo_link[:href]).to include("title=#{title_encoded}") - expect(yahoo_link[:href]).to include("st=#{start_time}") - expect(yahoo_link[:href]).to include("et=#{end_time}") - end - - it "provides Apple Calendar .ics download" do - apple_link = find_link("Apple") - encoded_ical = apple_link[:href].split(',', 2)[1] - ical_content = URI.decode_www_form_component(encoded_ical) - expect(apple_link[:href]).to include("data:text/calendar;charset=utf8,") - expect(apple_link[:href]).to include("SUMMARY:#{@event.title}") - expect(apple_link[:href]).to include("DTSTART:#{start_time}") - expect(apple_link[:href]).to include("DTEND:#{end_time}") - expect(apple_link[:download]).to be_present - end - - it "shows registered status and de-register button" do - within("#card_event_#{@event.id}") do - expect(page).to have_css("span.text-xs.bg-green-100.text-green-700.px-2.py-0\\.5.rounded-full", - text: "Registered") - expect(page).to have_button("De-register") - expect(page).to have_no_button("Register") - end - end - end - end - end -end diff --git a/spec/system/person_bookmarks_workshop_test.rb b/spec/system/person_bookmarks_workshop_test.rb deleted file mode 100644 index 2d8cdbbf7..000000000 --- a/spec/system/person_bookmarks_workshop_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'People can bookmark workshops' do - describe "Person bookmarks a workshop" do - context "when facilitator is logged in" do - before do - user = create(:user) - create(:person, user: user) - adult_window = create(:windows_type, :adult) - @workshop_world = create(:workshop, :published, title: 'The best workshop in the world', windows_type: adult_window) - - sign_in user - visit '/workshops' - end - - it "allows bookmarking a workshop and displays it in bookmarks list" do - expect(page).to have_content('Workshops') - expect(page).to have_content('The best workshop in the world') - # Bookmark the workshop - within("#bookmark_icon_workshop_#{@workshop_world.id}") do - find('button').click - end - - expect(page).to have_content("Workshop added to your bookmarks.") - - # Navigate to bookmarks page - visit personal_bookmarks_path - expect(page).to have_content('My Bookmarks (1)') - expect(page).to have_content('The best workshop in the world') - end - end - end -end diff --git a/spec/system/person_changes_password_test.rb b/spec/system/person_changes_password_test.rb deleted file mode 100644 index b977326f4..000000000 --- a/spec/system/person_changes_password_test.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'People can change their password quickly and easily' do - describe 'Person changes password through reset link' do - context 'when person requests password change' do - before do - @user = create(:user) - create(:person, user: @user) - end - - it 'completes the full password reset flow successfully' do - visit '/users/sign_in' - - expect(page).to have_content('Log in') - expect(page).to have_content('Email') - expect(page).to have_content('Password') - expect(page).to have_link('Forgot your password?') - - click_link('Forgot your password?') - - expect(page).to have_current_path('/users/password/new') - expect(page).to have_content('Forgot your password?') - - fill_in 'user_email', with: @user.email - click_button 'Email me reset password instructions' - - expect(page).to have_content( - 'You will receive an email with instructions on how to reset your password in a few minutes.' - ) - - # Retrieve Reset Link from Email - notification = Notification.find_by( - kind: 'reset_password', - recipient_email: @user.email - ) - - email_body = notification.email_body_text - path_match = email_body.match(%r{/users/password/edit\?reset_password_token=[^\s]+}) - reset_path = path_match[0] - - # Set new password - visit reset_path - - fill_in 'New password', with: 'NewPassword123!' - fill_in 'Confirm new password', with: 'NewPassword123!' - click_button 'Set password' - - expect(page).to have_content('Your password has been set successfully') - expect(page).to have_current_path('/') - - # Test Login with New Password - sign_out @user - - visit '/users/sign_in' - fill_in 'user_email', with: @user.email - fill_in 'user_password', with: 'NewPassword123!' - click_button 'Log in' - - expect(page).to have_content('Signed in successfully') - - # Verify Old Password is Invalid - sign_out @user - - visit '/users/sign_in' - fill_in 'user_email', with: @user.email - fill_in 'user_password', with: 'wrongpassword' - click_button 'Log in' - - expect(page).to have_content('Invalid Email or password.') - end - end - end -end diff --git a/spec/system/person_downloads_resources_test.rb b/spec/system/person_downloads_resources_test.rb deleted file mode 100644 index 8492ae01f..000000000 --- a/spec/system/person_downloads_resources_test.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can download resources", type: :system, js: true do - include DownloadHelpers - - let(:user) { create(:user) } - let(:resource) do - create(:resource, - title: "Test Template", - featured: true, - published: true, - kind: "Template") - end - - before do - Capybara.register_driver :selenium_chrome_headless_download do |app| - browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts| - opts.args << '--headless' - opts.args << '--disable-site-isolation-trials' - end - browser_options.add_preference(:download, prompt_for_download: false, - default_directory: DownloadHelpers::PATH.to_s) - browser_options.add_preference(:browser, set_download_behavior: { behavior: 'allow' }) - - Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) - end - - driven_by :selenium_chrome_headless_download - - create(:person, user: user) - create(:downloadable_asset, owner: resource) - clear_downloads - end - - after do - clear_downloads - end - - describe "when user is logged in" do - before { sign_in user } - - context "from the home page" do - it "downloads the resource" do - visit root_path - - find("a[href='/resources/#{resource.id}/download']").click - - wait_for_download - expect(downloads.length).to eq(1) - expect(download).to match(/.*\.pdf/) - end - end - - context "from the resources index page" do - it "downloads the resource" do - visit resources_path - - find("a[href='/resources/#{resource.id}/download']").click - - wait_for_download - expect(downloads.length).to eq(1) - expect(download).to match(/.*\.pdf/) - end - end - - context "when visiting download path directly" do - it "downloads the resource" do - visit "/resources/#{resource.id}/download" - - wait_for_download - expect(downloads.length).to eq(1) - expect(download).to match(/.*\.pdf/) - end - end - end -end diff --git a/spec/system/person_filters_workshops_test.rb b/spec/system/person_filters_workshops_test.rb deleted file mode 100644 index f483c918d..000000000 --- a/spec/system/person_filters_workshops_test.rb +++ /dev/null @@ -1,239 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'People can filter workshops using metadata' do - describe "Workshop filtering" do - context "when regular person is logged in" do - let(:user) { create(:user) } - let(:adult_window) { create(:windows_type, :adult) } - let(:child_window) { create(:windows_type, :children) } - let(:combined_window) { create(:windows_type, :combined) } - - let(:sector_veterans) { create(:sector, :published, name: "Veterans & Military") } - let(:sector_lgbtqia) { create(:sector, :published, name: "LGBTQIA") } - let(:sector_child_abuse) { create(:sector, :published, name: "Child Abuse") } - let(:sector_education) { create(:sector, :published, name: "Education/Schools") } - - before do - create(:person, user: user) - - # Create test workshops - workshop_world = create(:workshop, :published, title: 'The best workshop in the world', windows_type: adult_window) - workshop_world.sectors << sector_veterans - workshop_world.sectors << sector_education - - workshop_mars = create(:workshop, :published, title: 'The best workshop on mars', windows_type: child_window) - workshop_mars.sectors << sector_lgbtqia - - workshop_hello = create(:workshop, :published, title: 'oh hello!', windows_type: combined_window) - workshop_hello.sectors << sector_child_abuse - - workshop_combo = create(:workshop, :published, title: 'Combined workshop', windows_type: combined_window) - workshop_combo.sectors << sector_veterans - workshop_combo.sectors << sector_lgbtqia - workshop_combo.sectors << sector_education - - sign_in user - visit workshops_path - end - - it "shows workshops index page with filters" do - expect(page).to have_content("Workshops") - expect(page).to have_content('The best workshop in the world') - expect(page).to have_content('oh hello!') - expect(page).to have_content('The best workshop on mars') - expect(page).to have_content('Windows audience') - expect(page).to have_content('Sector') - expect(page).to have_content('Visibility') - end - - it "filters by Adult window type" do - find("#windows-types-button").click - check "Adult" - - expect(page).to have_content('The best workshop in the world') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('oh hello!') - end - - it "filters by Children window type" do - find("#windows-types-button").click - check "Children" - - expect(page).to have_content('The best workshop on mars') - expect(page).not_to have_content('The best workshop in the world') - expect(page).not_to have_content('oh hello!') - end - - it "filters by Combined window type" do - find("#windows-types-button").click - check "Combined" - - expect(page).to have_content('oh hello!') - expect(page).to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop in the world') - expect(page).not_to have_content('The best workshop on mars') - end - - it "filters by multiple window types" do - find("#windows-types-button").click - check "Children" - check "Combined" - - expect(page).to have_content('oh hello!') - expect(page).to have_content('The best workshop on mars') - expect(page).to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop in the world') - end - - it "filters by Veterans & Military sector" do - find("#sectors-button").click - check "Veterans & Military" - - expect(page).to have_content('The best workshop in the world') - expect(page).to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('oh hello!') - end - - it "filters by LGBTQIA sector" do - find("#sectors-button").click - check "Lgbtqia" - - expect(page).to have_content('The best workshop on mars') - expect(page).to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop in the world') - expect(page).not_to have_content('oh hello!') - end - - it "filters by Child Abuse sector" do - find("#sectors-button").click - check "Child Abuse" - - expect(page).to have_content('oh hello!') - expect(page).not_to have_content('The best workshop in the world') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('Combined workshop') - end - - it "filters by multiple sectors" do - find("#sectors-button").click - check "Veterans & Military" - check "Education/Schools" - - expect(page).to have_content('The best workshop in the world') - expect(page).to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('oh hello!') - end - - it "combines window type and sector filters" do - find("#windows-types-button").click - check "Adult" - find("#sectors-button").click - check "Veterans & Military" - - expect(page).to have_content('The best workshop in the world') - expect(page).not_to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('oh hello!') - end - - it "combines Combined window type with LGBTQIA sector" do - find("#windows-types-button").click - check "Combined" - find("#sectors-button").click - check "Lgbtqia" - - expect(page).to have_content('Combined workshop') - expect(page).not_to have_content('The best workshop in the world') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('oh hello!') - end - - it "shows no results when filters match nothing" do - find("#windows-types-button").click - check "Adult" - find("#sectors-button").click - check "Child Abuse" - - expect(page).to have_content('WORKSHOPS (0)') - expect(page).to have_content('Your search returned no results. Please try again.') - expect(page).not_to have_content('The best workshop in the world') - expect(page).not_to have_content('The best workshop on mars') - expect(page).not_to have_content('oh hello!') - expect(page).not_to have_content('Combined workshop') - end - end - - context "when admin facilitator is logged in" do - let(:admin) { create(:user, :admin) } - let(:adult_window) { create(:windows_type, :adult) } - let(:child_window) { create(:windows_type, :children) } - let(:sector_veterans) { create(:sector, :published, name: "Veterans & Military") } - let(:sector_lgbtqia) { create(:sector, :published, name: "LGBTQIA") } - - before do - create(:person, user: admin) - - # Published workshop - published_workshop = create(:workshop, - title: 'Published Workshop', - windows_type: adult_window, - published: true) - published_workshop.sectors << sector_veterans - - # Hidden workshop - hidden_workshop = create(:workshop, - title: 'Hidden Workshop', - windows_type: child_window, - published: false) - hidden_workshop.sectors << sector_lgbtqia - - another_published = create(:workshop, - title: 'Another Published Workshop', - windows_type: adult_window, - published: true) - another_published.sectors << sector_lgbtqia - - sign_in admin - visit workshops_path - end - - it "shows publish status filter for admin" do - expect(page).to have_content('Visibility') - expect(page).to have_content('Published Workshop') - expect(page).to have_content('Another Published Workshop') - expect(page).to have_content('Hidden Workshop') - end - - it "filters to show only unpublished workshops" do - find("#visibility-filter-button").click - check "visibility_unpublished" - - expect(page).to have_content('Hidden Workshop') - expect(page).not_to have_content('Published Workshop') - expect(page).not_to have_content('Another Published Workshop') - end - - it "filters to show only published workshops" do - find("#visibility-filter-button").click - check "visibility_published" - - expect(page).to have_content('Published Workshop') - expect(page).to have_content('Another Published Workshop') - expect(page).not_to have_content('Hidden Workshop') - end - - it "combines publish status with sector filter" do - find("#visibility-filter-button").click - check "visibility_unpublished" - find("#sectors-button").click - check "Lgbtqia" - - expect(page).to have_content('Hidden Workshop') - expect(page).not_to have_content('Published Workshop') - expect(page).not_to have_content('Another Published Workshop') - end - end - end -end diff --git a/spec/system/person_registers_for_event_test.rb b/spec/system/person_registers_for_event_test.rb deleted file mode 100644 index 11a6cc2dc..000000000 --- a/spec/system/person_registers_for_event_test.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can register for an event" do - describe "Person signs in, views the events and register for the events" do - context "When Person is logged in" do - before do - user = create(:user) - create(:person, user: user) - - @event = create(:event, - title: "Upcoming Workshop", - start_date: 1.day.from_now, - end_date: 2.days.from_now, - registration_close_date: 1.day.from_now, -published: true, - featured: true - ) - create(:event, - title: "Another Event", - start_date: 2.days.from_now, - end_date: 3.days.from_now, - registration_close_date: 1.day.from_now, - published: true, - featured: true, - created_by: user - ) - - sign_in user - visit '/' - end - - # home page registration - it "Register for events from home page" do - within("#card_event_#{@event.id}") do - expect(page).to have_button("Register") - click_button 'Register' - end - - within("#card_event_#{@event.id}") do - expect(page).to have_css("span.text-xs.bg-green-100.text-green-700.px-2.py-0\\.5.rounded-full", - text: "Registered") - expect(page).to have_button("De-register") - expect(page).to have_no_button("Register") - expect(page).to have_link("Google") - apple_link = find('a', text: "Apple") - expect(apple_link[:download]).to end_with(".ics") - expect(page).to have_link("Office 365") - expect(page).to have_link("Yahoo") - - accept_confirm do - click_button "De-register" - end - expect(page).to have_button("Register") - expect(page).to have_no_content("Registered") - end - end - - it "navigates to events via community" do - expect(page).to have_button("Community") - click_button 'Community' - within('#community_menu') do - click_link 'Events' - end - expect(page).to have_current_path(events_path) - end - - it "navigate to events page" do - expect(page).to have_content("Upcoming Events") - - # events - expect(page).to have_content("Upcoming Workshop") - expect(page).to have_content("Another Event") - - expect(page).to have_link("View all events") - click_link "View all events" - expect(page).to have_current_path(events_path) - end - - it "Register for the event" do - visit events_path - - within("#card_event_#{@event.id}") do - expect(page).to have_button("Register") - click_button 'Register' - end - - within("#card_event_#{@event.id}") do - expect(page).to have_css("span.text-xs.bg-green-100.text-green-700.px-2.py-0\\.5.rounded-full", - text: "Registered") - expect(page).to have_button("De-register") - expect(page).to have_no_button("Register") - expect(page).to have_link("Google") - apple_link = find('a', text: "Apple") - expect(apple_link[:download]).to end_with(".ics") - expect(page).to have_link("Office 365") - expect(page).to have_link("Yahoo") - - # de-register - accept_confirm do - click_button "De-register" - end - expect(page).to have_button("Register") - expect(page).to have_no_content("Registered") - end - end - end - end -end diff --git a/spec/system/person_searches_resources_test.rb b/spec/system/person_searches_resources_test.rb deleted file mode 100644 index 3d4bf408c..000000000 --- a/spec/system/person_searches_resources_test.rb +++ /dev/null @@ -1,201 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can search for resources" do - describe "create person and login and resources" do - context "When user is logged in" do - before do - user = create(:user) - create(:person, user: user) - create(:resource, :published, title: "Scholarship Application Guide", featured: true, kind: "Scholarship") - create(:resource, :published, title: "Workshop Session Template", kind: "Template") - create(:resource, :published, title: "Participant Handout Package", kind: "Handout") - create(:resource, :published, title: "Facilitator Toolkit Complete Set", kind: "Toolkit") - create(:resource, :published, title: "Registration and Consent Forms", kind: "Form") - create(:resource, :published, title: "Facilitator Resource Guide", kind: "Toolkit") - sign_in user - visit '/' - end - - it "navigate to resources and see results" do - visit resources_path - - expect(page).to have_content('Resources') - expect(page).to have_content('KINDS (CLICK TO FILTER)') - - expect(page).to have_content('Workshop Session Template') - expect(page).to have_content('Participant Handout Package') - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_content('Registration and Consent Forms') - expect(page).to have_content('Facilitator Resource Guide') - end - - describe "filtering with the kinds" do - before do - visit resources_path - end - - it "filter for Handouts" do - find('label', text: 'Handouts').click - expect(page).to have_content('Participant Handout Package') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "filter for Templates" do - find('label', text: 'Templates').click - expect(page).to have_content('Workshop Session Template') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "filter for Toolkits" do - find('label', text: 'Toolkits').click - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_content('Facilitator Resource Guide') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "filter for Forms" do - find('label', text: 'Forms').click - expect(page).to have_content('Registration and Consent Forms') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - end - - it "filter for multiple kinds" do - find('label', text: 'Toolkits').click - find('label', text: 'Forms').click - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_content('Facilitator Resource Guide') - expect(page).to have_content('Registration and Consent Forms') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - end - - it "clears kind buttons and keyword filter with Clear filters" do - # Select a kind filter - find('label', text: 'Toolkits').click - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Workshop Session Template') - - # Clear all filters - click_link "Clear filters" - - # All resources should reappear - expect(page).to have_content('Workshop Session Template') - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_content('Participant Handout Package') - expect(page).to have_content('Registration and Consent Forms') - expect(page).to have_content('Facilitator Resource Guide') - - # Kind checkbox should be unchecked - expect(find("#kind_Toolkit", visible: :all)).not_to be_checked - end - - describe "keyword search" do - it "searches for resource with 'Template' keyword" do - fill_in "query", with: "Template" - expect(page).to have_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "searches for resource with 'Session' keyword" do - fill_in "query", with: "Session" - expect(page).to have_content('Workshop Session Template') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "searches for resource with 'Handout' keyword" do - fill_in "query", with: "Handout" - expect(page).to have_content('Participant Handout Package') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "clears search with empty string" do - fill_in "query", with: "Handout" - expect(page).to have_content('Participant Handout Package') - - fill_in "query", with: "" - expect(page).to have_content('Workshop Session Template') - expect(page).to have_content('Participant Handout Package') - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_content('Registration and Consent Forms') - end - - it "searches for resource that doesn't exist" do - fill_in "query", with: "NonexistentResource" - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Registration and Consent Forms') - expect(page).to have_content('There are no resources that match your search. Please try again.') - end - - it "shows multiple results for partial match" do - fill_in "query", with: "Facilitator" - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_content('Facilitator Resource Guide') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Registration and Consent Forms') - end - - it "combines keyword search with kind filter" do - find('label', text: 'Toolkits').click - fill_in "query", with: "Complete" - expect(page).to have_content('Facilitator Toolkit Complete Set') - expect(page).to have_no_content('Facilitator Resource Guide') - expect(page).to have_no_content('Scholarship Application Guide') - expect(page).to have_no_content('Workshop Session Template') - expect(page).to have_no_content('Participant Handout Package') - expect(page).to have_no_content('Registration and Consent Forms') - end - end - - describe "pagination testing" do - before do - # Create 30 resources for pagination - 30.times do |i| - create(:resource, :published, - title: "Test Resource #{i+1}", - kind: [ "Toolkit", "Handout", "Template", "Form" ].sample - ) - end - end - - it "shows pagination" do - visit resources_path - - # pagination existence - expect(page).to have_css('div.pagination.flex.justify-center.mt-6.w-full') - expect(page).to have_css('span', text: '1') - expect(page).to have_css('a', text: '2') - expect(page).to have_css('a', text: '3') - - expect(page).to have_content('Test Resource') - expect(page).to have_link('2') - end - end - end - end - end -end diff --git a/spec/system/person_searches_workshop_test.rb b/spec/system/person_searches_workshop_test.rb deleted file mode 100644 index 8fef0221c..000000000 --- a/spec/system/person_searches_workshop_test.rb +++ /dev/null @@ -1,79 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'People can search for a workshop' do - describe "Person searches a workshop" do - context "when person is logged in" do - before do - user = create(:user) - create(:person, user: user) - - adult_window = create(:windows_type, :adult) - workshop_world = create(:workshop, :published, title: 'The best workshop in the world', windows_type: adult_window) - workshop_mars = create(:workshop, :published, title: 'The best workshop on mars', windows_type: adult_window) - workshop_hello = create(:workshop, :published, title: 'oh hello!', windows_type: adult_window) - - sign_in user - visit '/' - end - - it "views all workshops on the index page" do - visit workshops_path - expect(page).to have_current_path(workshops_path) - expect(page).to have_content('Workshops') - - expect(page).to have_content('The best workshop in the world') - expect(page).to have_content('The best workshop on mars') - expect(page).to have_content('oh hello!') - end - - it "searches for workshop with 'world' keyword" do - visit workshops_path - fill_in 'title', with: "world" - expect(page).to have_content('The best workshop in the world') - expect(page).to have_no_content("The best workshop on mars") - expect(page).to have_no_content("oh hello!") - end - - it "searches for workshop with 'mars' keyword" do - visit workshops_path - fill_in 'title', with: "mars" - expect(page).to have_content('The best workshop on mars') - expect(page).to have_no_content("The best workshop in the world") - expect(page).to have_no_content("oh hello!") - end - - it "searches for workshop with 'hello' keyword" do - visit workshops_path - fill_in 'title', with: "hello" - expect(page).to have_content('oh hello!') - expect(page).to have_no_content("The best workshop in the world") - expect(page).to have_no_content("The best workshop on mars") - end - - it "searches for workshop with 'the best' keyword for multiple results" do - visit workshops_path - fill_in 'title', with: "the best" - expect(page).to have_content("The best workshop in the world") - expect(page).to have_content("The best workshop on mars") - expect(page).to have_no_content('oh hello!') - end - - it "shows no results for non-matching search" do - visit workshops_path - fill_in 'title', with: "nonexistent" - expect(page).to have_no_content('The best workshop in the world') - expect(page).to have_no_content('The best workshop on mars') - expect(page).to have_no_content('oh hello!') - expect(page).to have_content('Your search returned no results. Please try again.') - end - - it "shows all workshops when search is cleared" do - visit workshops_path - fill_in 'title', with: "" - expect(page).to have_content('The best workshop in the world') - expect(page).to have_content("The best workshop on mars") - expect(page).to have_content("oh hello!") - end - end - end -end diff --git a/spec/system/person_submits_story_test.rb b/spec/system/person_submits_story_test.rb deleted file mode 100644 index cee57ba40..000000000 --- a/spec/system/person_submits_story_test.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "rails_helper" - -RSpec.describe "People can submit a story", type: :system do - describe "Share Your Story form" do - context "When person is logged in" do - before do - create(:windows_type, :adult) - create(:windows_type, :children) - create(:windows_type, :combined) - - @user = create(:user) - create(:person, user: @user) - - sign_in @user - visit new_story_path - end - - it "shows the New Story form" do - expect(page).to have_content("New story") - expect(page).to have_field("Title") - expect(page).to have_field("Body") - end - - it "can fill out and submit a story with workshop context" do - fill_in "Title", with: "Healing Through Art: My Journey with AWBW" - - check "Published" if page.has_field?("Published") - check "Featured" if page.has_field?("Featured") - select "ADULT", from: "story_windows_type_id" - - fill_in "Body *", with: <<~STORY - - Through AWBW"s workshops, I learned to process my grief and anxiety.#{" "} - The art therapy sessions helped me express the fear I felt when#{" "} - I thought I lost everything. Creating visual representations of#{" "} - the Great Barrier Reef allowed me to reconnect with joyful memories#{" "} - of Coral, rather than just the trauma of her loss. - STORY - - fill_in "Youtube url", with: "https://youtube.com/watch?v=2zLkasScy7A" - fill_in "Website url", with: "https://awbw.org/success-stories" - - # File uploads - if page.has_field?("Primary media") - attach_file "Primary media", Rails.root.join("spec/fixtures/some_image.jpg") - end - - if page.has_field?("Secondary media 1") - attach_file "Secondary media 1", Rails.root.join("spec/fixtures/some_image.jpg") - end - select @user.name, from: "story_created_by_id" - # Submit - click_button "Submit" - - expect(page).to have_content("Story was successfully created.") - expect(page).to have_content("Healing Through Art") - expect(page).to have_current_path(story_path(Story.last)) -end - it "can cancel the form" do - click_link "Cancel" - expect(page).not_to have_content("stories") - expect(page).to have_current_path(stories_path) - end - end - end -end diff --git a/spec/system/person_submits_workshop_idea_test.rb b/spec/system/person_submits_workshop_idea_test.rb deleted file mode 100644 index e52347cd9..000000000 --- a/spec/system/person_submits_workshop_idea_test.rb +++ /dev/null @@ -1,82 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can submit a workshop idea", type: :system do - describe "Navigate to Workshop Idea page" do - context "When Person is logged in" do - let!(:adult_windows_type) { create(:windows_type, :adult) } - let!(:children_windows_type) { create(:windows_type, :children) } - let!(:combined_windows_type) { create(:windows_type, :combined) } - - let(:user) { create(:user, :admin) } - - before do - Capybara.current_session.current_window.resize_to(1920, 5000) - create(:person, user: user) - sign_in user - visit new_workshop_idea_path - end - - it "shows the new workshop form" do - expect(page).to have_content("New Workshop Idea") - end - - it "submits the form successfully when all required fields are filled" do - fill_in 'workshop_idea_title', with: 'My Amazing Workshop' - select 'ADULT', from: 'workshop_idea_windows_type_id' - - click_button 'Submit' - expect(page).to have_content('Workshop idea was successfully created') - expect(page).to have_current_path(workshop_idea_path(WorkshopIdea.last)) - end - - it "cancels the form when clicking Cancel" do - fill_in 'workshop_idea_title', with: 'My unsubmitted Workshop' - select 'ADULT', from: 'workshop_idea_windows_type_id' - - click_link 'Cancel' - expect(page).to have_current_path(workshop_ideas_path) - expect(page).to have_content('Workshop ideas') - end - - context "validation errors" do - it "shows a validation error when title is missing" do - select 'ADULT', from: 'workshop_idea_windows_type_id' - - click_button 'Submit' - - expect(page).to have_content("can't be blank").or have_content("Title can't be blank") - expect(page).not_to have_content('Workshop idea was successfully created') - end - - it "shows a validation error when windows audience is missing" do - fill_in 'workshop_idea_title', with: 'Workshop Without Audience' - - click_button 'Submit' - - expect(page).to have_content("Windows type must exist") - expect(page).not_to have_content('Workshop idea was successfully created') - end - - it "shows validation errors when all required fields are missing" do - click_button 'Submit' - - expect(page).to have_css('[data-field="errors"], .errors, #error_explanation, [class*="error"]') - expect(page).not_to have_content('Workshop idea was successfully created') - end - it "shows a validation error when an invalid file type is attached" do - fill_in 'workshop_idea_title', with: 'Workshop With Bad File' - select 'ADULT', from: 'workshop_idea_windows_type_id' - - attach_file( - Rails.root.join('spec/fixtures/files/sample.txt'), - make_visible: true - ) - - click_button 'Submit' - expect(page).to have_content("File type not accepted") - expect(page).to have_content("Gallery assets file type not accepted") - end - end - end - end -end diff --git a/spec/system/person_submits_workshop_log_test.rb b/spec/system/person_submits_workshop_log_test.rb deleted file mode 100644 index 42fc9837c..000000000 --- a/spec/system/person_submits_workshop_log_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -require "rails_helper" - -RSpec.describe "People can submit a workshop log" do - describe "workshop log submission by person" do - context "when person is logged in" do - before do - @user = create(:user) - create(:person, user: @user) - - adult_window = create(:windows_type, :adult) - @windows_type = create(:windows_type, short_name: "Combined") - - @form_builder = FormBuilder.create!(windows_type_id: @windows_type.id, name: "The form") - @form_builder.forms.create! - - create(:workshop, :published, title: 'The best workshop in the world', windows_type: adult_window, featured: true) - create(:workshop, :published, title: 'The best workshop on mars', windows_type: adult_window, featured: true) - - @organization = create(:organization, name: "Test Project", windows_type_id: @windows_type.id) - person = Person.find_by(user: @user) - Affiliation.create!(person: person, organization: @organization, position: :default) - - sign_in @user - visit new_workshop_log_path - end - it "successfully submits a complete workshop log" do - expect(page).to have_content("New workshop log") - select "The best workshop in the world", from: "workshop_log[workshop_id]" - select @organization.name, from: "workshop_log[organization_id]" - fill_in "workshop_log[workshop_held_on]", with: 1.day.ago.strftime("%m-%d-%Y") - - fill_in "workshop_log_children_ongoing", with: "5" - fill_in "workshop_log_teens_ongoing", with: "3" - fill_in "workshop_log_adults_ongoing", with: "10" - fill_in "workshop_log_children_first_time", with: "2" - fill_in "workshop_log_teens_first_time", with: "1" - fill_in "workshop_log[adults_first_time]", with: "4" - - - click_link "Add Quote" - quote_fields = page.all("textarea[name*='[quote_attributes][quote]']") - quote_fields.last.set("This workshop helped me express feelings I couldn't put into words") - - age_fields = page.all("input[name*='[quote_attributes][age]']") - age_fields.last.set("32") - # second quote - click_link "Add Quote" - quote_fields = page.all("textarea[name*='[quote_attributes][quote]']") - quote_fields.last.set("Art has given me a new voice for my emotions") - - age_fields = page.all("input[name*='[quote_attributes][age]']") - age_fields.last.set("teen") - - remove_links = page.all('a', text: "Delete") - remove_links.last.click if remove_links.count >= 2 - - expect(page).not_to have_content("Art has given me a new voice") - - - # Upload a file - find("#workshop_log_gallery_assets_attributes_0_file", visible: :all) - .set(Rails.root.join('spec/fixtures/some_file.png')) - # second file - click_link "Add another file" - expect(page).to have_css('input[type="file"]', minimum: 2, visible: :all) - file_inputs = page.all('input[type="file"]', visible: :all) - file_inputs.last.set(Rails.root.join('spec/fixtures/some_file1.png')) - # Submit - click_button "Submit" - expect(page).to have_content("Thank you for submitting a workshop log") - end - - it "validates required fields individually" do - visit new_workshop_log_path - - # Missing organization - select "The best workshop in the world", from: "workshop_log[workshop_id]" - fill_in "workshop_log[workshop_held_on]", with: 1.day.ago.strftime("%m-%d-%Y") - select "", from: "workshop_log[organization_id]" - click_button "Submit" - expect(page).to have_content("Project must exist") - - # Missing workshop - visit new_workshop_log_path - select @organization.name, from: "workshop_log[organization_id]" - fill_in "workshop_log[workshop_held_on]", with: 1.day.ago.strftime("%m-%d-%Y") - click_button "Submit" - expect(page).to have_content("Workshop must exist") - - # Missing date - visit new_workshop_log_path - select "The best workshop in the world", from: "workshop_log[workshop_id]" - select @organization.name, from: "workshop_log[organization_id]" - click_button "Submit" - expect(page).to have_content("Date can't be blank") - end - end - end -end diff --git a/spec/system/person_submits_workshop_variation_idea_test.rb b/spec/system/person_submits_workshop_variation_idea_test.rb deleted file mode 100644 index 4aa3cc96a..000000000 --- a/spec/system/person_submits_workshop_variation_idea_test.rb +++ /dev/null @@ -1,250 +0,0 @@ -require "rails_helper" - -RSpec.describe "People can submit a workshop variation idea", type: :system do - def fill_in_rhino_editor(content) - page.execute_script( - "document.getElementById('workshop_variation_idea_rhino_body').value = arguments[0]", - content - ) - end - - def select_workshop_via_tom_select(workshop_title) - find(".ts-control").click - find(".ts-control input").set(workshop_title) - within(".ts-dropdown") do - find(".option", text: workshop_title).click - end - end - - def select_organization(organization) - find("#workshop_variation_idea_organization_id option[value='#{organization.id}']").select_option - end - - def open_mobile_new_menu - find("button[data-dropdown-payload-param*='mobile-menu']").click - within("#mobile-menu") do - find("button", text: "New").click - end - end - - def fill_in_variation_idea_form(workshop_title:, windows_type_short_name:, organization: nil) - fill_in "Variation name", with: "My Healing Art Variation" - select_workshop_via_tom_select(workshop_title) - select windows_type_short_name, from: "workshop_variation_idea_windows_type_id" - select_organization(organization) if organization - fill_in_rhino_editor("
This is my variation idea with details about adaptation.
") - select "I would like my full name published with the story", - from: "workshop_variation_idea_author_credit_preference" - check "workshop_variation_idea_permission_given" - end - - describe "Regular user submits from navbar" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:windows_type) { create(:windows_type, :adult) } - let!(:workshop) { create(:workshop, :published, title: "Healing Through Art", windows_type: windows_type) } - let!(:organization) { create(:organization, name: "Test Agency") } - - before do - create(:affiliation, person: person, organization: organization) - create(:affiliation, person: person, organization: create(:organization, name: "Second Agency")) - sign_in user - visit root_path - end - - it "navigates via mobile navbar, fills form, and submits successfully" do - open_mobile_new_menu - click_link "New workshop variation idea" - - expect(page).to have_content("New workshop variation idea") - - fill_in_variation_idea_form( - workshop_title: "Healing Through Art", - windows_type_short_name: "Adult", - organization: organization - ) - - click_button "Submit" - - expect(page).to have_content("Workshop variation idea was successfully created.") - expect(page).to have_content("My Healing Art Variation") - end - end - - describe "Regular user submits from workshop show page" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:windows_type) { create(:windows_type, :adult) } - let!(:workshop) { create(:workshop, :published, title: "Creative Expression", windows_type: windows_type) } - let!(:organization) { create(:organization, name: "Art Center") } - - before do - create(:affiliation, person: person, organization: organization) - create(:affiliation, person: person, organization: create(:organization, name: "Backup Agency")) - sign_in user - visit workshop_path(workshop) - end - - it "clicks 'New variation idea' from workshop show, fills form, and redirects back" do - click_link "New variation idea", wait: 10 - - expect(page).to have_content("New workshop variation idea") - - fill_in_variation_idea_form( - workshop_title: "Creative Expression", - windows_type_short_name: "Adult", - organization: organization - ) - - click_button "Submit" - - expect(page).to have_content("Workshop variation idea was successfully created.") - expect(page).to have_content(workshop.title) - end - end - - describe "Admin submits from navbar" do - let(:admin) { create(:user, :admin) } - let(:person) { create(:person, user: admin) } - let!(:windows_type) { create(:windows_type, :adult) } - let!(:workshop) { create(:workshop, :published, title: "Advanced Art Therapy", windows_type: windows_type) } - let!(:organization) { create(:organization, name: "Admin Org") } - - before do - create(:affiliation, person: person, organization: organization) - create(:affiliation, person: person, organization: create(:organization, name: "Admin Org 2")) - sign_in admin - visit root_path - end - - it "navigates via mobile navbar, fills form, and redirects to show page" do - open_mobile_new_menu - click_link "New workshop variation idea" - - expect(page).to have_content("New workshop variation idea") - - fill_in_variation_idea_form( - workshop_title: "Advanced Art Therapy", - windows_type_short_name: "Adult", - organization: organization - ) - - click_button "Submit" - - expect(page).to have_content("Workshop variation idea was successfully created.") - expect(page).to have_content("My Healing Art Variation") - end - end - - describe "Admin submits from workshop show page" do - let(:admin) { create(:user, :admin) } - let(:person) { create(:person, user: admin) } - let!(:windows_type) { create(:windows_type, :adult) } - let!(:workshop) { create(:workshop, :published, title: "Mindful Drawing", windows_type: windows_type) } - let!(:organization) { create(:organization, name: "Mindful Agency") } - - before do - create(:affiliation, person: person, organization: organization) - create(:affiliation, person: person, organization: create(:organization, name: "Mindful Agency 2")) - sign_in admin - visit workshop_path(workshop) - end - - it "clicks 'New variation idea' from workshop show and redirects back to workshop" do - click_link "New variation idea", wait: 10 - - expect(page).to have_content("New workshop variation idea") - - fill_in_variation_idea_form( - workshop_title: "Mindful Drawing", - windows_type_short_name: "Adult", - organization: organization - ) - - click_button "Submit" - - expect(page).to have_content("Workshop variation idea was successfully created.") - expect(page).to have_content(workshop.title) - end - end - - describe "Organization field based on affiliations" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:windows_type) { create(:windows_type, :adult) } - let!(:workshop) { create(:workshop, :published, title: "Org Test Workshop", windows_type: windows_type) } - let!(:organization) { create(:organization, name: "Primary Agency") } - - context "when user has one affiliation" do - before do - create(:affiliation, person: person, organization: organization) - sign_in user - visit new_workshop_variation_idea_path - end - - it "auto-sets organization without showing the dropdown" do - expect(page).not_to have_select("workshop_variation_idea_organization_id") - - fill_in "Variation name", with: "Single Org Variation" - select_workshop_via_tom_select("Org Test Workshop") - select "Adult", from: "workshop_variation_idea_windows_type_id" - fill_in_rhino_editor("Variation for a single-org user.
") - select "I would like my full name published with the story", - from: "workshop_variation_idea_author_credit_preference" - check "workshop_variation_idea_permission_given" - - click_button "Submit" - - expect(page).to have_content("Workshop variation idea was successfully created.") - expect(WorkshopVariationIdea.last.organization).to eq(organization) - end - end - - context "when user has multiple affiliations" do - let!(:second_organization) { create(:organization, name: "Second Agency") } - - before do - create(:affiliation, person: person, organization: organization) - create(:affiliation, person: person, organization: second_organization) - sign_in user - visit new_workshop_variation_idea_path - end - - it "requires selecting an organization from the dropdown" do - expect(page).to have_select("workshop_variation_idea_organization_id") - - fill_in "Variation name", with: "Multi Org Variation" - select_workshop_via_tom_select("Org Test Workshop") - select "Adult", from: "workshop_variation_idea_windows_type_id" - select_organization(organization) - fill_in_rhino_editor("Variation for a multi-org user.
") - select "I would like my full name published with the story", - from: "workshop_variation_idea_author_credit_preference" - check "workshop_variation_idea_permission_given" - - click_button "Submit" - - expect(page).to have_content("Workshop variation idea was successfully created.") - expect(WorkshopVariationIdea.last.organization).to eq(organization) - end - end - end - - describe "Form validation errors" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - - before do - create(:affiliation, person: person, organization: create(:organization)) - create(:affiliation, person: person, organization: create(:organization)) - sign_in user - visit new_workshop_variation_idea_path - end - - it "shows validation errors when required fields are missing" do - click_button "Submit" - - expect(page).to have_content("can't be blank") - end - end -end diff --git a/spec/system/person_views_community_news_spec.rb b/spec/system/person_views_community_news_spec.rb deleted file mode 100644 index d2d618b72..000000000 --- a/spec/system/person_views_community_news_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'People can view Community News on the home page' do - describe 'Viewing Community News and Events' do - before do - page.driver.browser.manage.window.resize_to(1400, 4000) - user = create(:user) - create(:person, user: user) - - create( - :event, - :featured, - :published, - :publicly_visible, - :publicly_featured, - title: 'Annual Leadership Summit', - start_date: 2.weeks.from_now, - end_date: 3.weeks.from_now, - description: 'Join us for our annual leadership conference' - ) - - create( - :community_news, - :featured, - :published, - :publicly_visible, - :publicly_featured, - title: 'March Community Newsletter', - rhino_body: 'Exciting updates this month!
' - ) - - sign_in user - visit root_path - end - - describe 'Upcoming Events section' do - it 'displays the Upcoming Events section' do - expect(page).to have_content('Upcoming Events') - end - - xit 'navigates to events page when "View all events" is clicked' do - expect(page).to have_link('View all events') - click_link('View all events') - - expect(page).to have_current_path(events_path) - expect(page).to have_content('Community of Practice Events') - expect(page).to have_content('Annual Leadership Summit') - end - end - - describe 'Community News section' do - it 'displays the Community News section' do - expect(page).to have_content('Community News') - end - - xit 'navigates to community news page when "Read all news" is clicked' do - expect(page).to have_link('Read all news') - click_link('Read all news') - - expect(page).to have_current_path(community_news_index_path) - expect(page).to have_content('Community news') - expect(page).to have_content('March Community Newsletter') - end - end - end -end diff --git a/spec/system/person_views_featured_workshops_test.rb b/spec/system/person_views_featured_workshops_test.rb deleted file mode 100644 index c2d2cccb4..000000000 --- a/spec/system/person_views_featured_workshops_test.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'People can bookmark workshops' do - describe "Person bookmarks a workshop" do - context "when person is logged in" do - before do - user = create(:user) - create(:person, user: user) - adult_window = create(:windows_type, :adult) - create(:workshop, :published, title: 'The best workshop in the world', windows_type: adult_window, featured: true) - create(:workshop, :published, title: 'The best workshop on mars', windows_type: adult_window, featured: true) - create(:workshop, :published, title: 'oh hello!', windows_type: adult_window, featured: true) - create(:workshop, :published, title: 'Advanced Leadership Skills', windows_type: adult_window, featured: true) - create(:workshop, :published, title: 'Mindfulness Meditation', windows_type: adult_window, featured: true) - - - sign_in user - visit '/' - end - def active_slide - find('.swiper-slide-active') - end - - it "verifies featured workshops existence" do - expect(page).to have_content("Featured Workshops") - expect(page).to have_content("The best workshop in the world") - expect(page).to have_content("The best workshop on mars") - expect(page).to have_content("oh hello!") - end - - it "verifies carousel presence" do - expect(page).to have_css('[data-controller="carousel"]') - expect(page).to have_css('.swiper-wrapper') - expect(page).to have_css('.swiper-button-next-custom') - expect(page).to have_css('.swiper-button-prev-custom') - end - - # next btn - it "tests next button functionality" do - expect(page).to have_css('.swiper-button-next-custom') - - find('.swiper-button-next-custom').click - expect(page).to have_content("Advanced Leadership Skills") - - sleep 1 - find('.swiper-button-next-custom').click - expect(page).to have_content("Mindfulness Meditation") - end - - # prev btn - it "tests previous button functionality" do - expect(page).to have_css('.swiper-button-prev-custom') - - find('.swiper-button-prev-custom').click - expect(page).to have_content("The best workshop on mars") - - find('.swiper-button-prev-custom').click - expect(page).to have_content("The best workshop in the world") - - find('.swiper-button-prev-custom').click - expect(page).to have_content("Mindfulness Meditation") - end - end - end -end diff --git a/spec/system/person_views_popular_resources_test.rb b/spec/system/person_views_popular_resources_test.rb deleted file mode 100644 index f1851bbcc..000000000 --- a/spec/system/person_views_popular_resources_test.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can view Popular Resources on the home page" do - describe "Person views and navigates to Popular Resources" do - context "when logged in" do - before do - @user = create(:user) - create(:person, user: @user) - @popular_resource = create(:resource, :published, - title: "Most Popular Resource", - featured: true, - kind: "Handout" - ) - - @unpopular_resource = create(:resource, :published, - title: "Unpopular Resource", - kind: "Template" - ) - - # Create Ahoy events to make the popular resource actually popular - visit = create(:ahoy_visit) - 1000.times do - create(:ahoy_event, - visit: visit, - name: "view.resource", - properties: { - resource_type: "Resource", - resource_id: @popular_resource.id, - resource_title: @popular_resource.title - }, - time: rand(1..30).days.ago - ) - end - - # Create just one event for the unpopular resource - create(:ahoy_event, - visit: visit, - name: "view.resource", - properties: { - resource_type: "Resource", - resource_id: @unpopular_resource.id, - resource_title: @unpopular_resource.title - }, - time: 1.day.ago - ) - - sign_in @user - visit '/' - end - - it "displays the Popular Resources section with the popular resource" do - expect(page).to have_content("Popular Resources") - expect(page).to have_content("Most Popular Resource") - expect(page).not_to have_content("Unpopular Resource") - end - - it "navigates to all resources page via 'Browse all resources' link and sees both resources" do - expect(page).to have_content("Most Popular Resource") - click_link 'Browse all resources' - expect(page).to have_current_path(resources_path) - - expect(page).to have_content("Most Popular Resource") - expect(page).to have_content("Unpopular Resource") - end - - it "navigates to a specific resource page by clicking its title" do - click_link 'Most Popular Resource' - expect(page).to have_current_path(resource_path(@popular_resource)) - expect(page).to have_content("Most Popular Resource") - end - end - end -end diff --git a/spec/system/person_views_story_idea_spec.rb b/spec/system/person_views_story_idea_spec.rb deleted file mode 100644 index 793b34d6d..000000000 --- a/spec/system/person_views_story_idea_spec.rb +++ /dev/null @@ -1,87 +0,0 @@ -require "rails_helper" - -RSpec.describe "Viewing a story idea", type: :system do - let(:windows_type) { create(:windows_type, :combined) } - let(:organization) { create(:organization, name: "Community Arts Project", windows_type_id: windows_type.id) } - let(:workshop) { create(:workshop, :published, title: "Healing Through Art", windows_type: windows_type) } - - describe "as the owner" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:story_idea) do - create(:story_idea, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type) - end - - before do - person # ensure person is created - sign_in user - end - - it "displays the organization as plain text (non-admin)" do - visit story_idea_path(story_idea) - - expect(page).to have_text(organization.name) - expect(page).not_to have_link(organization.name) - end - - it "displays the creator as a clickable label" do - visit story_idea_path(story_idea) - - expect(page).to have_link(user.name, href: person_path(person)) - end - end - - describe "as the owner without a person record" do - let(:user) { create(:user) } - let!(:story_idea) do - create(:story_idea, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type) - end - - before { sign_in user } - - it "displays the creator as plain text" do - visit story_idea_path(story_idea) - - expect(page).to have_text(user.name) - expect(page).not_to have_link(user.name) - end - end - - describe "as an admin" do - let(:admin) { create(:user, :admin) } - let(:creator) { create(:user) } - let(:creator_person) { create(:person, user: creator) } - let!(:story_idea) do - create(:story_idea, - created_by: creator, - organization: organization, - workshop: workshop, - windows_type: windows_type) - end - - before do - creator_person # ensure person is created - sign_in admin - end - - it "displays the organization as a clickable label" do - visit story_idea_path(story_idea) - - expect(page).to have_link(organization.name, href: organization_path(organization)) - end - - it "displays the creator as a clickable label" do - visit story_idea_path(story_idea) - - expect(page).to have_link(creator.name, href: person_path(creator_person)) - end - end -end diff --git a/spec/system/person_views_workshop_log_spec.rb b/spec/system/person_views_workshop_log_spec.rb deleted file mode 100644 index c1ac1a849..000000000 --- a/spec/system/person_views_workshop_log_spec.rb +++ /dev/null @@ -1,144 +0,0 @@ -require "rails_helper" - -RSpec.describe "Viewing a workshop log", type: :system do - let(:windows_type) { create(:windows_type, :combined) } - let(:organization) { create(:organization, name: "Community Arts Project", windows_type_id: windows_type.id) } - let(:workshop) { create(:workshop, :published, title: "Healing Through Art", windows_type: windows_type) } - - describe "as a regular user" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:affiliation) { create(:affiliation, person: person, organization: organization) } - let!(:workshop_log) do - create(:workshop_log, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type, - workshop_held_on: 1.day.ago) - end - - before { sign_in user } - - it "displays the organization as plain text (non-admin)" do - visit workshop_log_path(workshop_log) - - expect(page).to have_text("Community Arts Project") - expect(page).not_to have_link("Community Arts Project") - end - - it "displays the creator as a clickable label" do - visit workshop_log_path(workshop_log) - - expect(page).to have_link(user.name, href: person_path(person)) - end - end - - describe "as a user without a person record" do - let(:user) { create(:user) } - let!(:workshop_log) do - create(:workshop_log, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type, - workshop_held_on: 1.day.ago) - end - - before { sign_in user } - - it "displays the creator as plain text" do - visit workshop_log_path(workshop_log) - - expect(page).to have_text(user.name) - expect(page).not_to have_link(user.name) - end - end - - describe "workshop log with external title and no workshop" do - let(:user) { create(:user) } - let!(:workshop_log) do - create(:workshop_log, - created_by: user, - organization: organization, - workshop: nil, - windows_type: windows_type, - external_workshop_title: "Community Mural Project", - workshop_held_on: 1.day.ago) - end - - before { sign_in user } - - it "displays the external title in the heading" do - visit workshop_log_path(workshop_log) - - expect(page).to have_css("h1", text: "Community Mural Project") - end - - it "displays the external title next to the Workshop label" do - visit workshop_log_path(workshop_log) - - workshop_div = find("span", text: "Workshop:").ancestor("div", match: :first) - expect(workshop_div).to have_text("Community Mural Project") - end - end - - describe "workshop log with both workshop and external title" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:affiliation) { create(:affiliation, person: person, organization: organization) } - let!(:workshop_log) do - create(:workshop_log, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type, - external_workshop_title: "Guest-led Session", - workshop_held_on: 1.day.ago) - end - - before { sign_in user } - - it "displays the workshop name in the heading" do - visit workshop_log_path(workshop_log) - - expect(page).to have_css("h1", text: "Healing Through Art") - end - - it "displays both the workshop chip and external title" do - visit workshop_log_path(workshop_log) - - workshop_div = find("span", text: "Workshop:").ancestor("div", match: :first) - expect(workshop_div).to have_text("Healing Through Art") - expect(workshop_div).to have_text("Guest-led Session") - end - end - - describe "as an admin" do - let(:admin) { create(:user, :admin) } - let(:person) { create(:person, user: admin) } - let!(:affiliation) { create(:affiliation, person: person, organization: organization) } - let!(:workshop_log) do - create(:workshop_log, - created_by: admin, - organization: organization, - workshop: workshop, - windows_type: windows_type, - workshop_held_on: 1.day.ago) - end - - before { sign_in admin } - - it "displays the organization as a clickable label" do - visit workshop_log_path(workshop_log) - - expect(page).to have_link("Community Arts Project", href: organization_path(organization)) - end - - it "displays the creator as a clickable label" do - visit workshop_log_path(workshop_log) - - expect(page).to have_link(admin.name, href: person_path(person)) - end - end -end diff --git a/spec/system/person_views_workshop_logs_test.rb b/spec/system/person_views_workshop_logs_test.rb deleted file mode 100644 index 1d268e5a1..000000000 --- a/spec/system/person_views_workshop_logs_test.rb +++ /dev/null @@ -1,98 +0,0 @@ -require "rails_helper" - -RSpec.describe "People can view a submitted workshop log" do - describe "when person is logged in" do - context "viewing workshop logs" do - before do - Capybara.current_session.current_window.resize_to(1920, 5000) - - @user = create(:user) - create(:person, user: @user) - windows_type = create(:windows_type, short_name: "Combined") - - form_builder = FormBuilder.create!(windows_type_id: windows_type.id, name: "The form") - form_builder.forms.create! - - @workshop1 = create(:workshop, :published, title: 'The best workshop in the world', windows_type: windows_type, featured: true) - @workshop2 = create(:workshop, :published, title: 'Art therapy for beginners', windows_type: windows_type, featured: false) - - @organization = create(:organization, name: "Test Project", windows_type_id: windows_type.id) - person = Person.find_by(user: @user) - Affiliation.create!(person: person, organization: @organization, position: :default, title: "Project user") - - @workshop_log1 = create(:workshop_log, - workshop_id: @workshop1.id, - organization_id: @organization.id, - created_by_id: @user.id, - workshop_held_on: 1.day.ago, - adults_first_time: 4, - adults_ongoing: 10, - children_first_time: 2, - children_ongoing: 5, - teens_ongoing: 3, - ) - - @workshop_log2 = create(:workshop_log, - workshop_id: @workshop2.id, - organization_id: @organization.id, - created_by_id: @user.id, - workshop_held_on: 2.months.ago, - adults_first_time: 2, - adults_ongoing: 8, - children_first_time: 1, - children_ongoing: 3, - teens_first_time: 1, - teens_ongoing: 2, - ) - - sign_in @user - visit "/workshop_logs?created_by_id=#{@user.id}" - end - - it "verifies workshop log page has all required elements" do - expect(page).to have_content("Workshop logs") - expect(page).to have_content("Date") - expect(page).to have_content("Workshop") - expect(page).to have_content("Person") - expect(page).to have_content("# Ongoing") - expect(page).to have_content("# First-time") - expect(page).to have_content("children") - expect(page).to have_content("teens") - expect(page).to have_content("adults") - expect(page).to have_content("Action") - expect(page).to have_link("Edit") - expect(page).to have_link("View") - end - - it "displays all workshop logs with correct information" do - expect(page).to have_content(@workshop_log1.workshop_held_on.strftime("%b %d, %Y")) - expect(page).to have_content(@workshop1.title) - expect(page).to have_content("#{@user.person.first_name} #{@user.person.last_name}") - expect(page).to have_content("5") - expect(page).to have_content("3") - expect(page).to have_content("10") - expect(page).to have_content("2") - expect(page).to have_content("4") - expect(page).to have_content("--") - expect(page).to have_content("Grand Total:") - - expect(page).to have_content(@workshop_log2.workshop_held_on.strftime("%b %d, %Y")) - expect(page).to have_content(@workshop2.title) - expect(page).to have_content("#{@user.person.first_name} #{@user.person.last_name}") - end - - it "filters workshop logs by month submitted" do - expect(page).to have_content("Month Submitted") - find("#month_and_year").click - month_filter = @workshop_log2.workshop_held_on.strftime("%B %Y") - select month_filter, from: "month_and_year" - sleep 0.5 - expect(page).to have_content(@workshop_log2.workshop_held_on.strftime("%b %d, %Y")) - expect(page).to have_content(@workshop2.title) - expect(page).to have_content("#{@user.person.first_name} #{@user.person.last_name}") - expect(page).not_to have_content(@workshop_log1.workshop_held_on.strftime("%b %d, %Y")) - expect(page).not_to have_content(@workshop1.title) - end - end - end -end diff --git a/spec/system/person_views_workshop_test.rb b/spec/system/person_views_workshop_test.rb deleted file mode 100644 index 3519c8f10..000000000 --- a/spec/system/person_views_workshop_test.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'rails_helper' - -RSpec.describe "People can view a workshop" do - describe 'workshops views' do - context "When person is logged in" do - before do - user = create(:user) - create(:person, user: user) - adult_window = create(:windows_type, :adult) - @workshop_world = create(:workshop, :published, title: 'The best workshop in the world', windows_type: adult_window) - @workshop_mars = create(:workshop, :published, title: 'The best workshop on mars', windows_type: adult_window, featured: true, rhino_objective: 'take everyone to mars', rhino_materials: 'rocket', rhino_setup: 'make a rocket') - sign_in user - end - - it 'views workshop via home page' do - visit '/' - - expect(page).to have_content('The best workshop on mars') - - find('span', text: 'The best workshop on mars').click - - expect(page).to have_current_path(workshop_path(@workshop_mars)) - - expect(page).to have_css('h1', text: 'The best workshop on mars') - # expect(page).to have_content("Author: #{@workshop_mars.author}") - expect(page).to have_content("Author:") - expect(page).to have_content("Category: #{@workshop_mars.windows_type&.short_name}") - expect(page).to have_content("Added: #{@workshop_mars.created_at.strftime('%B %Y')}") - expect(page).to have_link('Details') - - within '#english-content' do - expect(page).to have_content('Objective') - expect(page).to have_content('Materials') - expect(page).to have_content('Setup') - end - end - - it 'views workshop from search' do - visit workshops_path - - fill_in 'title', with: 'world' - expect(page).to have_content('The best workshop in the world') - - - find('span', text: 'The best workshop in the world').click - - expect(page).to have_current_path(workshop_path(@workshop_world)) - expect(page).to have_css('h1', text: 'The best workshop in the world') - # expect(page).to have_content("Author: #{@workshop_world.author}") - expect(page).to have_content("Author:") - expect(page).to have_content("Category: #{@workshop_world.windows_type&.short_name}") - expect(page).to have_content("Added: #{@workshop_world.created_at.strftime('%B %Y')}") - expect(page).to have_link('Details') - end - - it 'views workshop from bookmarks' do - visit '/workshops' - expect(page).to have_content('Workshops') - expect(page).to have_content('The best workshop in the world') - # Bookmark the workshop - within("#bookmark_icon_workshop_#{@workshop_world.id}") do - find('button').click - end - - expect(page).to have_content("Workshop added to your bookmarks.") - - visit personal_bookmarks_path - expect(page).to have_content('My Bookmarks (1)') - expect(page).to have_content('The best workshop in the world') - - find('a', text: 'The best workshop in the world').click - - expect(page).to have_current_path(workshop_path(@workshop_world)) - expect(page).to have_css('h1', text: 'The best workshop in the world') - # expect(page).to have_content("Author: #{@workshop_world.author}") - expect(page).to have_content("Author:") - expect(page).to have_content("Category: #{@workshop_world.windows_type&.short_name}") - expect(page).to have_content("Added: #{@workshop_world.created_at.strftime('%B %Y')}") - expect(page).to have_link('Details') - end - end - end -end diff --git a/spec/system/person_views_workshop_variation_idea_spec.rb b/spec/system/person_views_workshop_variation_idea_spec.rb deleted file mode 100644 index a839dee22..000000000 --- a/spec/system/person_views_workshop_variation_idea_spec.rb +++ /dev/null @@ -1,87 +0,0 @@ -require "rails_helper" - -RSpec.describe "Viewing a workshop variation idea", type: :system do - let(:windows_type) { create(:windows_type, :combined) } - let(:organization) { create(:organization, name: "Community Arts Project", windows_type_id: windows_type.id) } - let(:workshop) { create(:workshop, :published, title: "Healing Through Art", windows_type: windows_type) } - - describe "as the owner" do - let(:user) { create(:user) } - let(:person) { create(:person, user: user) } - let!(:idea) do - create(:workshop_variation_idea, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type) - end - - before do - person # ensure person is created - sign_in user - end - - it "displays the organization as plain text (non-admin)" do - visit workshop_variation_idea_path(idea) - - expect(page).to have_text(organization.name) - expect(page).not_to have_link(organization.name) - end - - it "displays the creator as a clickable label" do - visit workshop_variation_idea_path(idea) - - expect(page).to have_link(user.name, href: person_path(person)) - end - end - - describe "as the owner without a person record" do - let(:user) { create(:user) } - let!(:idea) do - create(:workshop_variation_idea, - created_by: user, - organization: organization, - workshop: workshop, - windows_type: windows_type) - end - - before { sign_in user } - - it "displays the creator as plain text" do - visit workshop_variation_idea_path(idea) - - expect(page).to have_text(user.name) - expect(page).not_to have_link(user.name) - end - end - - describe "as an admin" do - let(:admin) { create(:user, :admin) } - let(:creator) { create(:user) } - let(:creator_person) { create(:person, user: creator) } - let!(:idea) do - create(:workshop_variation_idea, - created_by: creator, - organization: organization, - workshop: workshop, - windows_type: windows_type) - end - - before do - creator_person # ensure person is created - sign_in admin - end - - it "displays the organization as a clickable label" do - visit workshop_variation_idea_path(idea) - - expect(page).to have_link(organization.name, href: organization_path(organization)) - end - - it "displays the creator as a clickable label" do - visit workshop_variation_idea_path(idea) - - expect(page).to have_link(creator.name, href: person_path(creator_person)) - end - end -end diff --git a/spec/system/sectors_controller_spec.rb b/spec/system/sectors_controller_spec.rb deleted file mode 100644 index 275b7c4d3..000000000 --- a/spec/system/sectors_controller_spec.rb +++ /dev/null @@ -1,82 +0,0 @@ -require 'rails_helper' - -RSpec.describe SectorsController, type: :system do - describe "#index" do - let!(:admin) { create(:user, :admin) } - - before do - sign_in(admin) - end - - subject { visit sectors_path(params) } - - let!(:sectors) do - [ - create(:sector, name: "Sector1", published: true), - create(:sector, name: "Sector2", published: true), - create(:sector, name: "Sector3", published: false), - create(:sector, name: "Sector4", published: false) - ] - end - - context "without filters" do - let(:params) { {} } - - it "returns all sectors" do - subject - within "table" do - sectors.each do |sector| - expect(page).to have_content(sector.name) - expect(page).to have_content(sector.published ? "Yes" : "No") - end - end - end - end - - context "with published filter" do - let(:params) { { published: "true" } } - let(:published_sectors) { sectors.select(&:published) } - - it "returns only published sectors" do - subject - within "table" do - sectors.select(&:published).each do |sector| - expect(page).to have_content(sector.name) - expect(page).to have_content("Yes") - end - expect(page).to have_css('table tbody tr', count: published_sectors.size) - end - end - end - - context "with unpublished filter" do - let(:params) { { published: "false" } } - let(:unpublished_sectors) { sectors.reject(&:published) } - - it "returns only unpublished sectors" do - subject - within "table" do - sectors.reject(&:published).each do |sector| - expect(page).to have_content(sector.name) - expect(page).to have_content("No") - end - expect(page).to have_css('table tbody tr', count: unpublished_sectors.size) - end - end - end - - context "with name filter" do - let(:params) { { sector_name: "Sector1" } } - - it "returns sectors matching the name filter" do - subject - within "table" do - expect(page).to have_content("Sector1") - expect(page).not_to have_content("Sector2") - expect(page).not_to have_content("Sector3") - expect(page).not_to have_content("Sector4") - end - end - end - end - end diff --git a/spec/system/stories_spec.rb b/spec/system/stories_spec.rb deleted file mode 100644 index fd792eec1..000000000 --- a/spec/system/stories_spec.rb +++ /dev/null @@ -1,140 +0,0 @@ -require "rails_helper" - -RSpec.describe "Stories", type: :system do - describe "story index" do - context "as a regular_user" do - it "sees overview of stories" do - sign_in(create(:user)) - visit root_path - - create(:sector, :other) - adult_window = create(:windows_type, :adult) - story_world = create(:story, :published, title: "The best story in the world", windows_type: adult_window) - story_mars = create(:story, :published, title: "The best story on mars", windows_type: adult_window) - story_hello = create(:story, :published, title: "oh hello!", windows_type: adult_window) - story_public = create(:story, :published, :publicly_visible, title: "My public story", windows_type: adult_window) - story_admin = create(:story, title: "The Admins tell their Story", windows_type: adult_window) - - visit stories_path - - expect(page).to have_content("Stories") - expect(page).to have_css("turbo-frame#story_results") - - expect(page).to have_content(story_world.title) - expect(page).to have_content(story_mars.title) - expect(page).to have_content(story_hello.title) - expect(page).to have_content(story_public.title) - expect(page).to_not have_content(story_admin.title) - end - - it "sees message when no stories exist" do - sign_in(create(:user)) - - visit stories_path - - expect(page).to have_content("Stories") - expect(page).to have_css("turbo-frame#story_results") - - expect(page).to have_content("No stories found") - end - - it "User can search for a story" do - user = create(:user) - sign_in(user) - - create(:sector, :other) - adult_window = create(:windows_type, :adult) - facilitator = create(:person, first_name: "John", last_name: "Doe") - story_world = create(:story, :published, title: "The best story in the world", windows_type: adult_window, created_by: facilitator.user, rhino_body: "healing through art") - story_mars = create(:story, :published, title: "The best story on mars", windows_type: adult_window, created_by: facilitator.user, rhino_body: "healing through art") - story_hello = create(:story, :published, title: "oh hello!", windows_type: adult_window, rhino_body: "healing through art") - story_public = create(:story, :published, :publicly_visible, title: "My public story", windows_type: adult_window) - story_admin = create(:story, title: "The Admins tell their Story", windows_type: adult_window) - - visit stories_path - - expect(page).to have_content(story_world.title) - - fill_in "title", with: "best story" - fill_in "query", with: "healing" - - expect(page).to have_content(story_world.title) - expect(page).to have_content(story_mars.title) - expect(page).not_to have_content(story_hello.title) - expect(page).not_to have_content(story_public.title) - expect(page).not_to have_content(story_admin.title) - end - end - end - - describe "view story" do - context "as a regular_user" do - it "sees story show" do - sign_in(create(:user)) - visit root_path - expect(page).to have_no_link("Log In") - story = create(:story, :published, title: "The best story in the world. This is a tribute.") - - visit story_path(story) - - expect(page).to have_content(story.title) - end - - it "cannot see unpublished story show" do - sign_in(create(:user)) - visit root_path - expect(page).to have_no_link("Log In") - story = create(:story, :unpublished, title: "The best story in the world. This is a tribute.") - visit story_path(story) - expect(page).to have_current_path(root_path) - end - end - - context "as a guest" do - it "sees publicly_visible story show" do - story = create(:story, :published, :publicly_visible, title: "The best story in the world. This is a tribute.") - visit story_path(story) - expect(page).to have_content("The best story in the world") - end - - it "cannot see unpublished story show" do - story = create(:story, :unpublished, title: "The best story in the world. This is a tribute.") - visit story_path(story) - expect(page).to have_current_path(root_path) - end - - it "cannot see published story show" do - story = create(:story, :published, title: "The best story in the world. This is a tribute.") - visit story_path(story) - expect(page).to have_current_path(root_path) - end - end - end - - describe "edit story" do - context "When admin is logged in" do - # TODO: fix once we figure out how to get the end-to-end tests - # to work with Turbo Stream - # The redirect works when tested manually. - xit "Admin can edit an existing story" do - user = create(:user, :admin) - sign_in(user) - visit root_path - adult_window = create(:windows_type, :adult) - story = create(:story, title: "Old Title", windows_type: adult_window, created_by: user) - - visit edit_story_path(story) - - within("#edit_story_#{story.id}") do - fill_in "Title", with: "A New Title" - select adult_window.short_name, from: "Windows audience" - click_on "Save changes" - end - - expect(page).to have_content("Story was successfully updated.") - expect(page).to have_current_path(story_path(story)) - expect(page).to have_content("A New Title") - end - end - end -end