Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions src/react/src/__tests__/components/ProductionLocationDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,63 +104,47 @@ describe('ProductionLocationDialog', () => {
expect(screen.getByText(/Shirts, Pants/i)).toBeInTheDocument();
});

test('Continue to Claim button should be active if production location is unclaimed and approved', () => {
test.each([
['PENDING', 'unclaimed', true],
['PENDING', 'claimed', true],
['REJECTED', 'claimed', true],
['REJECTED', 'unclaimed', false],
['REJECTED', undefined, true],
['APPROVED', 'unclaimed', false],
['APPROVED', 'claimed', true]
])('handles moderation status %s and claim status %s correctly', (moderationStatus, claimStatus, shouldBeDisabled) => {
const { getByRole } = render(
<Router>
<ProductionLocationDialog
classes={{}}
data={defaultProps.data}
osID={defaultProps.osID}
moderationStatus='APPROVED'
claimStatus='unclaimed'
moderationStatus={moderationStatus}
claimStatus={claimStatus}
/>
</Router>
);

const claimButton = getByRole('button', { name: /Continue to Claim/i });

expect(window.getComputedStyle(claimButton).pointerEvents).not.toBe('none');

expect(claimButton).toHaveAttribute('href', `/facilities/${defaultProps.osID}/claim`);
expect(window.getComputedStyle(claimButton).pointerEvents).toBe(shouldBeDisabled ? 'none' : '');
});

test('Continue to Claim button should be active if production location is unclaimed and rejected', () => {
test('check link to the claim flow for specific production location', () => {
const { getByRole } = render(
<Router>
<ProductionLocationDialog
classes={{}}
data={defaultProps.data}
osID={defaultProps.osID}
moderationStatus='REJECTED'
moderationStatus='APPROVED'
claimStatus='unclaimed'
/>
</Router>
);

const claimButton = getByRole('button', { name: /Continue to Claim/i });

expect(window.getComputedStyle(claimButton).pointerEvents).not.toBe('none');

expect(claimButton).toHaveAttribute('href', `/facilities/${defaultProps.osID}/claim`);
});

test('Continue to Claim button should be disabled if production location has been claimed', () => {
const { getByRole } = render(
<Router>
<ProductionLocationDialog
classes={{}}
data={defaultProps.data}
osID={defaultProps.osID}
moderationStatus={defaultProps.moderationStatus}
claimStatus='claimed'
/>
</Router>
);

const claimButton = getByRole('button', { name: /Continue to Claim/i });

expect(window.getComputedStyle(claimButton).pointerEvents).toBe('none');
});
})

test('closes ProductionLocationDialog when close button is clicked', () => {
const handleShowMock = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const getTooltipText = (claimStatus, moderationStatus) => {
return 'Production location has been claimed already.';
}

return '';
return 'Claim is not available.';
};

const ProductionLocationDialog = ({
Expand Down Expand Up @@ -310,7 +310,7 @@ const ProductionLocationDialog = ({

ProductionLocationDialog.defaultProps = {
osID: null,
claimStatus: PRODUCTION_LOCATION_CLAIM_STATUSES_ENUM.UNCLAIMED,
claimStatus: null,
};

ProductionLocationDialog.propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
productionLocationInfoRouteCommon,
searchByNameAndAddressResultRoute,
MODERATION_STATUSES_ENUM,
PRODUCTION_LOCATION_CLAIM_STATUSES_ENUM,
} from '../../util/constants';
import COLOURS from '../../util/COLOURS';
import ProductionLocationDialog from './ProductionLocationDialog';
Expand Down Expand Up @@ -794,8 +793,7 @@ const ProductionLocationInfo = ({
MODERATION_STATUSES_ENUM.PENDING
}
claimStatus={
singleProductionLocationData?.claim_status ||
PRODUCTION_LOCATION_CLAIM_STATUSES_ENUM.UNCLAIMED
singleProductionLocationData?.claim_status || null
}
/>
) : null}
Expand Down