* 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} />);
}