PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
jetpack / _inc / shared / components / ai-banner / test / component.jsx

component.jsx in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at _inc/shared/components/ai-banner/test/component.jsx

45 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { render, screen } from '@testing-library/react';
2 import userEvent from '@testing-library/user-event';
3 import AiBanner from '../index';
4
5 const noop = () => {};
6
7 describe( 'AiBanner', () => {
8 test( 'renders title, description, and actions', () => {
9 render(
10 <AiBanner
11 title="Banner title"
12 description="Banner description"
13 actions={ <button type="button">Do it</button> }
14 onDismiss={ noop }
15 />
16 );
17
18 expect( screen.getByRole( 'heading', { name: 'Banner title' } ) ).toBeInTheDocument();
19 expect( screen.getByText( 'Banner description' ) ).toBeInTheDocument();
20 expect( screen.getByRole( 'button', { name: 'Do it' } ) ).toBeInTheDocument();
21 } );
22
23 test( 'renders only the close X when no actions are given', () => {
24 render( <AiBanner title="Banner title" description="Banner description" onDismiss={ noop } /> );
25
26 expect( screen.getAllByRole( 'button' ) ).toHaveLength( 1 );
27 expect( screen.getByRole( 'button', { name: 'Dismiss banner' } ) ).toBeInTheDocument();
28 } );
29
30 test( 'close X calls onDismiss and takes a custom label', async () => {
31 const onDismiss = jest.fn();
32 render(
33 <AiBanner
34 title="Banner title"
35 description="Banner description"
36 onDismiss={ onDismiss }
37 dismissLabel="Hide this"
38 />
39 );
40
41 await userEvent.click( screen.getByRole( 'button', { name: 'Hide this' } ) );
42 expect( onDismiss ).toHaveBeenCalledTimes( 1 );
43 } );
44 } );
45