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

💅🏽 461 [New UX] Trace View # 3 (Test Results) #477

Merged
merged 2 commits into from
May 11, 2022
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
4 changes: 2 additions & 2 deletions web/cypress/integration/Trace/CreateAssertion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('Create Assertion', () => {
cy.get('#add-assertion-modal-ok-button').click();

cy.get('[data-cy=assertion-table]').should('have.lengthOf', 2);
cy.get('[data-cy=assertion-check-property]').should('have.lengthOf', 3);
});

it('should update an assertion', () => {
Expand All @@ -84,6 +83,7 @@ describe('Create Assertion', () => {
cy.get('#add-assertion-modal-ok-button').click();

cy.get('[data-cy=assertion-table]').should('have.lengthOf', 2);
cy.get('[data-cy=assertion-check-property]').should('have.lengthOf', 4);

cy.get('[data-cy=test-results-assertion-table]').should('have.lengthOf', 2);
});
});
3 changes: 1 addition & 2 deletions web/cypress/integration/Trace/ShowTrace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Show Trace', () => {
cy.get('[data-cy=span-details-attributes]').should('be.visible');
cy.get('[data-cy=empty-assertion-table]').should('be.visible');

cy.get('[id*=tab-test-results').click();
cy.get('[data-cy=test-results]').should('be.visible');
cy.get('[data-cy=test-results]').should('exist');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test results its only partially displayed when the trace view loads

});
});
6 changes: 0 additions & 6 deletions web/src/App.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ body {
background: #fbfbff;
}

.ant-typography {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a wrong move, it was overwriting the color for the whole app 🥴

&& {
color: #031849;
}
}

#root {
display: flex;
flex-direction: column;
Expand Down
1 change: 1 addition & 0 deletions web/src/components/TestHeader/TestHeader.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const TestUrl = styled(Typography.Text).attrs({
})`
&& {
margin: 0;
align-self: flex-end;
}
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {Typography} from 'antd';
import styled, {css} from 'styled-components';
import noResultsIcon from '../../assets/SpanAssertionsEmptyState.svg';

export const Header = styled.div`
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
`;

export const TraceHeader = styled.div<{visiblePortion: number}>`
export const Header = styled.div<{visiblePortion: number}>`
display: flex;
align-items: center;
align-content: center;
Expand All @@ -20,12 +12,25 @@ export const TraceHeader = styled.div<{visiblePortion: number}>`
css`
height: ${props.visiblePortion}px;
`}
margin: 0 16px;
padding: 0 24px;
color: rgb(213, 215, 224);
`;

export const HeaderText = styled(Typography.Text)``;

export const StartDateText = styled(Typography.Text)`
&& {
margin-left: 14px;
margin-right: 40px;
font-size: 12px;
}
`;

export const CountNumber = styled.span`
margin-right: 15px;
`;

export const Container = styled.div`
padding: 24px;
border: 1px solid rgba(0, 0, 0, 0.06);
margin-bottom: 16px;
overflow-y: auto;
Expand All @@ -44,25 +49,6 @@ export const EmptyStateIcon = styled.img.attrs({
src: noResultsIcon,
})``;

export const TraceContainer = styled.div<{height: string}>`
display: flex;
width: 100%;
min-height: ${props => props.height};
max-height: ${props => props.height};
height: ${props => props.height};
`;

export const LeftContainer = styled.div`
flex-basis: 50%;
padding-top: 10px;
padding-left: 10px;
`;

