import React from 'react'; import renderer from 'react-test-renderer'; import ShippingAddressSection from '../components/user_summary/shipping_address/ShippingAddressSection'; import ShippingAddressForm from '../components/user_summary/shipping_address/ShippingAddressForm'; import {Address} from '../ShippingAddressProps'; import Countries from './mock/Countries.json'; import States from './mock/States.json'; let component: renderer.ReactTestRenderer; renderer.act(() => { component = renderer.create( address} onNewAddress={async (address: Address) => address} onAddressChange={async (id: string) => id} defaultCountry={Countries[0]} initialSelectionId="1" countries={Countries} states={States} accessToken="" cartId="" /> ); }); describe('ShippingAddressSection', () => { test('matches snapshot', () => { expect(component.toJSON()).toMatchSnapshot(); }); test('opens form on link click', () => { const link = component.root.findByType('a'); renderer.act(link.props.onClick); expect(component.root.findByType(ShippingAddressForm)).toBeDefined; }); test('closes form on cancel button click', () => { const cancelButton = component.root .findAllByType('button') .find(b => b.props.className .split(' ') .includes('ShippingAddressSection__button--cancel') ); renderer.act(cancelButton.props.onClick); expect(component.root.findAllByType(ShippingAddressForm).length).toEqual(0); }); test('opens form on link click', () => { const link = component.root.findByType('a'); renderer.act(link.props.onClick); expect(component.root.findByType(ShippingAddressForm)).toBeDefined; }); });