-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
295 additions
and
137 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
32 changes: 32 additions & 0 deletions
32
web/src/components/Inputs/Editor/Definition/Definition.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,32 @@ | ||
import CodeMirror from '@uiw/react-codemirror'; | ||
import {StreamLanguage} from '@codemirror/language'; | ||
import {yaml} from '@codemirror/legacy-modes/mode/yaml'; | ||
import {IEditorProps} from '../Editor'; | ||
|
||
const placeholder = `type: Test | ||
spec: | ||
name: My Test | ||
trigger: | ||
type: http | ||
httpRequest: | ||
method: GET | ||
url: google.com | ||
`; | ||
|
||
const Definition = ({value, onChange}: IEditorProps) => { | ||
return ( | ||
<CodeMirror | ||
value={value} | ||
onChange={onChange} | ||
data-cy="definition-editor" | ||
basicSetup={{indentOnInput: true}} | ||
extensions={[StreamLanguage.define(yaml)]} | ||
spellCheck={false} | ||
placeholder={placeholder} | ||
minHeight="200px" | ||
autoFocus | ||
/> | ||
); | ||
}; | ||
|
||
export default Definition; |
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,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export {default} from './Definition'; |
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
31 changes: 31 additions & 0 deletions
31
web/src/components/TestPlugins/Imports/Definition/Definition.styled.ts
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,31 @@ | ||
import {DeleteOutlined} from '@ant-design/icons'; | ||
import {Typography} from 'antd'; | ||
import styled from 'styled-components'; | ||
|
||
export const Row = styled.div` | ||
display: flex; | ||
`; | ||
|
||
export const Label = styled(Typography.Text).attrs({as: 'div'})` | ||
margin-bottom: 8px; | ||
`; | ||
|
||
export const URLInputContainer = styled.div` | ||
display: flex; | ||
align-items: flex-start; | ||
.ant-form-item { | ||
margin: 0; | ||
} | ||
`; | ||
|
||
export const HeaderContainer = styled.div` | ||
align-items: center; | ||
display: flex; | ||
margin-bottom: 8px; | ||
`; | ||
|
||
export const DeleteIcon = styled(DeleteOutlined)` | ||
color: ${({theme}) => theme.color.textSecondary}; | ||
font-size: ${({theme}) => theme.size.md}; | ||
`; |
28 changes: 28 additions & 0 deletions
28
web/src/components/TestPlugins/Imports/Definition/Definition.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,28 @@ | ||
import {Form} from 'antd'; | ||
import {Editor} from 'components/Inputs'; | ||
import {SupportedEditors} from 'constants/Editor.constants'; | ||
import DefinitionService from 'services/Importers/Definition.service'; | ||
|
||
const Definition = () => { | ||
return ( | ||
<Form.Item | ||
label="Paste Tracetest Definition" | ||
name="definition" | ||
rules={[ | ||
{required: true, message: 'Please enter a valid Tracetest Definition'}, | ||
{ | ||
validator: (_, definition) => { | ||
const errors = DefinitionService.validate(definition); | ||
if (errors.length) return Promise.reject(new Error(errors.join(', '))); | ||
|
||
return Promise.resolve(); | ||
}, | ||
}, | ||
]} | ||
> | ||
<Editor type={SupportedEditors.Definition} /> | ||
</Form.Item> | ||
); | ||
}; | ||
|
||
export default Definition; |
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,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export {default} from './Definition'; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {load} from 'js-yaml'; | ||
import {IDefinitionValues, IImportService} from 'types/Test.types'; | ||
import {TriggerTypeToPlugin} from 'constants/Plugins.constants'; | ||
import Test, {TRawTestResource} from 'models/Test.model'; | ||
import TestService from '../Test.service'; | ||
import {isJson} from '../../utils/Common'; | ||
|
||
interface IDefinitionImportService extends IImportService { | ||
validate(definition: string): string[]; | ||
load(raw: string): TRawTestResource; | ||
} | ||
|
||
const DefinitionImportService = (): IDefinitionImportService => ({ | ||
async getRequest(values) { | ||
const {definition} = values as IDefinitionValues; | ||
|
||
const test = Test.FromDefinition(definition); | ||
return TestService.getInitialValues(test); | ||
}, | ||
|
||
async validateDraft(draft) { | ||
const {definition} = draft as IDefinitionValues; | ||
|
||
return !this.validate(definition).length; | ||
}, | ||
|
||
getPlugin(draft) { | ||
const {definition} = draft as IDefinitionValues; | ||
const {spec = {}}: TRawTestResource = this.load(definition); | ||
|
||
const triggerType = spec.trigger?.type; | ||
return TriggerTypeToPlugin[triggerType!]; | ||
}, | ||
|
||
load(raw) { | ||
if (isJson(raw)) return JSON.parse(raw) as TRawTestResource; | ||
|
||
return load(raw) as TRawTestResource; | ||
}, | ||
|
||
validate(raw) { | ||
const {type, spec = {}}: TRawTestResource = this.load(raw); | ||
const errors = []; | ||
|
||
if (type !== 'Test') { | ||
errors.push(`Invalid type: ${type}`); | ||
} | ||
|
||
if (!spec.name) { | ||
errors.push(`Missing Name`); | ||
} | ||
|
||
if (!spec.trigger) { | ||
errors.push(`Missing trigger`); | ||
} | ||
|
||
if (!spec.trigger?.type) { | ||
errors.push('Missing trigger type'); | ||
} | ||
|
||
return errors; | ||
}, | ||
}); | ||
|
||
export default DefinitionImportService(); |
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