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 React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import { CustomHeadersSettings, Props } from './CustomHeadersSettings'; import { CustomHeadersSettings, Props } from './CustomHeadersSettings';
import { Button } from '../Button';
const setup = (propOverrides?: object) => { const setup = (propOverrides?: object) => {
const props: Props = { const props: Props = {
@ -48,6 +49,11 @@ describe('Render', () => {
expect(wrapper.find('SecretFormField').exists()).toBeTruthy(); 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', () => { it('should remove a header', () => {
const wrapper = setup({ const wrapper = setup({
dataSourceConfig: { dataSourceConfig: {

View File

@ -206,6 +206,7 @@ export class CustomHeadersSettings extends PureComponent<Props, State> {
<Button <Button
variant="secondary" variant="secondary"
icon="plus" icon="plus"
type="button"
onClick={(e) => { onClick={(e) => {
this.onHeaderAdd(); 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( expect(wrapper.find(Button).filterWhere((button: any) => button.contains('Show example log message')).length).toBe(
1 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); expect(wrapper.find(DerivedField).length).toBe(2);
}); });

View File

@ -82,7 +82,7 @@ export const DerivedFields = (props: Props) => {
</Button> </Button>
{value && value.length > 0 && ( {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'} {showDebug ? 'Hide example log message' : 'Show example log message'}
</Button> </Button>
)} )}