Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/PluginSlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { getPlugin, subscribe } from './pluginRegistry';

const PluginSlot = ({ scope, props: componentProps }) => {
const PluginSlot = ({ scope, props: componentProps = {} }) => {
const [Component, setComponent] = useState(() => getPlugin(scope));

useEffect(() => subscribe(() => setComponent(() => getPlugin(scope))), [scope]);
Expand Down
12 changes: 12 additions & 0 deletions tests/MarkerPopup/LocationDetailsBox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ describe('should render marker popup correctly', () => {
).not.toThrow();
});
});

describe('should handle plugin fields', () => {
it('renders the field label for a scoped plugin field even when plugin is not loaded', () => {
const placeWithPlugin = {
...correctMarkerData,
data: [['promocode', { scope: 'promocode', code: 'U1VN', text: 'Get it' }]],
metadata: { uuid: 'test-uuid' },
};
render(<LocationDetailsBox place={placeWithPlugin} />);
expect(screen.getByText('promocode')).toBeInTheDocument();
});
});
});
});

Expand Down
22 changes: 22 additions & 0 deletions tests/plugins/PluginSlot.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import PropTypes from 'prop-types';
import '@testing-library/jest-dom';
import { render, screen, act } from '@testing-library/react';
import PluginSlot from '../../src/plugins/PluginSlot';
import { registerPlugin } from '../../src/plugins/pluginRegistry';

describe('PluginSlot', () => {
it('renders nothing when plugin is not registered', () => {
const { container } = render(<PluginSlot scope="unregistered-scope" props={{}} />);
expect(container).toBeEmptyDOMElement();
});

it('renders the registered component with given props', () => {
const TestComponent = ({ message }) => <span>{message}</span>;
TestComponent.propTypes = { message: PropTypes.string.isRequired };
act(() => registerPlugin('test-scope', TestComponent));

render(<PluginSlot scope="test-scope" props={{ message: 'hello plugin' }} />);
expect(screen.getByText('hello plugin')).toBeInTheDocument();
});
});
Loading