import { describe, expect, it } from 'vitest';

import { findActiveFilterElement } from './active-filter-scroll';

describe('findActiveFilterElement', () => {
  it('returns the newest matching repeated filter card', () => {
    const root = document.createElement('div');
    root.innerHTML = `
      <div data-filter-name="Schools" data-card="first"></div>
      <div data-filter-name="price" data-card="price"></div>
      <div data-filter-name="Schools" data-card="latest"></div>
    `;

    expect(findActiveFilterElement(root, 'Schools')?.dataset.card).toBe('latest');
  });

  it('matches filter names with selector-special characters', () => {
    const root = document.createElement('div');
    root.innerHTML = '<div data-filter-name="Political vote share:%25%20Labour:1"></div>';

    expect(findActiveFilterElement(root, 'Political vote share:%25%20Labour:1')).not.toBeNull();
  });
});
