Skip to content

Commit 0aab6be

Browse files
committed
feat: display trust badge when product has only brand PPs
1 parent db2aec0 commit 0aab6be

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

src/__fixtures__/offers.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const offersSuccess = () => ({
2626
],
2727
});
2828

29+
// This happens when product doesn't have any proof points but its brand has
2930
export const offersNoProofPoints = () => ({
3031
trustBadge: {
3132
backgroundColor: '#dedede',

src/__tests__/api/index.test.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('getOffers', () => {
6969
});
7070

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

8080
expect(result).toEqual(offersNoProofPoints());
81-
expect(Errors.warn).toHaveBeenCalledWith(
82-
expect.stringContaining('No proof points found for the SKU: fakeSku')
83-
);
8481
});
8582
});
8683
});

src/__tests__/index.test.tsx

+19-5
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,28 @@ describe('TrustBadge', () => {
8383
});
8484

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

89-
await act(() => {
90-
getOffersPromiseResolve(offersNoProofPoints());
90+
await act(() => {
91+
getOffersPromiseResolve(offersNoProofPoints());
92+
});
93+
94+
expect(screen.root).toHaveTextContent(/Sustainability claims/i);
9195
});
96+
});
9297

93-
expect(screen.root).not.toHaveTextContent(/Sustainability claims/i);
98+
describe('when ProofPoint variant', () => {
99+
it('is still shown as success response from API without proof points indicates there are brand proof points', async () => {
100+
whenTrustBadgeRendered('ProofPoint');
101+
102+
await act(() => {
103+
getOffersPromiseResolve(offersNoProofPoints());
104+
});
105+
106+
expect(screen.queryAllByLabelText('Provenance logo')).toHaveLength(1);
107+
});
94108
});
95109

96110
describe('when no offers', () => {

src/api/index.tsx

-5
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ export async function getOffers(sku: string): Promise<OffersData | null> {
122122
);
123123
return null;
124124
}
125-
if (data.proofPoints.length === 0) {
126-
Errors.warn(
127-
`No proof points found for the SKU: ${sku}, it could be a valid case but better double check that the SKU is valid.`
128-
);
129-
}
130125
return data;
131126
} else {
132127
const message = await response.text();

src/trustBadge/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ const TrustBadgeComponent = ({
9595
const trustBadgeHeight =
9696
variant === 'Tick' ? Tick.getHeight() : ProofPoint.getHeight();
9797

98-
if (!offers || !offers.proofPoints || offers.proofPoints.length === 0)
99-
return <></>;
98+
if (!offers || !offers.proofPoints) return <></>;
10099

101100
return (
102101
<View style={{ flexBasis: scaled(trustBadgeHeight) }}>

0 commit comments

Comments
 (0)