Skip to content

Commit

Permalink
(fix) O3-3139 add mock for useRenderableExtensions + fix its state ty… (
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho authored Apr 30, 2024
1 parent 8085c7a commit f229b58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/framework/esm-react-utils/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const useSession = jest.fn(() => ({

export const useLayoutType = jest.fn(() => 'desktop');

export const useRenderableExtensions = jest.fn(() => []);

export const useAssignedExtensions = jest.fn(() => []);

export const useExtensionSlotMeta = jest.fn(() => ({}));
Expand Down
10 changes: 7 additions & 3 deletions packages/framework/esm-react-utils/src/extensions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ describe('ExtensionSlot, Extension, and useExtensionSlotMeta', () => {
});

test('useRenderableExtensions returns registered extensions', async () => {
registerSimpleExtension('Spanish', 'esm-languages-app', undefined, {
function SpanishExtension({ suffix }) {
return <div>Spanish{suffix}</div>;
}

registerSimpleExtension('Spanish', 'esm-languages-app', SpanishExtension, {
code: 'es',
});
attach('Box', 'Spanish');
Expand All @@ -292,11 +296,11 @@ describe('ExtensionSlot, Extension, and useExtensionSlotMeta', () => {
})(() => {
const extensions = useRenderableExtensions('Box');
const Ext = extensions[0];
return <Ext />;
return <Ext state={{ suffix: ' hola' }} />;
});
render(<App />);

await waitFor(() => expect(screen.getByText('Spanish')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Spanish hola')).toBeInTheDocument());
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useRenderableExtensions(name: string): Array<React.FC<Pick<Exten
const { extensions, extensionSlotModuleName } = useExtensionSlot(name);

return name
? extensions.map((extension) => (state: Record<string, unknown>) => (
? extensions.map((extension) => ({ state }: Pick<ExtensionProps, 'state'>) => (
<ComponentContext.Provider
value={{
moduleName: extensionSlotModuleName, // moduleName is not used by the receiving Extension
Expand Down

0 comments on commit f229b58

Please sign in to comment.