|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: (c) 2025 Liferay, Inc. https://liferay.com |
| 3 | + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 |
| 4 | + */ |
| 5 | + |
| 6 | +import '@testing-library/jest-dom'; |
| 7 | +import {render, screen} from '@testing-library/react'; |
| 8 | +import React from 'react'; |
| 9 | + |
| 10 | +import SpaceService from '../../../../src/main/resources/META-INF/resources/js/common/services/SpaceService'; |
| 11 | +import PerformanceDashboard from '../../../../src/main/resources/META-INF/resources/js/main_view/dashboard/performance/PerformanceDashboard'; |
| 12 | + |
| 13 | +jest.mock( |
| 14 | + '../../../../src/main/resources/META-INF/resources/js/common/services/SpaceService' |
| 15 | +); |
| 16 | + |
| 17 | +const mockedSpaceService = SpaceService as jest.Mocked<typeof SpaceService>; |
| 18 | + |
| 19 | +function renderPerformanceDashboard({ |
| 20 | + analyticsCloudEnabled = true, |
| 21 | +}: { |
| 22 | + analyticsCloudEnabled?: boolean; |
| 23 | +} = {}) { |
| 24 | + return render( |
| 25 | + <PerformanceDashboard |
| 26 | + admin={false} |
| 27 | + analyticsEnabled={analyticsCloudEnabled} |
| 28 | + /> |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +describe('PerformanceDashboard', () => { |
| 33 | + beforeEach(() => { |
| 34 | + jest.clearAllMocks(); |
| 35 | + |
| 36 | + mockedSpaceService.getSpaces.mockResolvedValue([]); |
| 37 | + }); |
| 38 | + |
| 39 | + it('shows the connect to Analytics Cloud state when the instance is not connected', () => { |
| 40 | + renderPerformanceDashboard({analyticsCloudEnabled: false}); |
| 41 | + |
| 42 | + expect( |
| 43 | + screen.getByText('connect-to-liferay-analytics-cloud') |
| 44 | + ).toBeInTheDocument(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('does not show the connect to Analytics Cloud state when the instance is connected', () => { |
| 48 | + renderPerformanceDashboard(); |
| 49 | + |
| 50 | + expect( |
| 51 | + screen.queryByText('connect-to-liferay-analytics-cloud') |
| 52 | + ).not.toBeInTheDocument(); |
| 53 | + }); |
| 54 | +}); |
0 commit comments