I'm currently working on an Angular component where I have a method that involves scrolling through a list of elements known as "cards" based on certain criteria. Despite my efforts to write unit tests for this method using the Jasmine framework, I've been struggling to make it work. Any suggestions or advice would be greatly appreciated!
Here's the code snippet of the method in question:
scrollToCard() {
const scrollSlotToMatch = '10:00 - 11:00';
// Querying the DOM to select specific schedule card view elements for scrolling into view
const matches = Array.from(document.querySelectorAll('test-card'));
// Iterating through the card elements to identify the desired one matching the target scroll time
let selectedCard: HTMLElement | undefined;
for (let i = 0; i < matches.length; i++) {
const card = matches[i] as HTMLElement;
const cardInnerText = card.innerText.split('\n');
if (cardInnerText[0] === scrollSlotToMatch) {
selectedCard = card;
break;
}
}
// Scroll the located card element into view if found
if (selectedCard !== undefined) {
selectedCard.scrollIntoView();
}
}