|
| 1 | +import { render } from '@testing-library/react'; |
| 2 | +import { ConfigProvider } from '../components/ConfigContext'; |
| 3 | +import { InteractiveAtom } from '../components/InteractiveAtom'; |
| 4 | +import { InteractiveLayoutAtom } from '../components/InteractiveLayoutAtom'; |
| 5 | + |
| 6 | +const mockCustomData = JSON.stringify({ key: 'value' }); |
| 7 | + |
| 8 | +describe('Interactive atom custom data attributes', () => { |
| 9 | + it('should add custom data attribute to InteractiveAtom on web', () => { |
| 10 | + const { container } = render( |
| 11 | + <ConfigProvider |
| 12 | + value={{ |
| 13 | + renderingTarget: 'Web', |
| 14 | + darkModeAvailable: true, |
| 15 | + assetOrigin: '/', |
| 16 | + editionId: 'UK', |
| 17 | + }} |
| 18 | + > |
| 19 | + <InteractiveAtom |
| 20 | + id="test-id" |
| 21 | + title="Test Title" |
| 22 | + customData={mockCustomData} |
| 23 | + /> |
| 24 | + </ConfigProvider>, |
| 25 | + ); |
| 26 | + const el = container.querySelector( |
| 27 | + `[data-atom-custom-data='${mockCustomData}']`, |
| 28 | + ); |
| 29 | + expect(el).toBeInTheDocument(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should add custom data attribute to InteractiveAtom on apps', () => { |
| 33 | + const { container } = render( |
| 34 | + <ConfigProvider |
| 35 | + value={{ |
| 36 | + renderingTarget: 'Apps', |
| 37 | + darkModeAvailable: true, |
| 38 | + assetOrigin: '/', |
| 39 | + editionId: 'UK', |
| 40 | + }} |
| 41 | + > |
| 42 | + <InteractiveAtom |
| 43 | + id="test-id" |
| 44 | + title="Test Title" |
| 45 | + customData={mockCustomData} |
| 46 | + /> |
| 47 | + </ConfigProvider>, |
| 48 | + ); |
| 49 | + const el = container.querySelector( |
| 50 | + `[data-atom-custom-data='${mockCustomData}']`, |
| 51 | + ); |
| 52 | + expect(el).toBeInTheDocument(); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should add custom data attribute to InteractiveLayoutAtom', () => { |
| 56 | + const { container } = render( |
| 57 | + <InteractiveLayoutAtom id="test-id" customData={mockCustomData} />, |
| 58 | + ); |
| 59 | + const el = container.querySelector( |
| 60 | + `[data-atom-custom-data='${mockCustomData}']`, |
| 61 | + ); |
| 62 | + expect(el).toBeInTheDocument(); |
| 63 | + }); |
| 64 | +}); |
0 commit comments