]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20254 Migrate Landing test to RTL
authorJeremy Davis <jeremy.davis@sonarsource.com>
Wed, 30 Aug 2023 12:11:27 +0000 (14:11 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 30 Aug 2023 20:03:07 +0000 (20:03 +0000)
server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx

index 6b308885d7a8c0f923430d06385cc7c25cbe8ea0..237ce80fc220a42b4344678a19b377f00914645d 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { shallow } from 'enzyme';
 import * as React from 'react';
-import { Navigate } from 'react-router-dom';
 import { mockCurrentUser, mockLoggedInUser } from '../../../helpers/testMocks';
+import { renderApp } from '../../../helpers/testReactTestingUtils';
+import { byText } from '../../../helpers/testSelector';
 import { CurrentUser } from '../../../types/users';
 import { Landing, LandingProps } from '../Landing';
 
 it.each([
-  [mockCurrentUser(), '/projects'],
-  [mockLoggedInUser(), '/projects'],
-  [
-    mockLoggedInUser({ homepage: { type: 'ISSUES' } }),
-    expect.objectContaining({ pathname: '/issues' }),
-  ],
-])('should render correctly', (currentUser: CurrentUser, expected: string) => {
-  const wrapper = shallowRender({ currentUser });
+  ['user not logged in', mockCurrentUser()],
+  ['user has no homepage', mockLoggedInUser({ homepage: undefined })],
+])('should redirect to projects (%s)', (_, currentUser: CurrentUser) => {
+  renderLanding({ currentUser });
+  expect(byText('/projects').get()).toBeInTheDocument();
+});
 
-  expect(wrapper.find(Navigate).props().to).toEqual(expected);
+it('should redirect to homepage', () => {
+  renderLanding({
+    currentUser: mockLoggedInUser({
+      homepage: { type: 'PROJECT', branch: undefined, component: 'pk1' },
+    }),
+  });
+  expect(byText('/dashboard?id=pk1').get()).toBeInTheDocument();
 });
 
-function shallowRender(props: Partial<LandingProps> = {}) {
-  return shallow<LandingProps>(<Landing currentUser={mockCurrentUser()} {...props} />);
+function renderLanding(props: Partial<LandingProps> = {}) {
+  return renderApp('/', <Landing currentUser={mockCurrentUser()} {...props} />);
 }