Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): pre fill selector when adding an output #1864

Merged
merged 5 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions web/cypress/e2e/TestRunDetail/Outputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ describe('Outputs', () => {
cy.get('[data-cy=output-add-button]').click();
cy.get('form#testOutput').within(() => {
cy.get('#testOutput_name').type('status_code');
cy.get('[data-cy=selector-editor] [contenteditable=true]').type('span[tracetest.span.type = "http"]:first');
cy.get('[data-cy=selector-editor] [contenteditable=true]')
.clear()
.type('span[tracetest.span.type = "http"]:first');
cy.get('[data-cy=expression-editor] [contenteditable=true]').type('attr:http.status_code');
});
cy.wait('@getSelect');
Expand Down Expand Up @@ -56,7 +58,9 @@ describe('Outputs', () => {
cy.get('[data-cy=output-add-button]').click();
cy.get('form#testOutput').within(() => {
cy.get('#testOutput_name').type('status_code');
cy.get('[data-cy=selector-editor] [contenteditable=true]').type('span[tracetest.span.type = "http"]:first');
cy.get('[data-cy=selector-editor] [contenteditable=true]')
.clear()
.type('span[tracetest.span.type = "http"]:first');
cy.get('[data-cy=expression-editor] [contenteditable=true]').type('attr:http.status_code');
});
cy.wait('@getSelect');
Expand Down
7 changes: 5 additions & 2 deletions web/src/components/TestOutputForm/SelectorInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ const SelectorInput = ({form, runId, spanIdList, testId}: IProps) => {
{required: true, message: 'Please enter a valid selector'},
{
message: 'Please select a single span',
validator: async () => {
if (spanIdList.length !== 1 && !isLoading) throw new Error('Please select a single span');
validator: () => {
if (spanIdList.length !== 1 && !isLoading) {
return Promise.reject(new Error('Please select a single span'));
}
return Promise.resolve();
},
validateTrigger: 'onSubmit',
},
Expand Down
9 changes: 6 additions & 3 deletions web/src/components/TestOutputForm/TestOutputForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Button, Form, Input, Tag} from 'antd';
import {useEffect} from 'react';

import Editor from 'components/Editor';
import {SELECTOR_LANGUAGE_CHEAT_SHEET_URL} from 'constants/Common.constants';
import {EXPRESSIONS_DOCUMENTATION_URL, SELECTOR_LANGUAGE_CHEAT_SHEET_URL} from 'constants/Common.constants';
import {SupportedEditors} from 'constants/Editor.constants';
import {useAppSelector} from 'redux/hooks';
import SpanSelectors from 'selectors/Span.selectors';
Expand All @@ -29,7 +29,7 @@ const TestOutputForm = ({isEditing = false, isLoading = false, onCancel, onSubmi
const selector = Form.useWatch('selector', form) || '';

useEffect(() => {
if (form.getFieldValue('selector')) {
if (form.getFieldValue('selector') && form.getFieldValue('value') && form.getFieldValue('name')) {
onValidate(null, form.getFieldsValue());
form.validateFields();
}
Expand Down Expand Up @@ -67,7 +67,10 @@ const TestOutputForm = ({isEditing = false, isLoading = false, onCancel, onSubmi
<S.FormSection>
<S.FormSectionTitle>2. Select the attribute</S.FormSectionTitle>
<S.FormSectionRow>
<S.FormSectionText>Choose one attribute from the selected span or use an expression</S.FormSectionText>
<S.FormSectionText>Choose one attribute from the selected span or use an </S.FormSectionText>
<a href={EXPRESSIONS_DOCUMENTATION_URL} target="_blank">
expression
</a>
</S.FormSectionRow>
<Form.Item name="value" rules={[{required: true, message: 'Please enter an attribute or expression'}]}>
<Editor
Expand Down
13 changes: 11 additions & 2 deletions web/src/components/TestOutputs/TestOutputs.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import {Button} from 'antd';

import TestOutput from 'components/TestOutput';
import TestOutputModel from 'models/TestOutput.model';
import {useSpan} from 'providers/Span/Span.provider';
import {useTestOutput} from 'providers/TestOutput/TestOutput.provider';
import SpanService from 'services/Span.service';
import {TTestOutput} from 'types/TestOutput.types';
import Empty from './Empty';
import * as S from './TestOutputs.styled';
import {TTestOutput} from '../../types/TestOutput.types';

interface IProps {
outputs: TTestOutput[];
}

const TestOutputs = ({outputs}: IProps) => {
const {onDelete, onOpen} = useTestOutput();
const {selectedSpan} = useSpan();

const handleOnAddTestOutput = () => {
const query = selectedSpan ? SpanService.getSelectorInformation(selectedSpan) : '';
onOpen(TestOutputModel({selector: {query}}));
};

return (
<S.Container>
<S.HeaderContainer>
<Button data-cy="output-add-button" onClick={() => onOpen()} type="primary">
<Button data-cy="output-add-button" onClick={handleOnAddTestOutput} type="primary">
Add Test Output
</Button>
</S.HeaderContainer>
Expand Down
1 change: 1 addition & 0 deletions web/src/constants/Common.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const TRACE_DOCUMENTATION_URL =

export const ADD_TEST_SPECS_DOCUMENTATION_URL = 'https://docs.tracetest.io/web-ui/creating-test-specifications';
export const ADD_TEST_OUTPUTS_DOCUMENTATION_URL = 'https://docs.tracetest.io/web-ui/creating-test-outputs';
export const EXPRESSIONS_DOCUMENTATION_URL = 'https://docs.tracetest.io/concepts/expressions';
export const ENVIRONMENTS_DOCUMENTATION_URL = 'https://docs.tracetest.io/concepts/environments';

export const SELECTOR_LANGUAGE_CHEAT_SHEET_URL = `${process.env.PUBLIC_URL}/SL_cheat_sheet.pdf`;
Expand Down