2021-04-24 19:30:52 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe FullCalendarFormatter do
|
|
|
|
|
let!(:room1) { create(:room) }
|
2021-04-26 09:48:16 +08:00
|
|
|
let!(:room2) { create(:room) }
|
2021-04-26 10:34:14 +08:00
|
|
|
let!(:rooms) { [room1, room2] }
|
2021-04-30 15:14:46 +08:00
|
|
|
let!(:conference) { create(:full_conference) }
|
|
|
|
|
let!(:program) { conference.program }
|
|
|
|
|
let!(:selected_schedule) { create(:schedule, program: program) }
|
|
|
|
|
let!(:event_type1) { create(:event_type, color: '#ffffff') }
|
|
|
|
|
let!(:event1) do
|
|
|
|
|
program.update_attributes!(selected_schedule: selected_schedule)
|
|
|
|
|
create(:event, program: program, event_type: event_type1)
|
|
|
|
|
end
|
|
|
|
|
let!(:event_schedule1) { create(:event_schedule, event: event1, schedule: selected_schedule, room: room1) }
|
|
|
|
|
let!(:event_type2) { create(:event_type, color: '#000000') }
|
|
|
|
|
let!(:event2) do
|
|
|
|
|
program.update_attributes!(selected_schedule: selected_schedule)
|
|
|
|
|
create(:event, program: program, room: room2, event_type: event_type2)
|
|
|
|
|
end
|
|
|
|
|
let!(:event_schedule2) { create(:event_schedule, event: event2, schedule: selected_schedule, room: room2) }
|
2021-04-26 10:34:14 +08:00
|
|
|
let!(:event_schedules) { [event_schedule1, event_schedule2] }
|
2021-04-24 19:30:52 -07:00
|
|
|
|
|
|
|
|
describe 'JSON formatting for FullCalendar' do
|
|
|
|
|
it 'translates rooms to resources' do
|
2021-04-26 09:48:16 +08:00
|
|
|
resources = described_class.rooms_to_resources(rooms)
|
|
|
|
|
expected_json = [
|
|
|
|
|
{
|
|
|
|
|
id: room1.guid,
|
|
|
|
|
title: room1.name
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: room2.guid,
|
|
|
|
|
title: room2.name
|
|
|
|
|
}
|
|
|
|
|
].to_json
|
|
|
|
|
expect(resources).to eq(expected_json)
|
2021-04-24 19:30:52 -07:00
|
|
|
end
|
2021-04-26 10:34:14 +08:00
|
|
|
|
|
|
|
|
it 'translates event schedules to resources' do
|
|
|
|
|
resources = described_class.event_schedules_to_resources(event_schedules)
|
|
|
|
|
expected_json = [
|
|
|
|
|
{
|
2021-04-30 15:14:46 +08:00
|
|
|
id: event_schedule1.event.guid,
|
|
|
|
|
title: event_schedule1.event.title,
|
|
|
|
|
start: event_schedule1.start_time,
|
|
|
|
|
end: event_schedule1.end_time,
|
|
|
|
|
resourceId: room1.guid,
|
2021-04-30 16:20:49 +08:00
|
|
|
url: Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event1.id),
|
2021-04-30 15:14:46 +08:00
|
|
|
backgroundColor: event1.event_type.color,
|
|
|
|
|
textColor: 'black'
|
2021-04-26 10:34:14 +08:00
|
|
|
},
|
|
|
|
|
{
|
2021-04-30 15:14:46 +08:00
|
|
|
id: event_schedule2.event.guid,
|
|
|
|
|
title: event_schedule2.event.title,
|
|
|
|
|
start: event_schedule2.start_time,
|
|
|
|
|
end: event_schedule2.end_time,
|
|
|
|
|
resourceId: room2.guid,
|
2021-04-30 16:20:49 +08:00
|
|
|
url: Rails.application.routes.url_helpers.conference_program_proposal_path(conference.short_title, event2.id),
|
2021-04-30 15:14:46 +08:00
|
|
|
backgroundColor: event2.event_type.color,
|
|
|
|
|
textColor: 'white'
|
2021-04-26 10:34:14 +08:00
|
|
|
}
|
|
|
|
|
].to_json
|
2021-04-30 16:48:15 +08:00
|
|
|
|
2021-04-26 10:34:14 +08:00
|
|
|
expect(resources).to eq(expected_json)
|
|
|
|
|
end
|
2021-04-24 19:30:52 -07:00
|
|
|
end
|
|
|
|
|
end
|