Add a test case for PrivateRoute

This commit is contained in:
Hung Viet Nguyen 2022-03-12 17:33:39 +07:00
parent 785c4e862e
commit b03e8e4adb
No known key found for this signature in database
GPG Key ID: CAFDC50535B4A074

View File

@ -54,7 +54,7 @@ describe('PrivateRoute', () => {
expect(screen.getByText('Please login')).toBeInTheDocument();
});
// Visit /settings/application-infos
// Visit /settings/application-infos (no search params)
history.push('/settings/application-infos');
// Should redirected to `/auth/login` and preserve the `/settings/application-infos` path
await waitFor(() => {
@ -65,5 +65,16 @@ describe('PrivateRoute', () => {
);
expect(screen.getByText('Please login')).toBeInTheDocument();
});
// Visit /settings/application-infos (have search params)
history.push('/settings/application-infos?hello=world');
await waitFor(() => {
expect(history.location.pathname).toBe('/auth/login');
// Should preserve search params
expect(history.location.search).toBe(
`?redirectTo=${encodeURIComponent('/settings/application-infos?hello=world')}`
);
expect(screen.getByText('Please login')).toBeInTheDocument();
});
});
});