forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for toast button and validation form
Signed-off-by: yujin-emma <[email protected]>
- Loading branch information
1 parent
bce6827
commit 613a02e
Showing
5 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../data_source_management/public/components/toast_button/manage_data_source_button.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { getManageDataSourceButton } from './manage_data_source_button'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { DSM_APP_ID } from '../../plugin'; | ||
import { render } from '@testing-library/react'; | ||
|
||
describe('ManageDataSourceButton', () => { | ||
const applicationMock = coreMock.createStart().application; | ||
|
||
it('renders without crashing', () => { | ||
const wrapper = render(getManageDataSourceButton()); | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
|
||
it('renders a button with correct label', () => { | ||
const { getByTestId } = render(getManageDataSourceButton(applicationMock)); | ||
const container = getByTestId('dataSourceManageDataSourceButtonContainer'); | ||
expect(container).toBeInTheDocument(); | ||
expect(container).toHaveTextContent('Manage data sources'); | ||
}); | ||
|
||
it('navigates to management app on button click', () => { | ||
const { getByTestId } = render(getManageDataSourceButton(applicationMock)); | ||
const button = getByTestId('dataSourceManageDataSourceButton'); | ||
button.click(); | ||
expect(applicationMock.navigateToApp).toHaveBeenCalledTimes(1); | ||
|
||
expect(applicationMock.navigateToApp).toHaveBeenCalledWith('management', { | ||
path: `opensearch-dashboards/${DSM_APP_ID}`, // Assuming DSM_APP_ID is replaced with a value | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/plugins/data_source_management/public/components/toast_button/reload_button.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { render, fireEvent } from '@testing-library/react'; | ||
import { getReloadButton } from './reload_button'; // Replace 'yourComponent' with the actual filename | ||
|
||
describe('getReloadButton', () => { | ||
it('renders button with correct label', () => { | ||
const { getByText } = render(getReloadButton()); | ||
expect(getByText('Refresh the page')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls window.location.reload() on button click', () => { | ||
const reloadMock = jest.fn(); | ||
Object.defineProperty(window, 'location', { | ||
value: { reload: reloadMock }, | ||
writable: true, | ||
}); | ||
|
||
const { getByText } = render(getReloadButton()); | ||
fireEvent.click(getByText('Refresh the page')); | ||
expect(reloadMock).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters