Skip to content

feat: display trust badge when product has only brand PPs #29

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
merged 1 commit into from
Mar 12, 2025
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
1 change: 1 addition & 0 deletions src/__fixtures__/offers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const offersSuccess = () => ({
],
});

// This happens when product doesn't have any proof points but its brand has
export const offersNoProofPoints = () => ({
trustBadge: {
backgroundColor: '#dedede',
Expand Down
5 changes: 1 addition & 4 deletions src/__tests__/api/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('getOffers', () => {
});

describe('when proof points were not found', () => {
it('is not shown', async () => {
it('returns the fetched data', async () => {
global.fetch = jest.fn(() => ({
ok: true,
json: () => Promise.resolve(offersNoProofPoints()),
Expand All @@ -78,9 +78,6 @@ describe('getOffers', () => {
const result = await getOffers('fakeSku');

expect(result).toEqual(offersNoProofPoints());
expect(Errors.warn).toHaveBeenCalledWith(
expect.stringContaining('No proof points found for the SKU: fakeSku')
);
});
});
});
Expand Down
24 changes: 19 additions & 5 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,28 @@ describe('TrustBadge', () => {
});

describe('when proof points were not found', () => {
it('is not shown', async () => {
whenTrustBadgeRendered();
describe('when Tick variant', () => {
it('is still shown as success response from API without proof points indicates there are brand proof points', async () => {
whenTrustBadgeRendered();

await act(() => {
getOffersPromiseResolve(offersNoProofPoints());
await act(() => {
getOffersPromiseResolve(offersNoProofPoints());
});

expect(screen.root).toHaveTextContent(/Sustainability claims/i);
});
});

expect(screen.root).not.toHaveTextContent(/Sustainability claims/i);
describe('when ProofPoint variant', () => {
it('is still shown as success response from API without proof points indicates there are brand proof points', async () => {
whenTrustBadgeRendered('ProofPoint');

await act(() => {
getOffersPromiseResolve(offersNoProofPoints());
});

expect(screen.queryAllByLabelText('Provenance logo')).toHaveLength(1);
});
});

describe('when no offers', () => {
Expand Down
5 changes: 0 additions & 5 deletions src/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ export async function getOffers(sku: string): Promise<OffersData | null> {
);
return null;
}
if (data.proofPoints.length === 0) {
Errors.warn(
`No proof points found for the SKU: ${sku}, it could be a valid case but better double check that the SKU is valid.`
);
}
return data;
} else {
const message = await response.text();
Expand Down
3 changes: 1 addition & 2 deletions src/trustBadge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ const TrustBadgeComponent = ({
const trustBadgeHeight =
variant === 'Tick' ? Tick.getHeight() : ProofPoint.getHeight();

if (!offers || !offers.proofPoints || offers.proofPoints.length === 0)
return <></>;
if (!offers || !offers.proofPoints) return <></>;

return (
<View style={{ flexBasis: scaled(trustBadgeHeight) }}>
Expand Down
Loading