Skip to content

Commit

Permalink
botonic-react: add tests to wa product carousel component
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertGom committed Jan 14, 2025
1 parent d3f7f2c commit 793b221
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders Whatsapp Product Carousel component with card indexes 1`] = `
<message
bodyParameters="[{"type":"text","text":"Pepito"},{"type":"text","text":"Test"}]"
cards="[{"card_index":1,"catalog_id":"fake-catalog-id","product_retailer_id":"fake-product-id-2"},{"card_index":1,"catalog_id":"fake-catalog-id","product_retailer_id":"fake-product-id-1"}]"
templateLanguage="en_US"
templateName="fake-template-name"
type="whatsapp-product-carousel"
/>
`;

exports[`renders Whatsapp Product Carousel component without card indexes 1`] = `
<message
bodyParameters="[{"type":"text","text":"Pepito"},{"type":"text","text":"Test"}]"
cards="[{"card_index":0,"catalog_id":"fake-catalog-id","product_retailer_id":"fake-product-id-2"},{"card_index":1,"catalog_id":"fake-catalog-id","product_retailer_id":"fake-product-id-1"}]"
templateLanguage="en_US"
templateName="fake-template-name"
type="whatsapp-product-carousel"
/>
`;
Original file line number Diff line number Diff line change
@@ -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(<WhatsappProductCarousel {...props} />)
expect(tree).toMatchSnapshot()
})

test('renders Whatsapp Product Carousel component with card indexes', () => {
const props = getProps(true)
const tree = renderToJSON(<WhatsappProductCarousel {...props} />)
expect(tree).toMatchSnapshot()
})

0 comments on commit 793b221

Please sign in to comment.