From b03e8e4adb43be2668302056aa03f00893c6494e Mon Sep 17 00:00:00 2001 From: Hung Viet Nguyen Date: Sat, 12 Mar 2022 17:33:39 +0700 Subject: [PATCH] Add a test case for PrivateRoute --- .../src/components/PrivateRoute/tests/index.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/admin/admin/src/components/PrivateRoute/tests/index.test.js b/packages/core/admin/admin/src/components/PrivateRoute/tests/index.test.js index 73d5711065..fb7de9a55a 100644 --- a/packages/core/admin/admin/src/components/PrivateRoute/tests/index.test.js +++ b/packages/core/admin/admin/src/components/PrivateRoute/tests/index.test.js @@ -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(); + }); }); });