mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
import React from 'react';
|
|
import get from 'lodash/get';
|
|
import { useDispatch } from 'react-redux';
|
|
import CodeEditor from 'components/CodeEditor';
|
|
import { updateRequestTests } from 'providers/ReduxStore/slices/collections';
|
|
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
|
import { useTheme } from 'providers/Theme';
|
|
import { usePreferences } from 'providers/Preferences';
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
const Tests = ({ item, collection }) => {
|
|
const dispatch = useDispatch();
|
|
const tests = item.draft ? get(item, 'draft.request.tests') : get(item, 'request.tests');
|
|
|
|
const { storedTheme } = useTheme();
|
|
const { preferences } = usePreferences();
|
|
|
|
const onEdit = (value) => {
|
|
dispatch(
|
|
updateRequestTests({
|
|
tests: value,
|
|
itemUid: item.uid,
|
|
collectionUid: collection.uid
|
|
})
|
|
);
|
|
};
|
|
|
|
const onRun = () => dispatch(sendRequest(item, collection.uid));
|
|
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));
|
|
|
|
return (
|
|
<StyledWrapper className="w-full">
|
|
<CodeEditor
|
|
collection={collection}
|
|
value={tests || ''}
|
|
theme={storedTheme}
|
|
font={preferences.codeFont}
|
|
onEdit={onEdit}
|
|
mode="javascript"
|
|
onRun={onRun}
|
|
onSave={onSave}
|
|
/>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default Tests;
|