Add JS tests to verify school and district dropdowns.

This commit is contained in:
rebuilt 2021-10-08 22:56:37 +02:00
parent 2d4ba042f9
commit 6320d5633f
12 changed files with 219 additions and 74 deletions

View file

@ -1,9 +1,12 @@
document.addEventListener("DOMContentLoaded", function() {
document.querySelector('#select-school').addEventListener('change', (event) => {
window.location = event.target.value;
});
document.addEventListener("turbolinks:load", function() {
const schoolDropdown = document.querySelector('#select-school');
if (schoolDropdown) {
document.querySelector('#select-school').addEventListener('change', (event) => {
window.location = event.target.value;
});
document.querySelector('#select-district').addEventListener('change', (event) => {
window.location = event.target.value;
});
document.querySelector('#select-district').addEventListener('change', (event) => {
window.location = event.target.value;
});
}
});

View file

@ -0,0 +1,25 @@
document.addEventListener('DOMContentLoaded', () => {
const districtDropdown = document.querySelector('#district-dropdown');
if (districtDropdown) {
districtDropdown.addEventListener('change', event => {
const schoolDropdown = document.querySelector('#school-dropdown');
const districtId = Number(event.target.value);
const schoolsInDistrict = window.schools.filter(school => school.district_id === districtId);
schoolsInDistrict.forEach(school => {
const optionElem = document.createElement('option');
optionElem.setAttribute('value', school.url);
const schoolNameNode = document.createTextNode(school.name);
optionElem.appendChild(schoolNameNode);
schoolDropdown.appendChild(optionElem);
});
});
document.querySelector('button[data-id="go-to-school"]').addEventListener('click', event => {
const selectedSchoolURL = document.querySelector('#school-dropdown').value;
window.location = selectedSchoolURL;
});
}
});