|
3 | 3 | import React from 'react'; |
4 | 4 | import '@testing-library/jest-dom'; |
5 | 5 | import classNames from 'classnames'; |
6 | | -import { render, fireEvent } from '@testing-library/react'; |
| 6 | +import { render, fireEvent, within } from '@testing-library/react'; |
7 | 7 | import userEvent from '@testing-library/user-event'; |
8 | 8 | import { logError } from '@edx/frontend-platform/logging'; |
9 | 9 | import { IntlProvider } from '@edx/frontend-platform/i18n'; |
@@ -78,14 +78,15 @@ function DefaultContents({ className, onClick, ...rest }) { |
78 | 78 | ); |
79 | 79 | } |
80 | 80 |
|
81 | | -function PluginSlotWrapper({ slotOptions, children }) { |
| 81 | +function PluginSlotWrapper({ slotOptions, children, pluginProps }) { |
82 | 82 | return ( |
83 | 83 | <IntlProvider locale="en"> |
84 | 84 | <PluginSlot |
85 | 85 | id="test-slot" |
86 | 86 | data-testid="test-slot-id" |
87 | 87 | as="div" |
88 | 88 | slotOptions={slotOptions} |
| 89 | + pluginProps={pluginProps} |
89 | 90 | > |
90 | 91 | {children} |
91 | 92 | </PluginSlot> |
@@ -182,20 +183,25 @@ describe('PluginSlot', () => { |
182 | 183 | { |
183 | 184 | op: PLUGIN_OPERATIONS.Wrap, |
184 | 185 | widgetId: 'default_contents', |
185 | | - wrapper: ({ component }) => ( |
| 186 | + wrapper: ({ component, pluginProps }) => ( |
186 | 187 | <div data-testid="custom-wrapper"> |
187 | 188 | {component} |
| 189 | + <div data-testid="custom-wrapper-prop"> |
| 190 | + {pluginProps.prop1} |
| 191 | + </div> |
188 | 192 | </div> |
189 | 193 | ), |
190 | 194 | }, |
191 | 195 | ], |
192 | 196 | keepDefault: true, |
193 | 197 | }); |
194 | 198 |
|
195 | | - const { getByTestId } = render(<TestPluginSlot />); |
| 199 | + const { getByTestId } = render(<TestPluginSlot pluginProps={{ prop1: 'prop1' }} />); |
196 | 200 | const customWrapper = getByTestId('custom-wrapper'); |
197 | 201 | const defaultContent = getByTestId('default_contents'); |
198 | 202 | expect(customWrapper).toContainElement(defaultContent); |
| 203 | + const pluginProps = within(customWrapper).getByTestId('custom-wrapper-prop'); |
| 204 | + expect(pluginProps).toHaveTextContent('prop1'); |
199 | 205 | }); |
200 | 206 |
|
201 | 207 | it('should not render a widget if the Hide operation is applied to it', () => { |
|
0 commit comments