require "rails_helper" feature "User managing casting calls" do let(:current_user) { create(:user, :manager) } let(:project) { create(:project, members: current_user, account: current_user.primary_account) } before :each do sign_in current_user end scenario "casting calls table is visible if there are existing casting calls" do create(:casting_call, project: project) visit project_casting_calls_path(project) expect(page).to have_content "Created On" expect(page).to have_content "Title" expect(page).to have_content "Status" end scenario "splash page is shown if there are no existing records" do visit project_casting_calls_path(project) expect(page).to have_content schedule_demo expect(page).to have_content create_casting_call end scenario "sees list of casting calls" do casting_call = create(:casting_call, project: project) visit project_casting_calls_path(project) expect(page).not_to have_content no_casting_calls_label expect(page).to have_content casting_call.created_at.try(:strftime, '%D') expect(page).to have_content casting_call.title expect(page).to have_content casting_call.status end scenario "can create casting call requests" do visit project_casting_calls_path(project) click_on add_new_casting_call_label fill_in title_field, with: "Casting Title" fill_in description_field, with: "Description" fill_in project_description_field, with: "Project Description" fill_in interview_instructions_field, with: "Welcome Message" fill_in interview_requirements_field, with: "Goodbye Message" fill_in questions_field, with: "Questions" click_on "Create Casting call" expect(page).to have_content("The casting call request has been created successfully.") end scenario "can update casting call requests" do create(:casting_call, title: "Title", project: project) visit project_casting_calls_path(project) click_on manage_button click_on "Edit" fill_in title_field, with: "New Title" click_on "Update Casting call" expect(page).to have_content("The casting call request has been updated") end scenario "can cancel a casting call request" do create(:casting_call, title: "Title", project: project) visit project_casting_calls_path(project) click_on manage_button click_on "Cancel" expect(page).to have_content("The casting call request has been cancelled") end scenario "can open casting call details" do cc = create(:casting_call, title: "Dummy title", project: project) visit project_casting_calls_path(project) click_on manage_button click_on view_button expect(page).to have_content cc.title expect(page).to have_content cc.description expect(page).to have_content cc.project_description expect(page).to have_content cc.created_at expect(page).to have_content cc.status expect(page).to have_content cc.interview_instructions expect(page).to have_content cc.interview_requirements expect(page).to have_content cc.questions end context 'When the user is associate' do let(:current_user) { create(:user, :associate) } it 'does show button to create new casting call' do visit project_casting_calls_path(project) expect(page).to have_content schedule_demo expect(page).to have_content create_casting_call end end context 'When the user is account manager' do let(:current_user) { create(:user, :account_manager) } it 'does show button to create new casting call' do visit project_casting_calls_path(project) expect(page).to have_content schedule_demo expect(page).to have_content create_casting_call end end context "when signed out" do scenario "user opens public accessible casting call URL" do cc = create(:casting_call, title: "Dummy title", project: project) sign_out public_url = "/casting_calls/#{cc.token}" visit public_url expect(page).to have_content cc.title expect(page).to have_content cc.description expect(page).to have_content cc.project_description expect(page).not_to have_content cc.created_at expect(page).not_to have_content cc.status expect(page).not_to have_content cc.interview_instructions expect(page).not_to have_content cc.interview_requirements expect(page).not_to have_content cc.questions end end private def no_casting_calls_label t 'casting_calls.index.empty' end def manage_button t "casting_calls.casting_call.actions.manage" end def view_button 'View' end def add_new_casting_call_label t "casting_calls.index.actions.new" end def title_field t "helpers.label.casting_call.title" end def description_field t "helpers.label.casting_call.description" end def project_description_field t "helpers.label.casting_call.project_description" end def interview_instructions_field t "helpers.label.casting_call.interview_instructions" end def interview_requirements_field t "helpers.label.casting_call.interview_requirements" end def questions_field t "helpers.label.casting_call.questions" end def create_casting_call t 'casting_calls.splash.actions.create_casting_call' end def schedule_demo t 'casting_calls.splash.actions.book_demo' end end