Files
old-holivud2/spec/features/user_managing_broadcasts_spec.rb
2020-06-26 14:29:17 +02:00

154 lines
5.3 KiB
Ruby

require "rails_helper"
feature "User managing broadcasts" do
let(:current_user) { create(:user, :manager) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "managing broadcasts" do
before do
sign_in current_user
allow(MuxLiveStream).to receive(:new).and_return(double(id: "id", key: "key", playback_id: "playback_id"))
end
scenario "creating and deleting a broadcast", js: true do
visit new_project_broadcast_path(project)
by "filling out the form" do
fill_in broadcast_name_field, with: "My Broadcast"
end
click_button "Create Live Stream"
expect(page).to have_content("A live stream has been created")
click_on "Manage"
expect(page).to have_link("Copy Stream URL", exact: true)
expect(page).to have_link("Copy Stream Key", exact: true)
expect(page).to have_link("View", exact: true)
expect(page).to have_link("Delete", exact: true)
it_also "Deletes the broadcast" do
allow_any_instance_of(Broadcast).to receive(:destroy_mux_live_stream).and_return(true)
accept_alert do
click_link "Delete"
end
expect(page).to have_content("A live stream has been deleted")
expect(page).not_to have_content("My Broadcast")
end
end
scenario "visit show page of broadcast", js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
recording = create(:broadcast_recording, broadcast: broadcast)
visit project_broadcast_path(project, broadcast)
expect(page).to have_content("Live stream is waiting to begin.")
expect(page).to have_content("Copy URL")
within "#files" do
expect(page).to have_content("contract.pdf")
end
click_on "Previous Sessions"
expect(page).to have_content(recording.download_file_name)
end
scenario "user can go back and forth between live session and previous sessions", js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
recording = create(:broadcast_recording, broadcast: broadcast)
visit project_broadcast_path(project, broadcast)
expect(page).to have_content broadcast.name.titleize, count: 1
expect(page).to have_content recording.download_file_name, count: 0
click_on switch_view_dropdown
expect(page).to have_content broadcast.name.titleize, count: 2
expect(page).to have_content recording.download_file_name, count: 1
live_stream_nav_item = page.find(".dropdown-item", text: broadcast.name.titleize)
recording_nav_item = page.find(".dropdown-item", text: recording.download_file_name)
expect(live_stream_nav_item[:class].include?("active")).to eq true
expect(recording_nav_item[:class].include?("active")).to eq false
click_on recording.download_file_name
expect(page).to have_content broadcast.name.titleize, count: 1
expect(page).to have_content recording.download_file_name, count: 0
expect(live_stream_nav_item[:class].include?("active")).to eq false
expect(recording_nav_item[:class].include?("active")).to eq true
click_on switch_view_dropdown
click_on broadcast.name.titleize
expect(page).to have_content broadcast.name.titleize, count: 1
expect(page).to have_content recording.download_file_name, count: 0
# Page is reloaded, we need to get dropdown items again
live_stream_nav_item = page.find(".dropdown-item", text: broadcast.name.titleize, visible: :all)
recording_nav_item = page.find(".dropdown-item", text: recording.download_file_name, visible: :all)
expect(live_stream_nav_item[:class].include?("active")).to eq true
expect(recording_nav_item[:class].include?("active")).to eq false
end
scenario "form will not submit if user clicks Add files without selected files", js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
visit project_broadcast_path(project, broadcast)
expect(page).to have_content("Live stream is waiting to begin.")
expect(page).to have_content add_file_button
click_on add_file_button
end
scenario "visit multi-view broadcast page", js: true do
broadcast_one = create(:broadcast, :with_stream, :with_files, name: "Broadcast 1", project: project)
broadcast_two = create(:broadcast, :with_stream, :with_files, name: "Broadcast 2", project: project)
visit project_broadcasts_path(project)
click_checkboxes
new_window = window_opened_by { click_link "Multi-View" }
within_window new_window do
expect(page).to have_content switch_view_dropdown
click_on switch_view_dropdown
expect(page).to have_link("Broadcast 1")
expect(page).to have_link("Broadcast 2")
within "#files" do
click_on "Broadcast 1"
expect(page).to have_content("contract.pdf")
click_on "Broadcast 2"
expect(page).to have_content("contract.pdf")
end
end
end
end
private
def add_file_button
'Add File'
end
def broadcast_name_field
"broadcast[name]"
end
def click_checkboxes
all('input[type="checkbox"]')[0].click
all('input[type="checkbox"]')[1].click
end
def switch_view_dropdown
"Switch View"
end
end