diff --git a/static/scripts/calendar.js b/static/scripts/calendar.js index 0e13017177..cafbb23503 100644 --- a/static/scripts/calendar.js +++ b/static/scripts/calendar.js @@ -49,6 +49,27 @@ const getCalendarLanguage = (langAttribute) => { } }; +// Add data-testid attributes to navigation buttons in calendar page +// as the calendar module used (https://fullcalendar.io, version 4.4.2) +// does not natively support configuring data-testids for buttons. +const addDataTestIdsToCalendarNavigation = () => { + const buttonData = [ + { selector: '.fc-right .fc-prev-button', testId: 'right-prev-button' }, + { selector: '.fc-right .fc-next-button', testId: 'right-next-button' }, + { selector: '.fc-right .fc-today-button', testId: 'right-today-button' }, + { selector: '.fc-right .fc-timeGridDay-button', testId: 'right-day-view-button' }, + { selector: '.fc-right .fc-timeGridWeek-button', testId: 'right-week-view-button' }, + { selector: '.fc-right .fc-dayGridMonth-button', testId: 'right-month-view-button' }, + ]; + + buttonData.forEach(({ selector, testId }) => { + const button = document.querySelector(selector); + if (button) { + button.dataset.testid = testId; + } + }); +}; + $(document).ready(() => { const $createEventModal = $('.create-event-modal'); const $editEventModal = $('.edit-event-modal'); @@ -207,6 +228,10 @@ $(document).ready(() => { viewRender(info) { window.location.hash = info.view.name; }, + + viewSkeletonRender() { + addDataTestIdsToCalendarNavigation(); + }, }); calendar.render(); diff --git a/views/calendar/calendar.hbs b/views/calendar/calendar.hbs index 351851a624..4f3369e149 100644 --- a/views/calendar/calendar.hbs +++ b/views/calendar/calendar.hbs @@ -13,7 +13,7 @@ {{#content "page"}}
-
+
{{#userHasPermission "CALENDAR_CREATE"}} {{#embed @@ -27,7 +27,7 @@ currentTimezoneOffset=../currentTimezoneOffset }} {{#content "fields"}} - {{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="2" collapseIdTeam="3"}} + {{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="2" collapseIdTeam="3" testIdPrefix="create"}} {{/content}} {{/embed}} {{/userHasPermission}} @@ -42,7 +42,7 @@ currentTimezoneOffset=../currentTimezoneOffset }} {{#content "fields"}} - {{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="4" collapseIdTeam="5"}} + {{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="4" collapseIdTeam="5" testIdPrefix="edit"}} {{/content}} {{#content "additional-actions"}}