Skip to content

Commit

Permalink
✅ Fix bad wrapper for MenuItem featureUuid tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariush2 committed Jan 15, 2025
1 parent 98f871f commit c0146b7
Showing 1 changed file with 26 additions and 42 deletions.
68 changes: 26 additions & 42 deletions src/organisms/SideBar/MenuItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ const wrapper = ({ children }: { children: ReactNode }) => {
);
};

const featureTestWrapper = ({ children }: { children: ReactNode }) => {
const queryClient = new QueryClient();

return (
<QueryClientProvider client={queryClient}>
<AuthProvider>
<FeatureToggleProvider>
<LoadingProvider>
<MemoryRouter initialEntries={['/']}>
<Routes>
<Route
path="/"
element={<SideBarProvider>{children}</SideBarProvider>}
/>
<Route path="/page1" element={<p>Page 1</p>} />
</Routes>
</MemoryRouter>
</LoadingProvider>
</FeatureToggleProvider>
</AuthProvider>
</QueryClientProvider>
);
};

test('should navigate if replace is set to true and url is a partial match', () => {
const props = fakeProps();
render(<MenuItem {...props} replace />, {
Expand All @@ -50,26 +74,7 @@ test('should hide if featureUuid is not in my features', () => {
const props = fakeProps();
const someRandomUuid = faker.string.uuid();
render(<MenuItem {...props} featureUuid={someRandomUuid} />, {
wrapper: ({ children }: { children: ReactNode }) => {
const queryClient = new QueryClient();
return (
<QueryClientProvider client={queryClient}>
<FeatureToggleProvider>
<LoadingProvider>
<MemoryRouter initialEntries={['/']}>
<Routes>
<Route
path="/"
element={<SideBarProvider>{children}</SideBarProvider>}
/>
<Route path="/page1" element={<p>Page 1</p>} />
</Routes>
</MemoryRouter>
</LoadingProvider>
</FeatureToggleProvider>
</QueryClientProvider>
);
},
wrapper: featureTestWrapper,
});

expect(screen.queryByTestId('sidebar-menu-item')).not.toBeInTheDocument();
Expand All @@ -78,28 +83,7 @@ test('should hide if featureUuid is not in my features', () => {
test('should show if featureUuid is in my features', async () => {
const props = fakeProps();
render(<MenuItem {...props} featureUuid={FAKE_FEATURE_TOGGLES[0].uuid} />, {
wrapper: ({ children }: { children: ReactNode }) => {
const queryClient = new QueryClient();
return (
<QueryClientProvider client={queryClient}>
<AuthProvider>
<FeatureToggleProvider>
<LoadingProvider>
<MemoryRouter initialEntries={['/']}>
<Routes>
<Route
path="/"
element={<SideBarProvider>{children}</SideBarProvider>}
/>
<Route path="/page1" element={<p>Page 1</p>} />
</Routes>
</MemoryRouter>
</LoadingProvider>
</FeatureToggleProvider>
</AuthProvider>
</QueryClientProvider>
);
},
wrapper: featureTestWrapper,
});
await waitForElementToBeRemoved(() => screen.getByRole('progressbar'), {
timeout: 5000,
Expand Down

0 comments on commit c0146b7

Please sign in to comment.