From: Jeremy Davis Date: Wed, 30 Aug 2023 12:11:27 +0000 (+0200) Subject: SONAR-20254 Migrate Landing test to RTL X-Git-Tag: 10.2.0.77647~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aec07e789036963ec9d29b48cf7bdfc03d83c290;p=sonarqube.git SONAR-20254 Migrate Landing test to RTL --- diff --git a/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx index 6b308885d7a..237ce80fc22 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx @@ -17,26 +17,30 @@ * 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 = {}) { - return shallow(); +function renderLanding(props: Partial = {}) { + return renderApp('/', ); }