Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-7936 Refactor calendar test to handle multiple selectors for form fields. #3530

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion static/scripts/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ const getCalendarLanguage = (langAttribute) => {
}
};

// Add data-testid attributes to navigation buttons in calendar page as the calendar module
// that is used (https://fullcalendar.io) does not support configuration of data-testids for buttons in used version
UzaeirKhan marked this conversation as resolved.
Show resolved Hide resolved
const addDatatestidsToCalendarNavigation = () => {
UzaeirKhan marked this conversation as resolved.
Show resolved Hide resolved
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');
Expand Down Expand Up @@ -207,6 +227,12 @@ $(document).ready(() => {
viewRender(info) {
window.location.hash = info.view.name;
},

// viewSkeletonRender to trigger the addition of data-testid to navigation buttons
viewSkeletonRender() {
// Add custom data-testids for navigation buttons
addDatatestidsToCalendarNavigation();
},
UzaeirKhan marked this conversation as resolved.
Show resolved Hide resolved
});

calendar.render();
Expand Down Expand Up @@ -304,4 +330,4 @@ $(document).ready(() => {
hideAreaByEvent(event);
}
});
});
});
UzaeirKhan marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions views/calendar/calendar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{{#content "page"}}
<div class="route-calendar">
<div class="fullcalendar" id="calendar"></div>
<div class="fullcalendar" id="calendar" data-testid="calendar"></div>
</div>
{{#userHasPermission "CALENDAR_CREATE"}}
{{#embed
Expand All @@ -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}}
Expand All @@ -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"}}
<button type="button" class="btn btn-primary btn-danger btn-delete" data-testid='calendar-event-btn-delete'>
Expand Down
11 changes: 6 additions & 5 deletions views/calendar/forms/form-create-event.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<input name="scopeId" type="hidden" data-force-value="true" value="{{userId}}" />
<div class="form-group">
<label class="control-label" for="title">{{$t "global.label.title" }}</label>
<input data-testid="team_event_name" class="form-control" name="summary" required placeholder="{{$t "calendar.input.egHandballTraining"}}">
<input data-testid="{{testIdPrefix}}-event-name" class="form-control" name="summary" required placeholder="{{$t "calendar.input.egHandballTraining"}}">
</div>
<div class="form-group">
{{> "lib/forms/form-datetime-input" label=($t "global.label.from") id="startDate" class="input-group" }}
{{> "lib/forms/form-datetime-input" label=($t "global.label.to") id="endDate" class="input-group" }}
{{> "lib/forms/form-datetime-input" label=($t "global.label.from") id="startDate" class="input-group" dataTestId=(concat testIdPrefix "-startDate") }}
{{> "lib/forms/form-datetime-input" label=($t "global.label.to") id="endDate" class="input-group" dataTestId=(concat testIdPrefix "-endDate") }}
</div>
<div class="form-group">
<label class="control-label" for="description">{{$t "global.label.description" }}</label>
<textarea class="form-control" name="description" aria-label="{{$t "global.label.description"}}" placeholder="" data-testid="team_event_description" ></textarea>
<textarea class="form-control" name="description" aria-label="{{$t "global.label.description"}}" placeholder="" data-testid="{{testIdPrefix}}-event-description"></textarea>
</div>
<div class="form-group">
<label class="control-label" for="location">{{$t "calendar.label.location" }}</label>
<input id="location" data-testid="team_event_location" class="form-control" name="location" placeholder="{{$t "calendar.input.egGym"}}">
<input id="location" data-testid="{{testIdPrefix}}-event-location" class="form-control" name="location" placeholder="{{$t "calendar.input.egGym"}}">
</div>

{{#ifConfig "FEATURE_VIDEOCONFERENCE_ENABLED" true}}
{{#if ../showVideoconferenceOption}}
<div class="form-group create-videoconference hidden">
Expand Down
Loading