From 00302aa159748c59d77e67ad2b9c935c8b0ce72c Mon Sep 17 00:00:00 2001 From: mazur Date: Tue, 31 Dec 2024 13:01:18 +0200 Subject: [PATCH] Add tests for ProductionLocationDetails component --- .../ProductionLocationDetails.test.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/react/src/__tests__/components/ProductionLocationDetails.test.js diff --git a/src/react/src/__tests__/components/ProductionLocationDetails.test.js b/src/react/src/__tests__/components/ProductionLocationDetails.test.js new file mode 100644 index 000000000..471f2c201 --- /dev/null +++ b/src/react/src/__tests__/components/ProductionLocationDetails.test.js @@ -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(); + + 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(); + + 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(); + + expect(getByText(`OS ID: ${osId}`)).toBeInTheDocument(); + }); + + test('renders the tooltip for each historical OS ID', () => { + const { getAllByTestId } = renderWithProviders(); + + const tooltips = getAllByTestId('previous-os-id-tooltip'); + expect(tooltips.length).toBe(defaultProps.historicalOsIds.length); + }); +}); + +