mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Test drag-and-drop schedule editor
This commit is contained in:
parent
6e276b2787
commit
163b12a804
4 changed files with 97 additions and 0 deletions
70
spec/features/schedule_spec.rb
Normal file
70
spec/features/schedule_spec.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -92,6 +92,8 @@ RSpec.configure do |config|
|
|||
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 Sidebar, type: :view
|
||||
config.include Devise::Test::ControllerHelpers, type: :view
|
||||
|
|
|
|||
11
spec/support/bootstrap_macros.rb
Normal file
11
spec/support/bootstrap_macros.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module BootstrapMacros
|
||||
# Interact with Bootstrap Switch
|
||||
def switch(locator, to:, **)
|
||||
checkbox = find(:checkbox, locator, **, visible: :hidden)
|
||||
|
||||
checkbox.ancestor('.bootstrap-switch').click unless checkbox.checked? == to
|
||||
expect(page).to have_selector(:checkbox, locator, **, visible: :hidden, checked: to)
|
||||
end
|
||||
end
|
||||
14
spec/support/jquery_macros.rb
Normal file
14
spec/support/jquery_macros.rb
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue