/usr/share/grafana/public/app/plugins/datasource/influxdb/components/editor/config-v2
import '@testing-library/jest-dom'; import { render, screen } from '@testing-library/react'; import { InfluxVersion } from '../../../types'; import { DatabaseConnectionSection } from './DatabaseConnectionSection'; import { createTestProps } from './helpers'; jest.mock('./AdvancedDBConnectionSettings', () => ({ AdvancedDbConnectionSettings: () => <div data-testid="advanced-db-settings" />, })); jest.mock('./InfluxFluxDBConnection', () => ({ InfluxFluxDBConnection: () => <div data-testid="flux-connection" />, })); jest.mock('./InfluxSQLDBConnection', () => ({ InfluxSQLDBConnection: () => <div data-testid="sql-connection" />, })); jest.mock('./InfluxInfluxQLDBConnection', () => ({ InfluxInfluxQLDBConnection: () => <div data-testid="influxql-connection" />, })); describe('DatabaseConnectionSection', () => { const onOptionsChangeMock = jest.fn(); const defaultProps = createTestProps({ options: { jsonData: {}, secureJsonData: {}, secureJsonFields: {}, }, mocks: { onOptionsChange: onOptionsChangeMock, }, }); it('shows alert when version is missing', () => { render(<DatabaseConnectionSection {...defaultProps} />); expect(screen.getByText(/To view connection settings/i)).toBeInTheDocument(); }); it('renders Flux connection component when version is Flux', () => { const props = { ...defaultProps, options: { ...defaultProps.options, jsonData: { version: InfluxVersion.Flux }, }, }; render(<DatabaseConnectionSection {...props} />); expect(screen.getByTestId('flux-connection')).toBeInTheDocument(); }); it('renders InfluxQL connection component when version is InfluxQL', () => { const props = { ...defaultProps, options: { ...defaultProps.options, jsonData: { version: InfluxVersion.InfluxQL }, }, }; render(<DatabaseConnectionSection {...props} />); expect(screen.getByTestId('influxql-connection')).toBeInTheDocument(); }); it('renders SQL connection component when version is SQL', () => { const props = { ...defaultProps, options: { ...defaultProps.options, jsonData: { version: InfluxVersion.SQL }, }, }; render(<DatabaseConnectionSection {...props} />); expect(screen.getByTestId('sql-connection')).toBeInTheDocument(); }); it('always renders AdvancedDbConnectionSettings', () => { const props = { ...defaultProps, options: { ...defaultProps.options, jsonData: { version: InfluxVersion.SQL }, }, }; render(<DatabaseConnectionSection {...props} />); expect(screen.getByTestId('advanced-db-settings')).toBeInTheDocument(); }); });
.
Edit
..
Edit
AdvancedDBConnectionSettings.test.tsx
Edit
AdvancedDBConnectionSettings.tsx
Edit
AdvancedHttpSettings.test.tsx
Edit
AdvancedHttpSettings.tsx
Edit
AuthSettings.test.tsx
Edit
AuthSettings.tsx
Edit
ConfigEditor.test.tsx
Edit
ConfigEditor.tsx
Edit
DatabaseConnectionSection.test.tsx
Edit
DatabaseConnectionSection.tsx
Edit
InfluxFluxDBConnection.test.tsx
Edit
InfluxFluxDBConnection.tsx
Edit
InfluxInfluxQLDBConnection.test.tsx
Edit
InfluxInfluxQLDBConnection.tsx
Edit
InfluxSQLDBConnection.test.tsx
Edit
InfluxSQLDBConnection.tsx
Edit
LeftSideBar.test.tsx
Edit
LeftSideBar.tsx
Edit
UrlAndAuthenticationSection.test.tsx
Edit
UrlAndAuthenticationSection.tsx
Edit
constants.ts
Edit
helpers.ts
Edit
tracking.ts
Edit
types.ts
Edit
versions.ts
Edit