-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathPDFReportProgressSnackbar.test.tsx
More file actions
106 lines (94 loc) · 3.07 KB
/
Copy pathPDFReportProgressSnackbar.test.tsx
File metadata and controls
106 lines (94 loc) · 3.07 KB
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* PDFReportProgressSnackbar component tests.
*
* Site Kit by Google, Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies
*/
import { fireEvent } from '@testing-library/react';
import type { MouseEvent } from 'react';
/**
* Internal dependencies
*/
import PDFReportProgressSnackbar from './PDFReportProgressSnackbar';
import { render } from '../../../../tests/js/test-utils';
describe( 'PDFReportProgressSnackbar', () => {
it( 'renders default title, description, and Cancel label', () => {
const { getByText, getByRole } = render(
<PDFReportProgressSnackbar onCancel={ () => {} } />
);
expect(
getByText( /Generating your PDF report/i )
).toBeInTheDocument();
expect(
getByText(
/Please keep this tab open until the download starts automatically/i
)
).toBeInTheDocument();
expect(
getByRole( 'button', { name: /cancel/i } )
).toBeInTheDocument();
} );
it( 'renders custom title, description, and cancelLabel when provided', () => {
const { getByText, getByRole, queryByText } = render(
<PDFReportProgressSnackbar
onCancel={ () => {} }
title="Custom title"
description="Custom description"
cancelLabel="Stop"
/>
);
expect( getByText( 'Custom title' ) ).toBeInTheDocument();
expect( getByText( 'Custom description' ) ).toBeInTheDocument();
expect( getByRole( 'button', { name: /stop/i } ) ).toBeInTheDocument();
expect(
queryByText( /Generating your PDF report/i )
).not.toBeInTheDocument();
} );
it( 'renders a progressbar that updates from the progress prop', () => {
const { getByRole, rerender } = render(
<PDFReportProgressSnackbar
onCancel={ () => {} }
progress={ 0.25 }
/>
);
const progressbar = getByRole( 'progressbar' );
expect( progressbar ).toBeInTheDocument();
expect(
progressbar.querySelector( '.mdc-linear-progress__primary-bar' )
).toHaveStyle( { width: '25%', transform: 'none' } );
rerender(
<PDFReportProgressSnackbar
onCancel={ () => {} }
progress={ 0.75 }
/>
);
expect(
progressbar.querySelector( '.mdc-linear-progress__primary-bar' )
).toHaveStyle( { width: '75%', transform: 'none' } );
} );
it( 'calls onCancel when the Cancel button is clicked', () => {
const onCancel = jest.fn(
( event: MouseEvent< HTMLAnchorElement | HTMLButtonElement > ) =>
event.preventDefault()
);
const { getByRole } = render(
<PDFReportProgressSnackbar onCancel={ onCancel } />
);
fireEvent.click( getByRole( 'button', { name: /cancel/i } ) );
expect( onCancel ).toHaveBeenCalledTimes( 1 );
} );
} );