Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Nov 6, 2023
1 parent cb41337 commit f661d7c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/react-utils/src/helpers/tests/componentUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import flushPromises from 'flush-promises';
import fetch from 'jest-fetch-mock';
import { superUserRole } from '../test-utils';
import { RbacProvider, RoleContext, UserRole } from '@opensrp/rbac';
import { render } from '@testing-library/react';
import { createMemoryHistory } from 'history';

const { PublicComponent, PrivateComponent, isAuthorized } = componentUtils;

Expand Down Expand Up @@ -44,6 +46,35 @@ describe('componentUtils', () => {
wrapper.unmount();
});

it('First check that user is logged in before Rbac', async () => {
const MockComponent = () => {
return <p>I love oof!</p>;
};
const history = createMemoryHistory();
const props = {
component: MockComponent,
redirectPath: '/login',
disableLoginProtection: false,
};

render(
<Provider store={store}>
<Router history={history}>
<RbacProvider value={superUserRole}>
<PrivateComponent {...props} component={MockComponent} permissions={[]} />
</RbacProvider>
</Router>
</Provider>
);
await act(async () => {
await flushPromises();
});

// should redirect non-AuthN'd users to login
expect(history.location.pathname).toEqual('/login');
expect(history.location.search).toEqual('?next=');
});

it('PrivateComponent Renders correctly', async () => {
store.dispatch(
authenticateUser(
Expand Down

0 comments on commit f661d7c

Please sign in to comment.