Prevent submitting the datasource form in Loki's datasource configuration page (#31823)

This commit is contained in:
Piotr Jamróz 2021-03-12 09:25:41 +01:00 committed by GitHub
parent c764bca58f
commit d0fa7b81f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import React from 'react';
import { mount } from 'enzyme';
import { CustomHeadersSettings, Props } from './CustomHeadersSettings';
import { Button } from '../Button';
const setup = (propOverrides?: object) => {
const props: Props = {
@ -48,6 +49,11 @@ describe('Render', () => {
expect(wrapper.find('SecretFormField').exists()).toBeTruthy();
});
it('add header button should not submit the form', () => {
const wrapper = setup();
expect(wrapper.find(Button).getDOMNode()).toHaveAttribute('type', 'button');
});
it('should remove a header', () => {
const wrapper = setup({
dataSourceConfig: {

View File

@ -206,6 +206,7 @@ export class CustomHeadersSettings extends PureComponent<Props, State> {
<Button
variant="secondary"
icon="plus"
type="button"
onClick={(e) => {
this.onHeaderAdd();
}}

View File

@ -38,6 +38,12 @@ describe('DerivedFields', () => {
expect(wrapper.find(Button).filterWhere((button: any) => button.contains('Show example log message')).length).toBe(
1
);
expect(
wrapper
.find(Button)
.filterWhere((button: any) => button.contains('Show example log message'))
.getDOMNode()
).toHaveAttribute('type', 'button');
expect(wrapper.find(DerivedField).length).toBe(2);
});

View File

@ -82,7 +82,7 @@ export const DerivedFields = (props: Props) => {
</Button>
{value && value.length > 0 && (
<Button variant="secondary" onClick={() => setShowDebug(!showDebug)}>
<Button variant="secondary" type="button" onClick={() => setShowDebug(!showDebug)}>
{showDebug ? 'Hide example log message' : 'Show example log message'}
</Button>
)}