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

182 lines
4.8 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')
screenshot
end
it "approved" do
lesson = testdrive_lesson(user, teacher, {accept:true, finish:false})
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: 'this lesson is coming up soon')
find('p.lesson-time', "will take place each")
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})
fast_signin(user, "/client#/jamclass/lesson-booking/" + lesson.id)
find('h2', text: "this lesson was missed (teacher)")
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 (teacher)")
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
end