|
| 1 | +/** |
| 2 | + * EmailReportingErrorNotice component tests. |
| 3 | + * |
| 4 | + * Site Kit by Google, Copyright 2026 Google LLC |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * Internal dependencies |
| 21 | + */ |
| 22 | + |
| 23 | +import EmailReportingErrorNotice from './EmailReportingErrorNotice'; |
| 24 | +import { |
| 25 | + render, |
| 26 | + createTestRegistry, |
| 27 | + provideUserAuthentication, |
| 28 | +} from '../../../../../tests/js/test-utils'; |
| 29 | +import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants'; |
| 30 | +import * as tracking from '@/js/util/tracking'; |
| 31 | +import { VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY } from '@/js/googlesitekit/constants'; |
| 32 | + |
| 33 | +const mockTrackEvent = jest.spyOn( tracking, 'trackEvent' ); |
| 34 | +mockTrackEvent.mockImplementation( () => Promise.resolve() ); |
| 35 | + |
| 36 | +describe( 'EmailReportingErrorNotice', () => { |
| 37 | + let registry; |
| 38 | + |
| 39 | + beforeEach( () => { |
| 40 | + registry = createTestRegistry(); |
| 41 | + provideUserAuthentication( registry ); |
| 42 | + mockTrackEvent.mockClear(); |
| 43 | + } ); |
| 44 | + |
| 45 | + it( 'should render the error notice when email reporting is enabled, user is not view-only, and there are errors', () => { |
| 46 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingSettings( { |
| 47 | + enabled: true, |
| 48 | + } ); |
| 49 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingErrors( { |
| 50 | + errors: [ { code: 'test_error' } ], |
| 51 | + errorData: [], |
| 52 | + } ); |
| 53 | + |
| 54 | + const { container, getByText } = render( |
| 55 | + <EmailReportingErrorNotice />, |
| 56 | + { |
| 57 | + registry, |
| 58 | + } |
| 59 | + ); |
| 60 | + |
| 61 | + expect( container ).not.toBeEmptyDOMElement(); |
| 62 | + expect( getByText( 'Email reports are paused' ) ).toBeInTheDocument(); |
| 63 | + expect( |
| 64 | + getByText( |
| 65 | + 'We were unable to deliver your report. Report delivery will automatically resume once the issue is resolved.' |
| 66 | + ) |
| 67 | + ).toBeInTheDocument(); |
| 68 | + } ); |
| 69 | + |
| 70 | + it( 'should not render when email reporting is not enabled', () => { |
| 71 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingSettings( { |
| 72 | + enabled: false, |
| 73 | + } ); |
| 74 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingErrors( { |
| 75 | + errors: [ { code: 'test_error' } ], |
| 76 | + errorData: [], |
| 77 | + } ); |
| 78 | + |
| 79 | + const { container } = render( <EmailReportingErrorNotice />, { |
| 80 | + registry, |
| 81 | + } ); |
| 82 | + |
| 83 | + expect( container ).toBeEmptyDOMElement(); |
| 84 | + } ); |
| 85 | + |
| 86 | + it( 'should not render when dashboard context is view-only', () => { |
| 87 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingSettings( { |
| 88 | + enabled: true, |
| 89 | + } ); |
| 90 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingErrors( { |
| 91 | + errors: [ { code: 'test_error' } ], |
| 92 | + errorData: [], |
| 93 | + } ); |
| 94 | + |
| 95 | + const { container } = render( <EmailReportingErrorNotice />, { |
| 96 | + registry, |
| 97 | + viewContext: VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY, |
| 98 | + } ); |
| 99 | + expect( container ).toBeEmptyDOMElement(); |
| 100 | + } ); |
| 101 | + |
| 102 | + it( 'should not render when there are no errors', () => { |
| 103 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingSettings( { |
| 104 | + enabled: true, |
| 105 | + } ); |
| 106 | + registry.dispatch( CORE_SITE ).receiveGetEmailReportingErrors( [] ); |
| 107 | + |
| 108 | + const { container } = render( <EmailReportingErrorNotice />, { |
| 109 | + registry, |
| 110 | + } ); |
| 111 | + |
| 112 | + expect( container ).toBeEmptyDOMElement(); |
| 113 | + } ); |
| 114 | +} ); |
0 commit comments