From 7ed4c85fc5fa55227eed11058638987c2aedd225 Mon Sep 17 00:00:00 2001 From: diti Date: Fri, 6 Mar 2026 16:25:44 +0100 Subject: [PATCH] Updated workshop_idea submission test --- spec/fixtures/files/sample.txt | 0 .../person_submits_workshop_idea_test.rb | 113 +++++++++--------- 2 files changed, 56 insertions(+), 57 deletions(-) create mode 100644 spec/fixtures/files/sample.txt diff --git a/spec/fixtures/files/sample.txt b/spec/fixtures/files/sample.txt new file mode 100644 index 000000000..e69de29bb diff --git a/spec/system/person_submits_workshop_idea_test.rb b/spec/system/person_submits_workshop_idea_test.rb index 1b24c736e..e52347cd9 100644 --- a/spec/system/person_submits_workshop_idea_test.rb +++ b/spec/system/person_submits_workshop_idea_test.rb @@ -1,82 +1,81 @@ - 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 - before do - create(:windows_type, :adult) - create(:windows_type, :children) - create(:windows_type, :combined) + 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) } - user = create(:user) + 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") + expect(page).to have_content("New Workshop Idea") end - it "submits the form when clicking Submit" do + it "submits the form successfully when all required fields are filled" do fill_in 'workshop_idea_title', with: 'My Amazing Workshop' - select 'ADULT WINDOWS', from: 'workshop_idea_windows_type_id' - # select 'Adult', from:'workshop_idea_age_range' - fill_in 'workshop_idea_objective', with: 'Learn something new' - fill_in 'workshop_idea_description', with: 'This is a test workshop description.' - fill_in 'workshop_idea_materials', with: 'Paper, markers' - fill_in 'workshop_idea_optional_materials', with: 'Scissors, glue' - fill_in 'workshop_idea_setup', with: 'Arrange tables' - fill_in 'workshop_idea_introduction', with: 'Start with a story' - fill_in 'workshop_idea_time_intro', with: 10 - fill_in 'workshop_idea_opening_circle', with: 'Welcome and warm up' - fill_in 'workshop_idea_time_opening_circle', with: 5 - fill_in 'workshop_idea_demonstration', with: 'Show how it works' - fill_in 'workshop_idea_time_demonstration', with: 15 - fill_in 'workshop_idea_warm_up', with: 'Stretching and breathing' - fill_in 'workshop_idea_time_warm_up', with: 5 - fill_in 'workshop_idea_creation', with: 'Hands-on creation' - fill_in 'workshop_idea_time_creation', with: 30 - fill_in 'workshop_idea_closing', with: 'Reflection and clean up' - fill_in 'workshop_idea_time_closing', with: 10 - fill_in 'workshop_idea_notes', with: 'Some notes' - fill_in 'workshop_idea_tips', with: 'Some tips' - attach_file('workshop_primary_media', Rails.root.join('spec/fixtures/some_file.png')) if page.has_field?('workshop_idea_primary_asset_attributes_file') - # Submit + 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 WINDOWS', from: 'workshop_idea_windows_type_id' - # select 'Adult', from:'workshop_idea_age_range' - fill_in 'workshop_idea_objective', with: 'Learn nothing new' - fill_in 'workshop_idea_description', with: 'This is a test workshop description.' - fill_in 'workshop_idea_materials', with: 'Paper, markers' - fill_in 'workshop_idea_optional_materials', with: 'Scissors, glue' - fill_in 'workshop_idea_setup', with: 'Arrange tables' - fill_in 'workshop_idea_introduction', with: 'Start with a story' - fill_in 'workshop_idea_time_intro', with: 10 - fill_in 'workshop_idea_opening_circle', with: 'Welcome and warm up' - fill_in 'workshop_idea_time_opening_circle', with: 5 - fill_in 'workshop_idea_demonstration', with: 'Show how it works' - fill_in 'workshop_idea_time_demonstration', with: 15 - fill_in 'workshop_idea_warm_up', with: 'Stretching and breathing' - fill_in 'workshop_idea_time_warm_up', with: 5 - fill_in 'workshop_idea_creation', with: 'Hands-on creation' - fill_in 'workshop_idea_time_creation', with: 30 - fill_in 'workshop_idea_closing', with: 'Reflection and clean up' - fill_in 'workshop_idea_time_closing', with: 10 - fill_in 'workshop_idea_notes', with: 'Some notes' - fill_in 'workshop_idea_tips', with: 'Some tips' - attach_file('workshop_primary_media', Rails.root.join('spec/fixtures/some_file.png')) if page.has_field?('workshop_idea_primary_asset_attributes_file') - # Cancel + select 'ADULT', from: 'workshop_idea_windows_type_id' + click_link 'Cancel' - expect(page).to have_content('Featured Workshops') - expect(page).to have_content('Community News') + 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