export const RightContainer = styled.div`
display: flex;
flex-basis: 50%;
width: 100%;
flex-grow: 1;
padding-top: 10px;
padding-left: 10px;
export const Content = styled.div`
padding: 24px;
`;
94 changes: 94 additions & 0 deletions web/src/components/TestResults/TestResults.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {Badge, Typography} from 'antd';
import {useSelector} from 'react-redux';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving it to its own component folder

import {format, parseISO} from 'date-fns';
import SkeletonTable from 'components/SkeletonTable';
import {FC, Dispatch, PointerEventHandler, useMemo, SetStateAction, useEffect} from 'react';
import * as S from './TestResults.styled';
import TestResultSelectors from '../../selectors/TestResult.selectors';
import TraceService from '../../services/Trace.service';
import TraceAssertionsResultTable from '../TraceAssertionsTable/TraceAssertionsTable';
import {useElementSize} from '../../hooks/useElementSize';
import {useDoubleClick} from '../../hooks/useDoubleClick';
import GuidedTourService, {GuidedTours} from '../../services/GuidedTour.service';
import {Steps} from '../GuidedTour/traceStepList';
import {ITestRunResult} from '../../types/TestRunResult.types';

type TTestResultsProps = {
result: ITestRunResult;
onPointerDown?: PointerEventHandler;
visiblePortion: number;
setMax: Dispatch<SetStateAction<number>>;
max: number;
height?: number;
setHeight?: Dispatch<SetStateAction<number>>;
onSpanSelected(spanId: string): void;
};

const TestResults: FC<TTestResultsProps> = ({
result: {resultId, trace, createdAt},
onSpanSelected,
setMax,
setHeight,
visiblePortion,
onPointerDown,
...props
}) => {
const [squareRef, {height}] = useElementSize();
useEffect(() => setMax(height), [height, setMax]);

const traceResultList = useSelector(TestResultSelectors.selectTestResultList(resultId));
const totalSpanCount = trace?.spans.length;
const totalAssertionCount = traceResultList.length || 0;

const {totalPassedCount, totalFailedCount} = useMemo(
() => TraceService.getTestResultCount(traceResultList),
[traceResultList]
);

const startDate = format(parseISO(createdAt), "EEEE, do MMMM yyyy 'at' HH:mm:ss");

return (
<S.Container
data-cy="test-results"
ref={squareRef}
onClick={useDoubleClick(() => setHeight?.(height === props.height ? visiblePortion : height))}
>
<S.Header
onPointerDown={onPointerDown}
visiblePortion={visiblePortion}
data-tour={GuidedTourService.getStep(GuidedTours.Trace, Steps.Timeline)}
style={{height: visiblePortion}}
>
<S.HeaderText strong>Trace Information</S.HeaderText>
<S.StartDateText>Trace Start {startDate}</S.StartDateText>
<S.HeaderText strong>
{totalSpanCount} total spans • {totalAssertionCount} selectors • {totalPassedCount + totalFailedCount} checks
• <Badge count="P" style={{backgroundColor: '#49AA19'}} /> <S.CountNumber>{totalPassedCount}</S.CountNumber>
<Badge count="F" /> <S.CountNumber>{totalFailedCount}</S.CountNumber>
</S.HeaderText>
</S.Header>
<S.Content>
<SkeletonTable loading={!trace}>
{traceResultList.length ? (
traceResultList.map(assertionResult =>
assertionResult.spanListAssertionResult.length ? (
<TraceAssertionsResultTable
key={assertionResult.assertion.assertionId}
assertionResult={assertionResult}
onSpanSelected={onSpanSelected}
/>
) : null
)
) : (
<S.EmptyStateContainer>
<S.EmptyStateIcon />
<Typography.Text disabled>No Data</Typography.Text>
</S.EmptyStateContainer>
)}
</SkeletonTable>
</S.Content>
</S.Container>
);
};

export default TestResults;
2 changes: 2 additions & 0 deletions web/src/components/TestResults/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export {default} from './TestResults';
57 changes: 0 additions & 57 deletions web/src/components/Trace/TestResults.tsx

This file was deleted.

9 changes: 2 additions & 7 deletions web/src/components/Trace/Trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {ITestRunResult} from 'types/TestRunResult.types';
import {ITest} from 'types/Test.types';
import Diagram, {SupportedDiagrams} from 'components/Diagram/Diagram';
import SpanDetail from 'components/SpanDetail';
import {TimelineDrawer} from './TimelineDrawer';
import {useHandleOnSpanSelectedCallback} from './hooks/useHandleOnSpanSelectedCallback';
import * as S from './Trace.styled';
import DiagramSwitcher from '../DiagramSwitcher';
import TraceDrawer from './TraceDrawer';

interface IProps {
displayError: boolean;
Expand Down Expand Up @@ -45,12 +45,7 @@ const Trace = ({displayError, visiblePortion, minHeight, test, testResultDetails
<SpanDetail resultId={testResultDetails?.resultId} testId={test?.testId} span={selectedSpan} />
</S.DetailsSection>
</S.Main>
<TimelineDrawer
visiblePortion={visiblePortion}
testResultDetails={testResultDetails}
onSelectSpan={onSelectSpan}
selectedSpan={selectedSpan}
/>
<TraceDrawer visiblePortion={visiblePortion} testResultDetails={testResultDetails} onSelectSpan={onSelectSpan} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trace drawer is whatever we show at the bottom of the page

</>
) : null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import {useState} from 'react';
import {ITestRunResult} from 'types/TestRunResult.types';
import ResizableDrawer from '../ResizableDrawer/ResizableDrawer';
import {TraceTimeline} from './TraceTimeline';
import {ISpan} from '../../types/Span.types';
import TestResults from '../TestResults';

interface IProps {
visiblePortion: number;
testResultDetails: ITestRunResult | undefined;
testResultDetails?: ITestRunResult;
onSelectSpan: (spanId: string) => void;
selectedSpan?: ISpan;
}

export const TimelineDrawer = ({
visiblePortion,
onSelectSpan,
selectedSpan,
testResultDetails,
}: IProps): JSX.Element => {
const TraceDrawer: React.FC<IProps> = ({visiblePortion, onSelectSpan, testResultDetails}) => {
const [max, setMax] = useState(600);

return (
<ResizableDrawer open min={visiblePortion} max={max}>
<TraceTimeline
<TestResults
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we show the test results instead of the timeline chart.

max={max}
result={testResultDetails!}
setMax={setMax}
visiblePortion={visiblePortion}
trace={testResultDetails?.trace!}
onSelectSpan={onSelectSpan}
selectedSpan={selectedSpan}
onSpanSelected={onSelectSpan}
/>
</ResizableDrawer>
);
};

export default TraceDrawer;
Loading