From ec1480b96452ce705d3c6c6e8cc75e48213f175d Mon Sep 17 00:00:00 2001 From: Seyaji <67058118+Seyaji@users.noreply.github.com> Date: Thu, 23 Jun 2022 12:39:00 +0100 Subject: [PATCH] Chore: Convert DataSourceDashboards test to RTL (#51294) * Convert DataSourceDashboards test to RTL * Convert DataSourceDashboards test to RTL * Convert DataSourceDashboards test to RTL * Update public/app/features/datasources/DataSourceDashboards.test.tsx Co-authored-by: Alex Khomenko * Convert DataSourceDashboards test to RTL Co-authored-by: Alex Khomenko --- .betterer.results | 3 --- .../datasources/DataSourceDashboards.test.tsx | 27 ++++++++++++------- .../DataSourceDashboards.test.tsx.snap | 17 ------------ 3 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 public/app/features/datasources/__snapshots__/DataSourceDashboards.test.tsx.snap diff --git a/.betterer.results b/.betterer.results index 20907adc198..1839f7f2b89 100644 --- a/.betterer.results +++ b/.betterer.results @@ -95,9 +95,6 @@ exports[`no enzyme tests`] = { "public/app/features/dashboard/dashgrid/DashboardGrid.test.tsx:2723773538": [ [0, 35, 13, "RegExp match", "2409514259"] ], - "public/app/features/datasources/DataSourceDashboards.test.tsx:1369048021": [ - [0, 19, 13, "RegExp match", "2409514259"] - ], "public/app/features/dimensions/editors/ThresholdsEditor/ThresholdsEditor.test.tsx:4164297658": [ [0, 17, 13, "RegExp match", "2409514259"] ], diff --git a/public/app/features/datasources/DataSourceDashboards.test.tsx b/public/app/features/datasources/DataSourceDashboards.test.tsx index 516b90f6570..f90ad2b1a2b 100644 --- a/public/app/features/datasources/DataSourceDashboards.test.tsx +++ b/public/app/features/datasources/DataSourceDashboards.test.tsx @@ -1,16 +1,17 @@ -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import React from 'react'; -import { DataSourceSettings, NavModel } from '@grafana/data'; +import { DataSourceSettings } from '@grafana/data'; import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps'; +import { RouteDescriptor } from 'app/core/navigation/types'; import { PluginDashboard } from 'app/types'; import { DataSourceDashboards, Props } from './DataSourceDashboards'; -const setup = (propOverrides?: object) => { +const setup = (propOverrides?: Partial) => { const props: Props = { ...getRouteComponentProps(), - navModel: {} as NavModel, + navModel: { main: { text: 'nav-text' }, node: { text: 'node-text' } }, dashboards: [] as PluginDashboard[], dataSource: {} as DataSourceSettings, dataSourceId: 'x', @@ -18,18 +19,26 @@ const setup = (propOverrides?: object) => { loadDataSource: jest.fn(), loadPluginDashboards: jest.fn(), removeDashboard: jest.fn(), + route: {} as RouteDescriptor, isLoading: false, + ...propOverrides, }; - Object.assign(props, propOverrides); - - return shallow(); + return render(); }; describe('Render', () => { + it('should render without exploding', () => { + expect(() => setup()).not.toThrow(); + }); it('should render component', () => { - const wrapper = setup(); + setup(); - expect(wrapper).toMatchSnapshot(); + expect(screen.getByRole('heading', { name: 'nav-text' })).toBeInTheDocument(); + expect(screen.getByRole('table')).toBeInTheDocument(); + expect(screen.getByRole('list')).toBeInTheDocument(); + expect(screen.getByRole('link', { name: 'Documentation' })).toBeInTheDocument(); + expect(screen.getByRole('link', { name: 'Support' })).toBeInTheDocument(); + expect(screen.getByRole('link', { name: 'Community' })).toBeInTheDocument(); }); }); diff --git a/public/app/features/datasources/__snapshots__/DataSourceDashboards.test.tsx.snap b/public/app/features/datasources/__snapshots__/DataSourceDashboards.test.tsx.snap deleted file mode 100644 index 28b20de8a18..00000000000 --- a/public/app/features/datasources/__snapshots__/DataSourceDashboards.test.tsx.snap +++ /dev/null @@ -1,17 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Render should render component 1`] = ` - - - - - -`;