jam-cloud/web/spec/features/lesson_booking_status_spec.rb

278 lines
8.5 KiB
Ruby

require 'spec_helper'
describe "Lesson Booking Status page", :js => true, :type => :feature, :capybara_feature => true do
subject { page }
let(:user) { FactoryGirl.create(:user) }
let(:teacher) { FactoryGirl.create(:teacher_user) }
after(:each) do
Timecop.return
end
def screenshot
if ENV['SCREENSHOT'] == '1'
screenshot_and_save_page
end
end
describe "student" do
it "requested" do
lesson = testdrive_lesson(user, teacher, {accept:false, finish:false})
lesson.lesson_booking.status.should eql LessonBooking::STATUS_REQUESTED
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'your lesson has been requested')
find('p.proposing-new-time')
screenshot
end
it "approved" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false})
lesson.reload
lesson.status.should
lesson.lesson_booking.accepter_id.should_not be_nil
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id )
find('h2', text: 'this lesson is coming up soon')
find('p.generic-time-stmt')
screenshot
end
it "now" do
pending "sinon needed to fake time"
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false})
Timecop.travel(lesson.scheduled_start + 1)
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'the lesson is scheduled for right now!')
screenshot
end
it "successful" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:true})
# travel to after the lesson is over
Timecop.travel(lesson.scheduled_start + (lesson.duration * 60) + 1)
lesson.reload
lesson.success.should be_true
lesson.status.should eql LessonSession::STATUS_COMPLETED
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'this lesson is over')
screenshot
end
it "canceled" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false, cancel: true})
lesson.reload
lesson.status.should eql LessonSession::STATUS_CANCELED
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: "this lesson was canceled (student)")
screenshot
end
it "missed" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false, miss: true})
lesson.reload
lesson.status.should eql LessonSession::STATUS_COMPLETED
lesson.success.should be_false
lesson.student_missed.should be_true
lesson.teacher_missed.should be_true
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: "this lesson was missed (both)")
screenshot
end
end
describe "teacher" do
it "requested" do
lesson = testdrive_lesson(user, teacher, {accept:false, finish:false})
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'respond to lesson request')
screenshot
end
it "approved" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false})
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'this lesson is coming up soon')
screenshot
end
it "now" do
pending "sinon needed to fake time"
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false})
Timecop.travel(lesson.scheduled_start + 1)
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'the lesson is scheduled for right now!')
screenshot
end
it "successful" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:true})
# travel to after the lesson is over
Timecop.travel(lesson.scheduled_start + (lesson.duration * 60) + 1)
lesson.success.should be_true
lesson.status.should eql LessonSession::STATUS_COMPLETED
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'this lesson is over')
screenshot
end
it "canceled" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false, cancel: true})
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: "this lesson was canceled (student)")
screenshot
end
it "missed" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false, miss: true})
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: "this lesson was missed (both)")
screenshot
end
end
it "pretty US timezone" do
slots = []
slots << FactoryGirl.build(:lesson_booking_slot_single, timezone: 'America/Chicago')
slots << FactoryGirl.build(:lesson_booking_slot_single, timezone: 'America/Chicago')
lesson = testdrive_lesson(user, teacher, {accept:false, finish:false, slots:slots})
fast_signin(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('#lesson-booking', text: 'US Central Time')
end
it "requested recurring with focused lesson" do
lesson = monthly_lesson(user, teacher, {accept: false})
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('.request-sent', text: 'Your request has been sent.')
page.should_not have_selector('p.proposing-new-time')
# the teacher can either accept or propose a new time, so they see both
switch_user(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('p.action', text: 'Has requested')
page.should_not have_selector('p.generic-time-stmt')
find(".slot-decision-field[data-slot-id=\"#{lesson.lesson_booking.default_slot.id}\"] ins", visible: false).trigger(:click)
find('.schedule.button-orange').trigger(:click)
find('tr[data-lesson-session-id="' + lesson.id + '"] td.displayStatusColumn', text: 'Scheduled')
end
it "requested recurring with unfocused lesson" do
lesson = monthly_lesson(user, teacher, {accept: false})
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.lesson_booking.id)
find('.request-sent', text: 'Your request has been sent.')
page.should_not have_selector('p.proposing-new-time')
switch_user(teacher, "/client#/jamclass/lesson-booking/" + lesson.id)
find('p.action', text: 'Has requested')
page.should_not have_selector('p.generic-time-stmt')
find(".slot-decision-field[data-slot-id=\"#{lesson.lesson_booking.default_slot.id}\"] ins", visible: false).trigger(:click)
find('.schedule.button-orange').trigger(:click)
find('tr[data-lesson-session-id="' + lesson.id + '"] td.displayStatusColumn', text: 'Scheduled')
end
it "accepted recurring with focused lesson" do
lesson = monthly_lesson(user, teacher, {accept: true})
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id + "_rescheduling")
find('p.proposing-new-time')
# the teacher can either accept or propose a new time, so they see both
switch_user(teacher, "/client#/jamclass/lesson-booking/" + lesson.id + "_rescheduling")
find('p.proposing-new-time')
# change the lesson time
fill_in "alt-date-input", with: date_picker_format(Date.new(Date.today.year, Date.today.month + 1, 17))
find('td a', text: '17').trigger(:click)
sleep 3
find('.schedule.button-orange').trigger(:click)
find('#banner h1', text: 'Lesson Change Requested')
find('#banner .close-btn').trigger(:click)
find('tr[data-lesson-session-id="' + lesson.id + '"] td.displayStatusColumn', text: 'Requested')
switch_user(user, "/client#/jamclass")
end
it "accepted recurring with unfocused lesson" do
lesson = monthly_lesson(user, teacher, {accept: true})
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.lesson_booking.id + "_rescheduling")
find('.request-sent', text: 'Your request has been sent.')
page.should_not have_selector('p.proposing-new-time')
switch_user(teacher, "/client#/jamclass/lesson-booking/" + lesson.lesson_booking.id + "_rescheduling")
find('p.proposing-new-time')
fill_in "alt-date-input", with: date_picker_format(Date.new(Date.today.year, Date.today.month + 1, 17))
find('td a', text: '17').trigger(:click)
sleep 3
find(".slot-decision-field[data-slot-id=\"#{lesson.lesson_booking.default_slot.id}\"] ins", visible: false).trigger(:click)
find('.schedule.button-orange').trigger(:click)
find('tr[data-lesson-session-id="' + lesson.id + '"] td.displayStatusColumn', text: 'Scheduled')
end
end