Skip to content

Commit

Permalink
test: growthbook provider to form test renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasdc authored and ccbc-service-account committed Dec 4, 2024
1 parent 62e35b3 commit 98d3673
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions app/tests/utils/formTestRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtim
import { useRef, useState } from 'react';
import { IChangeEvent } from '@rjsf/core';
import { FormBaseRef } from 'components/Form/FormBase';
import { GrowthBookProvider } from '@growthbook/growthbook-react';
import createMockRouter from './mockNextRouter';
import mockGrowthBook from './mockGrowthBook';

type Props = {
formData: any;
Expand Down Expand Up @@ -44,27 +46,29 @@ const FormTestRenderer: React.FC<Props> = ({

return (
<RelayEnvironmentProvider environment={env}>
<GlobalTheme>
<RouterContext.Provider value={createMockRouter()}>
<UnsavedChangesProvider>
<FormBase
ref={formRef}
theme={defaultTheme}
formData={formState}
onSubmit={handleSubmit}
schema={schema as RJSFSchema}
uiSchema={uiSchema}
formContext={formContext}
onChange={(e: IChangeEvent) => setFormState(e.formData)}
>
<button type="submit">Submit</button>
<button type="button" onClick={() => setFormState({})}>
Cancel
</button>
</FormBase>
</UnsavedChangesProvider>
</RouterContext.Provider>
</GlobalTheme>
<GrowthBookProvider growthbook={mockGrowthBook as any}>
<GlobalTheme>
<RouterContext.Provider value={createMockRouter()}>
<UnsavedChangesProvider>
<FormBase
ref={formRef}
theme={defaultTheme}
formData={formState}
onSubmit={handleSubmit}
schema={schema as RJSFSchema}
uiSchema={uiSchema}
formContext={formContext}
onChange={(e: IChangeEvent) => setFormState(e.formData)}
>
<button type="submit">Submit</button>
<button type="button" onClick={() => setFormState({})}>
Cancel
</button>
</FormBase>
</UnsavedChangesProvider>
</RouterContext.Provider>
</GlobalTheme>
</GrowthBookProvider>
</RelayEnvironmentProvider>
);
};
Expand Down

0 comments on commit 98d3673

Please sign in to comment.