|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import React from 'react'; |
| 7 | +import { render } from '@testing-library/react'; |
| 8 | +import { setServices } from '../opensearch_dashboards_services'; |
| 9 | +import { getMockedServices } from '../opensearch_dashboards_services.mock'; |
| 10 | +import { ImportSampleDataApp, HomeApp } from './home_app'; |
| 11 | + |
| 12 | +jest.mock('./legacy/home', () => ({ |
| 13 | + Home: () => <div>Home</div>, |
| 14 | +})); |
| 15 | + |
| 16 | +jest.mock('../load_tutorials', () => ({ |
| 17 | + getTutorial: () => {}, |
| 18 | +})); |
| 19 | + |
| 20 | +jest.mock('./tutorial_directory', () => ({ |
| 21 | + TutorialDirectory: (props: { withoutHomeBreadCrumb?: boolean }) => ( |
| 22 | + <div |
| 23 | + data-test-subj="tutorial_directory" |
| 24 | + data-without-home-bread-crumb={!!props.withoutHomeBreadCrumb} |
| 25 | + /> |
| 26 | + ), |
| 27 | +})); |
| 28 | + |
| 29 | +describe('<HomeApp />', () => { |
| 30 | + let currentService: ReturnType<typeof getMockedServices>; |
| 31 | + beforeEach(() => { |
| 32 | + currentService = getMockedServices(); |
| 33 | + setServices(currentService); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should not pass withoutHomeBreadCrumb to TutorialDirectory component', async () => { |
| 37 | + const originalHash = window.location.hash; |
| 38 | + const { findByTestId } = render(<HomeApp />); |
| 39 | + window.location.hash = '/tutorial_directory'; |
| 40 | + const tutorialRenderResult = await findByTestId('tutorial_directory'); |
| 41 | + expect(tutorialRenderResult.dataset.withoutHomeBreadCrumb).toEqual('false'); |
| 42 | + |
| 43 | + // revert to original hash |
| 44 | + window.location.hash = originalHash; |
| 45 | + }); |
| 46 | +}); |
| 47 | + |
| 48 | +describe('<ImportSampleDataApp />', () => { |
| 49 | + let currentService: ReturnType<typeof getMockedServices>; |
| 50 | + beforeEach(() => { |
| 51 | + currentService = getMockedServices(); |
| 52 | + setServices(currentService); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should pass withoutHomeBreadCrumb to TutorialDirectory component', async () => { |
| 56 | + const { findByTestId } = render(<ImportSampleDataApp />); |
| 57 | + const tutorialRenderResult = await findByTestId('tutorial_directory'); |
| 58 | + expect(tutorialRenderResult.dataset.withoutHomeBreadCrumb).toEqual('true'); |
| 59 | + }); |
| 60 | +}); |
0 commit comments