-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ProductionLocationDetails component
- Loading branch information
1 parent
8b0e243
commit 00302aa
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/react/src/__tests__/components/ProductionLocationDetails.test.js
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,54 @@ | ||
import React from 'react'; | ||
import ProductionLocationDetails from '../../components/Contribute/ProductionLocationDetails'; | ||
import renderWithProviders from '../../util/testUtils/renderWithProviders'; | ||
|
||
describe('ProductionLocationDetails component', () => { | ||
const osId = 'US2021250D1DTN7'; | ||
const name = 'Production Location Name'; | ||
const address = '1234 Production Location St, City, State, 12345'; | ||
const countryName = 'United States'; | ||
const historicalOsIds = ['US2020053ZH1RY4', 'US2020053ZH1RY5']; | ||
|
||
const defaultProps = { | ||
osId, | ||
name, | ||
address, | ||
countryName, | ||
historicalOsIds, | ||
}; | ||
|
||
test('renders the production location details correctly', () => { | ||
const { getByText } = renderWithProviders(<ProductionLocationDetails {...defaultProps}/>); | ||
|
||
expect(getByText(name)).toBeInTheDocument(); | ||
expect(getByText(`Current OS ID: ${osId}`)).toBeInTheDocument(); | ||
expect(getByText(`Previous OS ID: ${historicalOsIds[0]}`)).toBeInTheDocument(); | ||
expect(getByText(`Previous OS ID: ${historicalOsIds[1]}`)).toBeInTheDocument(); | ||
expect(getByText(address)).toBeInTheDocument(); | ||
expect(getByText(countryName)).toBeInTheDocument(); | ||
}); | ||
|
||
test('does not render historical OS IDs if the array is empty', () => { | ||
const props = { ...defaultProps, historicalOsIds: [] }; | ||
const { getByText, queryByText } = renderWithProviders(<ProductionLocationDetails {...props}/>); | ||
|
||
expect(getByText(`OS ID: ${osId}`)).toBeInTheDocument(); | ||
expect(queryByText('Previous OS ID:')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('renders without crashing when no historical OS IDs are provided', () => { | ||
const props = { ...defaultProps, historicalOsIds: undefined }; | ||
const { getByText } = renderWithProviders(<ProductionLocationDetails {...props}/>); | ||
|
||
expect(getByText(`OS ID: ${osId}`)).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders the tooltip for each historical OS ID', () => { | ||
const { getAllByTestId } = renderWithProviders(<ProductionLocationDetails {...defaultProps}/>); | ||
|
||
const tooltips = getAllByTestId('previous-os-id-tooltip'); | ||
expect(tooltips.length).toBe(defaultProps.historicalOsIds.length); | ||
}); | ||
}); | ||
|
||
|