Skip to content

Commit

Permalink
Test drag-and-drop schedule editor
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKvalheim committed Mar 17, 2024
1 parent cd97bb0 commit 796ff79
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
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)
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

0 comments on commit 796ff79

Please sign in to comment.