import { getActiveLibraries, getActiveUrls } from 'src/utils/widgets';

describe('widgets utils', () => {
  test('getActiveUrls returns empty array for non-array inputs', () => {
    expect(getActiveUrls(undefined)).toEqual([]);
    expect(getActiveUrls(null)).toEqual([]);
    expect(getActiveUrls({})).toEqual([]);
    expect(getActiveUrls('not-an-array')).toEqual([]);
    expect(getActiveLibraries({})).toEqual([]);
  });

  test('getActiveUrls returns only active URL widgets', () => {
    const widgets = [
      { id: 1, type: 'URL', active: true, title: 'A' },
      { id: 2, type: 'URL', active: false, title: 'B' },
      { id: 3, type: 'KNOWLEDGE_LIBRARY', active: true, title: 'C' },
      null,
    ] as any;

    expect(getActiveUrls(widgets)).toEqual([
      { id: 1, type: 'URL', active: true, title: 'A' },
    ]);
  });

  test('getActiveLibraries returns only active knowledge library widgets', () => {
    const widgets = [
      { id: 1, type: 'URL', active: true, title: 'A' },
      { id: 2, type: 'KNOWLEDGE_LIBRARY', active: true, title: 'B' },
      { id: 3, type: 'KNOWLEDGE_LIBRARY', active: false, title: 'C' },
      123,
    ] as any;

    expect(getActiveLibraries(widgets)).toEqual([
      { id: 2, type: 'KNOWLEDGE_LIBRARY', active: true, title: 'B' },
    ]);
  });
});
