Просмотр исходного кода

SONAR-20254 Migrate Landing test to RTL

tags/10.2.0.77647
Jeremy Davis 9 месяцев назад
Родитель
Сommit
aec07e7890
1 измененных файлов: 17 добавлений и 13 удалений
  1. 17
    13
      server/sonar-web/src/main/js/app/components/__tests__/Landing-test.tsx

+ 17
- 13
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<LandingProps> = {}) {
return shallow<LandingProps>(<Landing currentUser={mockCurrentUser()} {...props} />);
function renderLanding(props: Partial<LandingProps> = {}) {
return renderApp('/', <Landing currentUser={mockCurrentUser()} {...props} />);
}

Загрузка…
Отмена
Сохранить