aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-bison.min.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/prism/prism-bison.min.js')
0 files changed, 0 insertions, 0 deletions
#n48'>48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
import { describe, expect, it } from '@jest/globals';
import { render, screen as rtlScreen } from '@testing-library/react';
import { Heading } from '../../../atoms';
import { LinksWidget, type LinksWidgetItemData } from './links-widget';

describe('LinksWidget', () => {
  it('renders the widget heading and a list of links', () => {
    const heading = 'modi sit fugiat';
    const headingLvl = 3;
    const items = [
      { id: 'item1', label: 'Link 1', url: '#link1' },
      { id: 'item2', label: 'Link 2', url: '#link2' },
      { id: 'item3', label: 'Link 3', url: '#link3' },
    ] satisfies LinksWidgetItemData[];

    render(
      <LinksWidget
        heading={<Heading level={headingLvl}>{heading}</Heading>}
        items={items}
      />
    );

    expect(
      rtlScreen.getByRole('heading', { level: headingLvl })
    ).toHaveTextContent(heading);
    expect(rtlScreen.getAllByRole('link').length).toBe(items.length);
  });

  it('can render a nested list of links', () => {
    const heading = 'modi sit fugiat';
    const headingLvl = 3;
    const items = [
      { id: 'item1', label: 'Link 1', url: '#link1' },
      {
        id: 'item2',
        label: 'Link 2',
        url: '#link2',
        child: [
          { id: 'subitem1', label: 'Nested link 1', url: '#nested-link1' },
          { id: 'subitem2', label: 'Nested link 2', url: '#nested-link2' },
        ],
      },
      { id: 'item3', label: 'Link 3', url: '#link3' },
    ] satisfies LinksWidgetItemData[];

    render(
      <LinksWidget
        heading={<Heading level={headingLvl}>{heading}</Heading>}
        items={items}
      />
    );

    const totalLinks =
      items.length +
      items.reduce(
        (accumulator, currentValue) =>
          accumulator + (currentValue.child?.length ?? 0),
        0
      );

    expect(rtlScreen.getAllByRole('link').length).toBe(totalLinks);
  });

  it('can render an ordered list of links', () => {
    const heading = 'modi sit fugiat';
    const headingLvl = 3;
    const items = [
      { id: 'item1', label: 'Link 1', url: '#link1' },
      { id: 'item2', label: 'Link 2', url: '#link2' },
      { id: 'item3', label: 'Link 3', url: '#link3' },
    ] satisfies LinksWidgetItemData[];

    render(
      <LinksWidget
        heading={<Heading level={headingLvl}>{heading}</Heading>}
        isOrdered
        items={items}
      />
    );

    expect(rtlScreen.getByRole('list')).toHaveClass(`list--ordered`);
  });
});