-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-2372] Implement 'Operational Details Submitted by Management' section using claim info #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VadimKovalenkoSNF
merged 19 commits into
main
from
OSDEV-2372-operational-details-claim
Mar 12, 2026
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3455b09
Add claim data section
VadimKovalenkoSNF fa7d258
Add switch button
VadimKovalenkoSNF f247bcf
Merge branch 'main' into OSDEV-2372-operational-details-claim
VadimKovalenkoSNF 98f8ba1
Bring back Divider component
VadimKovalenkoSNF a2bb7a1
Remove toogle switch, minor fixes
VadimKovalenkoSNF d5f6988
Update release notes
VadimKovalenkoSNF 6beb1eb
Remove redundant divider
VadimKovalenkoSNF f1c129d
Refactor icon markup
VadimKovalenkoSNF b696ec4
Update release notes
VadimKovalenkoSNF 22895dc
Revert fixed to implemented claim badge
VadimKovalenkoSNF f9b6ea8
Add break-word CSS rule
VadimKovalenkoSNF f273a02
Use lodash instead of regular JS functions
VadimKovalenkoSNF d64260a
Bring back switch button
VadimKovalenkoSNF 18836d4
Minor style fixes
VadimKovalenkoSNF 2cf9735
Connect scroll to title feature
VadimKovalenkoSNF 5a25385
Refactor divider
VadimKovalenkoSNF feb8ca1
Show tooltip text near each claim field
VadimKovalenkoSNF c6c8410
Add sorting for the claim fields
VadimKovalenkoSNF bb24deb
Update unit tests
VadimKovalenkoSNF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
221 changes: 221 additions & 0 deletions
221
src/react/src/__tests__/components/ClaimDataContainer.test.js
This file contains hidden or 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,221 @@ | ||
| import React from 'react'; | ||
| import renderWithProviders from '../../util/testUtils/renderWithProviders'; | ||
| import ClaimDataContainer from '../../components/ProductionLocation/ClaimSection/ClaimDataContainer/ClaimDataContainer'; | ||
| import { STATUS_CLAIMED } from '../../components/ProductionLocation/DataPoint/constants'; | ||
|
|
||
|
|
||
| const makeClaimInfo = (overrides = {}) => ({ | ||
| facility: { | ||
| website: 'https://example.com', | ||
| phone_number: '+1 234 567 8900', | ||
| minimum_order: '100 units', | ||
| average_lead_time: '30 days', | ||
| female_workers_percentage: 60, | ||
| affiliations: ['Fair Trade'], | ||
| certifications: ['ISO 9001'], | ||
| opening_date: '2010', | ||
| closing_date: null, | ||
| estimated_annual_throughput: 20000, | ||
| actual_annual_energy_consumption: null, | ||
| description: 'A sample facility.', | ||
| }, | ||
| contact: { | ||
| name: 'Jane Doe', | ||
| email: '[email protected]', | ||
| }, | ||
| office: { | ||
| name: 'Head Office', | ||
| address: '1 Office St', | ||
| country: 'US', | ||
| phone_number: '+1 800 000 0000', | ||
| }, | ||
| contributor: { name: 'Test Contributor' }, | ||
| approved_at: '2023-05-15T00:00:00Z', | ||
| created_at: '2023-01-01T00:00:00Z', | ||
| ...overrides, | ||
| }); | ||
|
|
||
| const renderComponent = (props = {}) => { | ||
| const claimInfo = | ||
| 'claimInfo' in props ? props.claimInfo : makeClaimInfo(); | ||
| return renderWithProviders( | ||
| <ClaimDataContainer | ||
| isClaimed={props.isClaimed ?? true} | ||
| claimInfo={claimInfo} | ||
| className={props.className} | ||
| />, | ||
| ); | ||
| }; | ||
|
|
||
| describe('ClaimDataContainer — empty state', () => { | ||
| it('renders nothing when isClaimed is false', () => { | ||
| const { container } = renderComponent({ isClaimed: false }); | ||
| expect(container.firstChild).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders nothing when claimInfo is null', () => { | ||
| const { container } = renderComponent({ | ||
| isClaimed: true, | ||
| claimInfo: null, | ||
| }); | ||
| expect(container.firstChild).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders nothing when all facility fields are empty', () => { | ||
| const { container } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ | ||
| facility: {}, | ||
| contact: null, | ||
| office: null, | ||
| }), | ||
| }); | ||
| expect(container.firstChild).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ClaimDataContainer — section header', () => { | ||
| it('renders the section title', () => { | ||
| const { getByText } = renderComponent(); | ||
| expect( | ||
| getByText('Operational Details Submitted by Management'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders the info tooltip trigger', () => { | ||
| const { getByTestId } = renderComponent(); | ||
| expect(getByTestId('claim-data-info-tooltip')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ClaimDataContainer — field labels and values', () => { | ||
| it('renders all expected field labels', () => { | ||
| const { getByText } = renderComponent(); | ||
|
|
||
| const expectedLabels = [ | ||
| 'Website', | ||
| 'Contact Person', | ||
| 'Contact Email', | ||
| 'Phone Number', | ||
| 'Minimum Order', | ||
| 'Average Lead Time', | ||
| 'Affiliations', | ||
| 'Certifications/Standards/Regulations', | ||
| 'Opening Date', | ||
| 'Estimated Annual Throughput', | ||
| 'Office Name', | ||
| 'Office Address', | ||
| 'Office Phone Number', | ||
| 'Description', | ||
| ]; | ||
|
|
||
| expectedLabels.forEach(label => { | ||
| expect(getByText(label, { exact: true })).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it('renders plain field values', () => { | ||
| const claimInfo = makeClaimInfo(); | ||
| const { getByText } = renderComponent({ claimInfo }); | ||
|
|
||
| expect( | ||
| getByText(claimInfo.facility.phone_number, { exact: true }), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| getByText(claimInfo.facility.minimum_order, { exact: true }), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| getByText(claimInfo.facility.average_lead_time, { exact: true }), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| getByText(claimInfo.facility.description, { exact: true }), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| getByText('20000 kg/year', { exact: true }), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders contact fields when contact is provided', () => { | ||
| const { getByText } = renderComponent(); | ||
| expect(getByText('Jane Doe', { exact: true })).toBeInTheDocument(); | ||
| expect( | ||
| getByText('[email protected]', { exact: true }), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('omits contact fields when contact is null', () => { | ||
| const { queryByText } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ contact: null }), | ||
| }); | ||
| expect(queryByText('Contact Person')).not.toBeInTheDocument(); | ||
| expect(queryByText('Contact Email')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders office fields when office is provided', () => { | ||
| const { getByText } = renderComponent(); | ||
| expect(getByText('Head Office', { exact: true })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('omits office fields when office is null', () => { | ||
| const { queryByText } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ office: null }), | ||
| }); | ||
| expect(queryByText('Office Name')).not.toBeInTheDocument(); | ||
| expect(queryByText('Office Address')).not.toBeInTheDocument(); | ||
| expect(queryByText('Office Phone Number')).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ClaimDataContainer — Claimed status chips', () => { | ||
| it('renders a Claimed chip for each displayed field', () => { | ||
| const { getAllByTestId, getAllByText } = renderComponent(); | ||
| const dataPoints = getAllByTestId('data-point'); | ||
| const claimedChips = getAllByText(STATUS_CLAIMED); | ||
| expect(claimedChips.length).toBe(dataPoints.length); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ClaimDataContainer — contributor attribution', () => { | ||
| it('resolves contributor name from contributor.name object', () => { | ||
| const { getAllByTestId } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ | ||
| contributor: { name: 'Acme Corp' }, | ||
| }), | ||
| }); | ||
| getAllByTestId('data-point-contributor').forEach(el => { | ||
| expect(el).toHaveTextContent('Acme Corp'); | ||
| }); | ||
| }); | ||
|
|
||
| it('resolves contributor name from a plain string', () => { | ||
| const { getAllByTestId } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ contributor: 'String Contributor' }), | ||
| }); | ||
| getAllByTestId('data-point-contributor').forEach(el => { | ||
| expect(el).toHaveTextContent('String Contributor'); | ||
| }); | ||
| }); | ||
|
|
||
| it('prefers approved_at over created_at for the date', () => { | ||
| const { getAllByTestId } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ | ||
| approved_at: '2023-05-15T00:00:00Z', | ||
| created_at: '2023-01-01T00:00:00Z', | ||
| }), | ||
| }); | ||
| getAllByTestId('data-point-date').forEach(el => { | ||
| expect(el).toHaveTextContent('May 15, 2023'); | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to created_at when approved_at is absent', () => { | ||
| const { getAllByTestId } = renderComponent({ | ||
| claimInfo: makeClaimInfo({ | ||
| approved_at: undefined, | ||
| created_at: '2022-11-09T00:00:00Z', | ||
| }), | ||
| }); | ||
| getAllByTestId('data-point-date').forEach(el => { | ||
| expect(el).toHaveTextContent('November 9, 2022'); | ||
| }); | ||
| }); | ||
| }); |
111 changes: 104 additions & 7 deletions
111
.../src/components/ProductionLocation/ClaimSection/ClaimDataContainer/ClaimDataContainer.jsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,112 @@ | ||
| import React from 'react'; | ||
| import { object, bool, shape, oneOfType, string } from 'prop-types'; | ||
| import { withStyles } from '@material-ui/core/styles'; | ||
| import Typography from '@material-ui/core/Typography'; | ||
| import Divider from '@material-ui/core/Divider'; | ||
| import InfoOutlined from '@material-ui/icons/InfoOutlined'; | ||
|
|
||
| import DataPoint from '../../DataPoint/DataPoint'; | ||
| import { STATUS_CLAIMED } from '../../DataPoint/constants'; | ||
| import IconComponent from '../../../Shared/IconComponent/IconComponent'; | ||
| import LearnMoreLink from '../../Shared/LearnMoreLink/LearnMoreLink'; | ||
| import BadgeClaimed from '../../../BadgeClaimed'; | ||
| import { | ||
| getLocationFieldsConfig, | ||
| hasDisplayableValue, | ||
| } from '../../../FacilityDetailsClaimedInfo/utils'; | ||
|
|
||
| import claimDataContainerStyles from './styles'; | ||
|
|
||
| const ClaimDataContainer = ({ classes, className }) => ( | ||
| <div className={`${classes.container} ${className || ''}`}> | ||
| <Typography variant="title" className={classes.title} component="h3"> | ||
| Claim Data | ||
| </Typography> | ||
| </div> | ||
| ); | ||
| const ClaimDataContainer = ({ classes, className, claimInfo, isClaimed }) => { | ||
| if (!isClaimed || !claimInfo) { | ||
| return null; | ||
| } | ||
|
|
||
| const { facility, contact, office } = claimInfo; | ||
|
|
||
| const contributorName = | ||
| typeof claimInfo.contributor === 'string' | ||
| ? claimInfo.contributor | ||
| : claimInfo.contributor?.name ?? null; | ||
|
|
||
| const claimedAt = claimInfo.approved_at ?? claimInfo.created_at ?? null; | ||
|
|
||
| const fieldsConfig = getLocationFieldsConfig( | ||
| facility || {}, | ||
| contact || null, | ||
| office || null, | ||
| ); | ||
|
|
||
| const displayableFields = fieldsConfig.filter(field => | ||
| hasDisplayableValue(field.getValue()), | ||
| ); | ||
protsack-stephan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (displayableFields.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div className={`${classes.container} ${className || ''}`}> | ||
| <div className={classes.titleRow}> | ||
| <BadgeClaimed className={classes.titleIcon} /> | ||
| <Typography | ||
| variant="title" | ||
| className={classes.sectionTitle} | ||
| component="h3" | ||
| > | ||
| Operational Details Submitted by Management | ||
| </Typography> | ||
| <IconComponent | ||
| title={ | ||
| <> | ||
| Data provided by the production location management | ||
| through the claim process. | ||
| <LearnMoreLink href="https://info.opensupplyhub.org/resources/claim-a-facility" /> | ||
| </> | ||
| } | ||
| icon={InfoOutlined} | ||
| className={classes.infoButton} | ||
| data-testid="claim-data-info-tooltip" | ||
| /> | ||
| </div> | ||
| <div className={classes.dataPointsList}> | ||
| {displayableFields.map((field, index) => ( | ||
| <React.Fragment key={field.key}> | ||
| <DataPoint | ||
| label={field.label} | ||
| value={field.getValue()} | ||
| statusLabel={STATUS_CLAIMED} | ||
| contributorName={contributorName} | ||
| date={claimedAt} | ||
| /> | ||
| {index < displayableFields.length - 1 && ( | ||
| <Divider className={classes.divider} /> | ||
| )} | ||
| </React.Fragment> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| ClaimDataContainer.propTypes = { | ||
| classes: object.isRequired, | ||
| className: string, | ||
| claimInfo: shape({ | ||
| facility: object, | ||
| contact: object, | ||
| office: object, | ||
| contributor: oneOfType([string, shape({ name: string })]), | ||
| approved_at: string, | ||
| created_at: string, | ||
| }), | ||
| isClaimed: bool, | ||
| }; | ||
|
|
||
| ClaimDataContainer.defaultProps = { | ||
| className: '', | ||
| claimInfo: null, | ||
| isClaimed: false, | ||
| }; | ||
|
|
||
| export default withStyles(claimDataContainerStyles)(ClaimDataContainer); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.