aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/widgets/social-media.test.tsx
blob: ead29d9313964f0ab5e8a401a1da22269b922757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, expect, it } from '@jest/globals';
import { render, screen as rtlScreen } from '../../../../tests/utils';
import { SocialMedia, type Media } from './social-media';
import { Heading } from 'src/components/atoms';

const media: Media[] = [
  { icon: 'Github', id: 'github', label: 'Github', url: '#' },
  { icon: 'LinkedIn', id: 'gitlab', label: 'Gitlab', url: '#' },
];
const title = 'Dolores ut ut';
const titleLevel = 2;

/**
 * Next.js mock images with next/image component. So for now, I need to mock
 * the svg files manually.
 */
jest.mock('@assets/images/social-media/github.svg', () => 'svg-file');
jest.mock('@assets/images/social-media/gitlab.svg', () => 'svg-file');
jest.mock('@assets/images/social-media/linkedin.svg', () => 'svg-file');
jest.mock('@assets/images/social-media/twitter.svg', () => 'svg-file');

describe('SocialMedia', () => {
  it('renders the widget title', () => {
    render(
      <SocialMedia
        heading={<Heading level={titleLevel}>{title}</Heading>}
        media={media}
      />
    );
    expect(
      rtlScreen.getByRole('heading', {
        level: titleLevel,
        name: new RegExp(title, 'i'),
      })
    ).toBeInTheDocument();
  });

  it('renders the correct number of items', () => {
    render(
      <SocialMedia
        heading={<Heading level={titleLevel}>{title}</Heading>}
        media={media}
      />
    );
    expect(rtlScreen.getAllByRole('listitem')).toHaveLength(media.length);
  });
});