diff --git a/app/coffeescripts/calendar/EventDataSource.js b/app/coffeescripts/calendar/EventDataSource.js index c1313457bf2..9db7dc3c52d 100644 --- a/app/coffeescripts/calendar/EventDataSource.js +++ b/app/coffeescripts/calendar/EventDataSource.js @@ -495,23 +495,21 @@ export default class EventDataSource { if (ENV.STUDENT_PLANNER_ENABLED) { eventDataSources.push(['/api/v1/planner_notes', params]) } - if (ENV.CALENDAR && ENV.CALENDAR.MANAGE_CONTEXTS) { - const [admin_contexts, student_contexts] = _.partition( - params.context_codes, - cc => ENV.CALENDAR.MANAGE_CONTEXTS.indexOf(cc) >= 0 - ) - if (student_contexts.length) { - const pparams = {filter: 'ungraded_todo_items', ...params, context_codes: student_contexts} - eventDataSources.push(['/api/v1/planner/items', pparams]) - } - if (admin_contexts.length) { - const pparams = { - filter: 'all_ungraded_todo_items', - ...params, - context_codes: admin_contexts - } - eventDataSources.push(['/api/v1/planner/items', pparams]) + const [admin_contexts, student_contexts] = _.partition( + params.context_codes, + cc => ENV.CALENDAR?.MANAGE_CONTEXTS?.indexOf(cc) >= 0 + ) + if (student_contexts.length) { + const pparams = {filter: 'ungraded_todo_items', ...params, context_codes: student_contexts} + eventDataSources.push(['/api/v1/planner/items', pparams]) + } + if (admin_contexts.length) { + const pparams = { + filter: 'all_ungraded_todo_items', + ...params, + context_codes: admin_contexts } + eventDataSources.push(['/api/v1/planner/items', pparams]) } return this.startFetch(eventDataSources, dataCB, doneCB, options) } diff --git a/spec/coffeescripts/calendar/AgendaViewSpec.js b/spec/coffeescripts/calendar/AgendaViewSpec.js index 00287a230d2..146f50472dd 100644 --- a/spec/coffeescripts/calendar/AgendaViewSpec.js +++ b/spec/coffeescripts/calendar/AgendaViewSpec.js @@ -24,18 +24,19 @@ import denver from 'timezone/America/Denver' import juneau from 'timezone/America/Juneau' import french from 'timezone/fr_FR' import AgendaView from 'compiled/views/calendar/AgendaView' -import Calendar from 'compiled/calendar/Calendar' import EventDataSource from 'compiled/calendar/EventDataSource' import eventResponse from 'helpers/ajax_mocks/api/v1/calendarEvents' +import plannerItemsResponse from 'helpers/ajax_mocks/api/planner/items' import assignmentResponse from 'helpers/ajax_mocks/api/v1/calendarAssignments' import I18nStubber from 'helpers/I18nStubber' import fakeENV from 'helpers/fakeENV' const loadEventPage = (server, includeNext = false) => - sendCustomEvents(server, eventResponse, assignmentResponse, includeNext) -var sendCustomEvents = function(server, events, assignments, includeNext = false) { - const requestIndex = server.requests.length - 2 - server.requests[requestIndex].respond( + sendCustomEvents(server, eventResponse, assignmentResponse, plannerItemsResponse, includeNext) +const sendCustomEvents = function(server, events, assignments, plannerItems, includeNext = false) { + const requestIndex = server.requests.length - 3 + server.requests[requestIndex].respond(200, {'Content-Type': 'application/json'}, plannerItems) + server.requests[requestIndex + 1].respond( 200, { 'Content-Type': 'application/json', @@ -43,7 +44,7 @@ var sendCustomEvents = function(server, events, assignments, includeNext = false }, events ) - return server.requests[requestIndex + 1].respond( + return server.requests[requestIndex + 2].respond( 200, {'Content-Type': 'application/json'}, assignments @@ -151,7 +152,13 @@ test('should only include days on page breaks once', function() { date.setFullYear(date.getFullYear() + 1) addEvents(events, date) } - sendCustomEvents(this.server, JSON.stringify(events), JSON.stringify([]), true) + sendCustomEvents( + this.server, + JSON.stringify(events), + JSON.stringify([]), + JSON.stringify([]), + true + ) ok( this.container.find('.agenda-event__item-container').length, 40, @@ -164,7 +171,13 @@ test('should only include days on page breaks once', function() { addEvents(events, date) date.setFullYear(date.getFullYear() + 1) } - sendCustomEvents(this.server, JSON.stringify(events), JSON.stringify([]), false) + sendCustomEvents( + this.server, + JSON.stringify(events), + JSON.stringify([]), + JSON.stringify([]), + false + ) equal( this.container.find('.agenda-event__item-container').length, 70, diff --git a/spec/coffeescripts/helpers/ajax_mocks/api/planner/items.js b/spec/coffeescripts/helpers/ajax_mocks/api/planner/items.js new file mode 100644 index 00000000000..c547834b41a --- /dev/null +++ b/spec/coffeescripts/helpers/ajax_mocks/api/planner/items.js @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2013 - present Instructure, Inc. + * + * This file is part of Canvas. + * + * Canvas is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, version 3 of the License. + * + * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License along + * with this program. If not, see . + */ + +export default `[]`