Skip to content

Commit cad9418

Browse files
committed
fixup! fixup! refactor: Use dynamic slot ids for pluggable pages.
1 parent f97d2b3 commit cad9418

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/plugin-routes.test.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getConfig } from '@edx/frontend-platform';
2-
import { render } from '@testing-library/react';
2+
import { render,screen } from '@testing-library/react';
33
import React from 'react';
44
import { getPluginRoutes } from './plugin-routes';
55

@@ -18,31 +18,33 @@ jest.mock('./decode-page-route', () => ({
1818
}));
1919

2020
jest.mock('@openedx/frontend-plugin-framework', () => ({
21-
PluginSlot: ({ id, pluginProps }: { id: string; pluginProps: Record<string, any> }) => (
22-
<div data-testid="plugin-slot" data-route={pluginProps.route}>
23-
id: {id}, route: {pluginProps.route}
21+
PluginSlot: ({ id }: { id: string }) => (
22+
<div data-testid="plugin-slot" data-plugin-id={id}>
23+
id: {id}
2424
</div>
2525
),
2626
}));
2727

2828
describe('getPluginRoutes', () => {
2929
it('should return a valid route element for each plugin route', () => {
30-
const pluginRoutes = ['/route-1', '/route-2'];
30+
const pluginRoutes = [
31+
{id: 'route-1', route: '/route-1'},
32+
{id: 'route-2', route: '/route-2'},
33+
];
3134
(getConfig as jest.Mock).mockImplementation(() => ({
3235
PLUGIN_ROUTES: pluginRoutes,
3336
}));
3437

35-
const result = getPluginRoutes();
36-
const { container } = render(<>{result}</>);
38+
const { container } = render(getPluginRoutes());
3739

38-
pluginRoutes.forEach((route) => {
39-
expect(container.querySelector(`[data-route="${route}"]`)).toBeInTheDocument();
40+
pluginRoutes.forEach(({id}) => {
41+
expect(container.querySelector(`[data-plugin-id="org.openedx.frontend.learning.course_page.${id}.v1"]`)).toBeInTheDocument();
4042
});
4143
expect(container.querySelectorAll('[data-testid="plugin-slot"]').length).toBe(pluginRoutes.length);
4244
});
4345

4446
it('should return null if no plugin routes are configured', () => {
45-
(getConfig as jest.Mock).mockImplementation(() => ({}));
47+
(getConfig as jest.Mock).mockImplementation(() => ([]));
4648

4749
const result = getPluginRoutes();
4850
expect(result).toBeNull();

0 commit comments

Comments
 (0)