generated from VolkovLabs/volkovlabs-abc-panel
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update position of Query fields for initial values (#455)
* elements fields updated * remove as unused * Formatting * Update Initial Fields Editor * Update test * tests update * Formatting * Remove unused aria-label * Update CHANGELOG.md --------- Co-authored-by: Mikhail Volkov <mikhail@volkovlabs.io> Co-authored-by: asimonok <sashasimonok@gmail.com>
- Loading branch information
1 parent
a3d79cf
commit d546ecf
Showing
12 changed files
with
250 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/components/InitialFieldsEditor/InitialFieldsEditor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { toDataFrame } from '@grafana/data'; | ||
import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { FORM_ELEMENT_DEFAULT, RequestMethod } from '../../constants'; | ||
import { getInitialFieldsEditorSelectors } from '../../utils'; | ||
import { InitialFieldsEditor } from './InitialFieldsEditor'; | ||
|
||
/** | ||
* Form Elements Editor | ||
*/ | ||
describe('Form Elements Editor', () => { | ||
/** | ||
* OnChange function | ||
*/ | ||
const onChange = jest.fn(); | ||
|
||
/** | ||
* Form Elements Editor Selectors | ||
*/ | ||
const selectors = getInitialFieldsEditorSelectors(screen); | ||
|
||
/** | ||
* Get Tested Component | ||
* @param value | ||
* @param context | ||
* @param restProps | ||
*/ | ||
const getComponent = ({ value = [], context = {}, ...restProps }: any) => { | ||
return <InitialFieldsEditor {...restProps} value={value} context={context} />; | ||
}; | ||
|
||
it('Should render component for Datasource method', async () => { | ||
const elements = [{ ...FORM_ELEMENT_DEFAULT, id: 'id' }]; | ||
render( | ||
getComponent({ | ||
value: elements, | ||
onChange, | ||
context: { options: { initial: { method: RequestMethod.DATASOURCE } } }, | ||
}) | ||
); | ||
|
||
expect(selectors.root()).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should change Field Name', async () => { | ||
const elements = [{ ...FORM_ELEMENT_DEFAULT, id: 'id', fieldName: 'max' }]; | ||
render( | ||
getComponent({ | ||
value: elements, | ||
onChange, | ||
context: { options: { initial: { method: RequestMethod.DATASOURCE } } }, | ||
}) | ||
); | ||
|
||
expect(selectors.root()).toBeInTheDocument(); | ||
|
||
expect(selectors.fieldNamePicker()).toBeInTheDocument(); | ||
expect(selectors.fieldNamePicker()).toHaveValue('max'); | ||
|
||
/** | ||
* Change field name | ||
*/ | ||
await act(() => fireEvent.change(selectors.fieldNamePicker(), { target: { value: 'metric' } })); | ||
|
||
expect(selectors.fieldNamePicker()).toHaveValue('metric'); | ||
}); | ||
|
||
it('Should change Query Name', async () => { | ||
const elements = [{ ...FORM_ELEMENT_DEFAULT, id: 'id' }]; | ||
const context = { | ||
options: { | ||
initial: { | ||
method: RequestMethod.QUERY, | ||
}, | ||
}, | ||
data: [ | ||
toDataFrame({ | ||
fields: [ | ||
{ | ||
name: 'field1', | ||
values: [], | ||
}, | ||
{ | ||
name: 'field2', | ||
values: [], | ||
}, | ||
], | ||
refId: 'A', | ||
}), | ||
], | ||
}; | ||
|
||
render( | ||
getComponent({ | ||
value: elements, | ||
onChange, | ||
context, | ||
}) | ||
); | ||
|
||
expect(selectors.root()).toBeInTheDocument(); | ||
|
||
expect(selectors.fieldNamePicker(true)).not.toBeInTheDocument(); | ||
|
||
expect(selectors.fieldFromQueryPicker()).toHaveValue(''); | ||
|
||
/** | ||
* Change query field name | ||
*/ | ||
await act(() => fireEvent.change(selectors.fieldFromQueryPicker(), { target: { value: 'field1' } })); | ||
|
||
expect(selectors.fieldFromQueryPicker()).toHaveValue('field1'); | ||
}); | ||
}); |
Oops, something went wrong.