Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve inability to schedule events #3244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/osem-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var Schedule = {
room_id: new_parent.attr("room_id"),
start_time: (new_parent.attr("date") + ' ' + new_parent.attr("hour"))
}};
if(event_schedule_id != null){
if(event_schedule_id){
type = 'PUT';
my_url += ('/' + event_schedule_id);
}
Expand Down
70 changes: 70 additions & 0 deletions spec/features/schedule_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

require 'spec_helper'

def expect_scheduled(event, time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visit admin_conference_program_event_path(event.conference.short_title, event)
if time
date = event.conference.start_date.strftime('%F')
expect(page).to have_text("Scheduled time #{date} #{time} #{event.conference.timezone}")
else
expect(page).to have_no_text('Scheduled')
end
end

def move(event, to:)
draggable = find("#event-#{event.id}.ui-draggable")
droppable = find("#schedule-room-#{to[0].guid}-#{to[1]}-#{to[2]}.ui-droppable")
wait_for_ajax { draggable.drag_to droppable }
end

def remove(event)
button = find("#event-#{event.id} .schedule-event-delete-button")
wait_for_ajax { button.click }
end

feature Schedule do
let(:venue) { create(:venue) }
let(:conference) { create(:conference, venue: venue) }
let!(:room) { create(:room, venue: venue) }
let!(:event) { create(:event, program: conference.program, state: 'confirmed') }

context 'as an organizer' do
let(:organizer) { create(:organizer, resource: conference) }

before :each do
sign_in organizer
end

scenario 'create a schedule', js: true do
expect_scheduled event, nil

visit admin_conference_schedules_path(conference)
click_on 'Add Schedule'
move event, to: [room, 9, 30]
wait_for_ajax { switch conference.short_title, to: true }

expect_scheduled event, '09:30'
end

scenario 'reschedule an event', js: true do
create(:event_schedule, event: event, room: room)
expect_scheduled event, '09:00'

visit admin_conference_schedule_path(conference, conference.program.selected_schedule)
move event, to: [room, 12, 15]

expect_scheduled event, '12:15'
end

scenario 'unschedule an event', js: true do
create(:event_schedule, event: event, room: room)
expect_scheduled event, '09:00'

visit admin_conference_schedule_path(conference, conference.program.selected_schedule)
remove event

expect_scheduled event, nil
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
config.include FactoryBot::Syntax::Methods
config.include OmniauthMacros
config.include Devise::Test::ControllerHelpers, type: :controller
config.include BootstrapMacros, type: :feature
config.include JQueryMacros, type: :feature
config.include LoginMacros, type: :feature
config.include Flash, type: :feature
config.include Sidebar, type: :view
Expand Down
11 changes: 11 additions & 0 deletions spec/support/bootstrap_macros.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module BootstrapMacros
# Interact with Bootstrap Switch
def switch(locator, to:, **options)
checkbox = find(:checkbox, locator, **options, visible: :hidden)

checkbox.ancestor('.bootstrap-switch').click unless checkbox.checked? == to
expect(page).to have_selector(:checkbox, locator, **options, visible: :hidden, checked: to)
end
end
14 changes: 14 additions & 0 deletions spec/support/jquery_macros.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module JQueryMacros
# Wait for one jQuery Ajax request during the block
def wait_for_ajax
flag = "window.ajax_#{SecureRandom.alphanumeric(16)}"
page.execute_script "#{flag} = false; $(document).one('ajaxComplete', () => #{flag} = true);"

yield

Timeout.timeout(Capybara.default_max_wait_time) { loop until page.evaluate_script(flag) }
page.execute_script "delete #{flag};"
end
end
Loading