From 701edcdc46271090d6f3119c37a0afee415a1f9d Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Tue, 14 Jun 2022 11:39:43 +0300 Subject: [PATCH] UserListPage: Convert tests to RTL (#50717) --- .betterer.results | 3 - .../app/features/users/UsersListPage.test.tsx | 35 +++++----- public/app/features/users/UsersListPage.tsx | 2 +- .../__snapshots__/UsersListPage.test.tsx.snap | 69 ------------------- 4 files changed, 19 insertions(+), 90 deletions(-) delete mode 100644 public/app/features/users/__snapshots__/UsersListPage.test.tsx.snap diff --git a/.betterer.results b/.betterer.results index 2ddef2a2f99..d72ef859fbb 100644 --- a/.betterer.results +++ b/.betterer.results @@ -143,9 +143,6 @@ exports[`no enzyme tests`] = { "public/app/features/org/OrgDetailsPage.test.tsx:3835042085": [ [0, 19, 13, "RegExp match", "2409514259"] ], - "public/app/features/users/UsersListPage.test.tsx:2518052139": [ - [0, 19, 13, "RegExp match", "2409514259"] - ], "public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:227258837": [ [0, 19, 13, "RegExp match", "2409514259"] ], diff --git a/public/app/features/users/UsersListPage.test.tsx b/public/app/features/users/UsersListPage.test.tsx index e5a2837e98f..48490f59539 100644 --- a/public/app/features/users/UsersListPage.test.tsx +++ b/public/app/features/users/UsersListPage.test.tsx @@ -1,8 +1,10 @@ -import { shallow } from 'enzyme'; +import { render } from '@testing-library/react'; import React from 'react'; +import { Provider } from 'react-redux'; import { mockToolkitActionCreator } from 'test/core/redux/mocks'; import { NavModel } from '@grafana/data'; +import { configureStore } from 'app/store/configureStore'; import { Invitee, OrgUser } from 'app/types'; import { Props, UsersListPage } from './UsersListPage'; @@ -12,13 +14,16 @@ jest.mock('../../core/app_events', () => ({ emit: jest.fn(), })); -jest.mock('app/core/services/context_srv', () => ({ +jest.mock('app/core/core', () => ({ contextSrv: { user: { orgId: 1 }, + hasAccess: () => false, + licensedAccessControlEnabled: () => false, }, })); const setup = (propOverrides?: object) => { + const store = configureStore(); const props: Props = { navModel: { main: { @@ -44,27 +49,23 @@ const setup = (propOverrides?: object) => { Object.assign(props, propOverrides); - const wrapper = shallow(); - const instance = wrapper.instance() as UsersListPage; - - return { - wrapper, - instance, - }; + render( + + + + ); }; describe('Render', () => { it('should render component', () => { - const { wrapper } = setup(); - - expect(wrapper).toMatchSnapshot(); + expect(setup).not.toThrow(); }); it('should render List page', () => { - const { wrapper } = setup({ - hasFetched: true, - }); - - expect(wrapper).toMatchSnapshot(); + expect(() => + setup({ + hasFetched: true, + }) + ).not.toThrow(); }); }); diff --git a/public/app/features/users/UsersListPage.tsx b/public/app/features/users/UsersListPage.tsx index 803deead884..6205a86a7c1 100644 --- a/public/app/features/users/UsersListPage.tsx +++ b/public/app/features/users/UsersListPage.tsx @@ -4,8 +4,8 @@ import { connect, ConnectedProps } from 'react-redux'; import { renderMarkdown } from '@grafana/data'; import { HorizontalGroup, Pagination, VerticalGroup } from '@grafana/ui'; import Page from 'app/core/components/Page/Page'; +import { contextSrv } from 'app/core/core'; import { getNavModel } from 'app/core/selectors/navModel'; -import { contextSrv } from 'app/core/services/context_srv'; import { OrgUser, OrgRole, StoreState } from 'app/types'; import InviteesTable from '../invites/InviteesTable'; diff --git a/public/app/features/users/__snapshots__/UsersListPage.test.tsx.snap b/public/app/features/users/__snapshots__/UsersListPage.test.tsx.snap deleted file mode 100644 index 01d1dbeeba2..00000000000 --- a/public/app/features/users/__snapshots__/UsersListPage.test.tsx.snap +++ /dev/null @@ -1,69 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Render should render List page 1`] = ` - - - - - - - - - - - -`; - -exports[`Render should render component 1`] = ` - - - - - -`;