Skip to content

Commit

Permalink
Add tests for ProductionLocationDetails component
Browse files Browse the repository at this point in the history
  • Loading branch information
mazursasha1990 committed Dec 31, 2024
1 parent 8b0e243 commit 00302aa
Showing 1 changed file with 54 additions and 0 deletions.
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);
});
});


0 comments on commit 00302aa

Please sign in to comment.