From 793b22143e3de547a1b5d093e0d02be05f4de787 Mon Sep 17 00:00:00 2001 From: Albert Date: Tue, 14 Jan 2025 11:45:27 +0100 Subject: [PATCH] botonic-react: add tests to wa product carousel component --- .../whatsapp-product-carousel.test.jsx.snap | 21 ++++++++ .../whatsapp-product-carousel.test.jsx | 48 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 packages/botonic-react/tests/components/__snapshots__/whatsapp-product-carousel.test.jsx.snap create mode 100644 packages/botonic-react/tests/components/whatsapp-product-carousel.test.jsx diff --git a/packages/botonic-react/tests/components/__snapshots__/whatsapp-product-carousel.test.jsx.snap b/packages/botonic-react/tests/components/__snapshots__/whatsapp-product-carousel.test.jsx.snap new file mode 100644 index 000000000..7d250ba68 --- /dev/null +++ b/packages/botonic-react/tests/components/__snapshots__/whatsapp-product-carousel.test.jsx.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders Whatsapp Product Carousel component with card indexes 1`] = ` + +`; + +exports[`renders Whatsapp Product Carousel component without card indexes 1`] = ` + +`; diff --git a/packages/botonic-react/tests/components/whatsapp-product-carousel.test.jsx b/packages/botonic-react/tests/components/whatsapp-product-carousel.test.jsx new file mode 100644 index 000000000..866d9a262 --- /dev/null +++ b/packages/botonic-react/tests/components/whatsapp-product-carousel.test.jsx @@ -0,0 +1,48 @@ +import { expect, test } from '@jest/globals' +import React from 'react' +import TestRenderer from 'react-test-renderer' + +import { WhatsappProductCarousel } from '../../src/components' + +const renderToJSON = sut => TestRenderer.create(sut).toJSON() + +const getProps = withIndexes => { + return { + templateName: 'fake-template-name', + templateLanguage: 'en_US', + cards: [ + { + card_index: withIndexes ? 1 : undefined, + catalog_id: 'fake-catalog-id', + product_retailer_id: 'fake-product-id-2', + }, + { + card_index: withIndexes ? 0 : undefined, + catalog_id: 'fake-catalog-id', + product_retailer_id: 'fake-product-id-1', + }, + ], + bodyParameters: [ + { + type: 'text', + text: 'Pepito', + }, + { + type: 'text', + text: 'Test', + }, + ], + } +} + +test('renders Whatsapp Product Carousel component without card indexes', () => { + const props = getProps(false) + const tree = renderToJSON() + expect(tree).toMatchSnapshot() +}) + +test('renders Whatsapp Product Carousel component with card indexes', () => { + const props = getProps(true) + const tree = renderToJSON() + expect(tree).toMatchSnapshot() +})