File size: 1,803 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
/**
 * @jest-environment jsdom
 */
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import '@testing-library/user-event';
import * as React from 'react';
import SummaryButton from '../index';

describe( 'SummaryButton', () => {
	test( 'should render a button element by default', () => {
		render( <SummaryButton title="Test Title" /> );
		expect(
			screen.getByRole( 'button', {
				name: 'Test Title',
			} )
		).toBeVisible();
	} );
	test( 'should render an anchor element when href is provided', () => {
		render( <SummaryButton title="Test Title" href="/test-link" /> );
		const anchors = screen.getAllByRole( 'link' );
		expect( anchors.length ).toBe( 1 );
		expect( anchors[ 0 ] ).toHaveAttribute( 'href', '/test-link' );
	} );
	test( 'should render a button element when disabled and href is provided', () => {
		render( <SummaryButton title="Test Title" href="/test-link" disabled /> );
		expect( screen.getByRole( 'button' ) ).toBeVisible();
		expect( screen.queryByRole( 'link' ) ).toBeNull();
	} );
	test( 'should render description and strapline when provided in low density mode', () => {
		render(
			<SummaryButton
				title="Test Title"
				description="Test Description"
				strapline="Test Strapline"
				density="low"
			/>
		);
		expect( screen.getByText( 'Test Description' ) ).toBeVisible();
		expect( screen.getByText( 'Test Strapline' ) ).toBeVisible();
	} );
	test( 'should not render description and strapline in medium density mode', () => {
		render(
			<SummaryButton
				title="Test Title"
				description="Test Description"
				strapline="Test Strapline"
				density="medium"
			/>
		);
		expect( screen.queryByText( 'Test Description' ) ).toBeNull();
		expect( screen.queryByText( 'Test Strapline' ) ).toBeNull();
	} );
} );