Skip to content

Commit

Permalink
feature: adding part of transaction info to the test run page (#1903)
Browse files Browse the repository at this point in the history
* feature: adding part of transaction info to the test run page

* feature: adding part of transaction info to the test run page
  • Loading branch information
xoscar committed Jan 27, 2023
1 parent 6d01dcb commit 436e3af
Show file tree
Hide file tree
Showing 14 changed files with 405 additions and 190 deletions.
4 changes: 4 additions & 0 deletions api/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ components:
type: object
additionalProperties:
type: string
transactionId:
type: string
transactionRunId:
type: string

RunInformation:
type: object
Expand Down
382 changes: 209 additions & 173 deletions cli/openapi/api_api.go

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions cli/openapi/model_test_run.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/http/mappings/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ func (m OpenAPI) Run(in *model.Run) openapi.TestRun {
Outputs: m.RunOutputs(in.Outputs),
Metadata: in.Metadata,
Environment: m.Environment(in.Environment),
TransactionId: in.TransactionID,
TransactionRunId: in.TransactionRunID,
}
}

Expand Down
5 changes: 5 additions & 0 deletions server/model/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ type (

// environment
Environment Environment

// transaction

TransactionID string
TransactionRunID string
}

RunResults struct {
Expand Down
4 changes: 4 additions & 0 deletions server/openapi/model_test_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type TestRun struct {
Outputs []TestRunOutputs `json:"outputs,omitempty"`

Metadata map[string]string `json:"metadata,omitempty"`

TransactionId string `json:"transactionId,omitempty"`

TransactionRunId string `json:"transactionRunId,omitempty"`
}

// AssertTestRunRequired checks if the required fields are not zero-ed
Expand Down
22 changes: 19 additions & 3 deletions server/testdb/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,17 @@ SELECT
"test_results",
"trace",
"outputs",
"last_error",
"last_error",
"metadata",
"environment"
"environment",
-- transaction run
transaction_run.transaction_run_id,
transaction_run.transaction_run_transaction_id
FROM test_runs
LEFT OUTER JOIN
transaction_run_steps transaction_run
ON transaction_run.test_run_id = id
`

func (td *postgresDB) GetRun(ctx context.Context, testID id.ID, runID int) (model.Run, error) {
Expand Down Expand Up @@ -437,6 +443,9 @@ func readRunRow(row scanner) (model.Run, error) {
lastError *string
traceID,
spanID string

transactionID,
transactionRunID sql.NullString
)

err := row.Scan(
Expand All @@ -458,6 +467,8 @@ func readRunRow(row scanner) (model.Run, error) {
&lastError,
&jsonMetadata,
&jsonEnvironment,
&transactionRunID,
&transactionID,
)

switch err {
Expand Down Expand Up @@ -528,6 +539,11 @@ func readRunRow(row scanner) (model.Run, error) {
r.LastError = fmt.Errorf(*lastError)
}

if transactionID.Valid && transactionRunID.Valid {
r.TransactionID = transactionID.String
r.TransactionRunID = transactionRunID.String
}

return r, nil

default:
Expand Down
22 changes: 21 additions & 1 deletion web/src/components/RunActionsMenu/RunActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ interface IProps {
testId: string;
testVersion: number;
isRunView?: boolean;
transactionId?: string;
transactionRunId: string;
}

const RunActionsMenu = ({resultId, testId, testVersion, isRunView = false}: IProps) => {
const RunActionsMenu = ({
resultId,
testId,
testVersion,
transactionId,
transactionRunId,
isRunView = false,
}: IProps) => {
const {loadJUnit, loadDefinition} = useFileViewerModal();

const navigate = useNavigate();
Expand All @@ -26,6 +35,17 @@ const RunActionsMenu = ({resultId, testId, testVersion, isRunView = false}: IPro
<Dropdown
overlay={
<Menu>
{!!transactionId && !!transactionRunId && (
<Menu.Item
data-cy="transaction-run-button"
key="transaction-run"
onClick={() => {
navigate(`/transaction/${transactionId}/run/${transactionRunId}`);
}}
>
Transaction Run
</Menu.Item>
)}
<Menu.Item
data-cy="view-junit-button"
key="view-junit"
Expand Down
23 changes: 21 additions & 2 deletions web/src/components/RunCard/TestRunCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ function getIcon(state: TTestRun['state'], failedAssertions: number) {
}

const TestRunCard = ({
run: {id: runId, executionTime, passedAssertionCount, failedAssertionCount, state, createdAt, testVersion, metadata},
run: {
id: runId,
executionTime,
passedAssertionCount,
failedAssertionCount,
state,
createdAt,
testVersion,
metadata,
transactionId,
transactionRunId,
},
testId,
linkTo,
}: IProps) => {
Expand Down Expand Up @@ -61,6 +72,8 @@ const TestRunCard = ({
</S.Row>
</S.Info>

{!!transactionId && !!transactionRunId && <S.Text>Part of transaction</S.Text>}

{state !== TestStateEnum.FAILED && state !== TestStateEnum.FINISHED && (
<div data-cy={`test-run-result-status-${runId}`}>
<TestState testState={state} />
Expand All @@ -85,7 +98,13 @@ const TestRunCard = ({
)}

<div>
<RunActionsMenu resultId={runId} testId={testId} testVersion={testVersion} />
<RunActionsMenu
resultId={runId}
testId={testId}
testVersion={testVersion}
transactionRunId={transactionRunId}
transactionId={transactionId}
/>
</div>
</S.Container>
</Link>
Expand Down
38 changes: 28 additions & 10 deletions web/src/components/RunDetailLayout/HeaderLeft.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {Link} from 'react-router-dom';
import {useMemo} from 'react';
import {LinkOutlined} from '@ant-design/icons';

import {useTestRun} from 'providers/TestRun/TestRun.provider';
import Date from 'utils/Date';
Expand All @@ -12,8 +14,26 @@ interface IProps {
}

const HeaderLeft = ({name, testId, triggerType}: IProps) => {
const {run} = useTestRun();
const createdTimeAgo = Date.getTimeAgo(run?.createdAt ?? '');
const {run: {createdAt, transactionId, transactionRunId, executionTime, trace, traceId, testVersion} = {}, run} =
useTestRun();
const createdTimeAgo = Date.getTimeAgo(createdAt ?? '');

const description = useMemo(() => {
return (
<>
{triggerType} • Ran {createdTimeAgo}
{transactionId && transactionRunId && (
<>
{' '}
{' '}
<S.TransactionLink to={`/transaction/${transactionId}/run/${transactionRunId}`} target="_blank">
Part of transaction <LinkOutlined />
</S.TransactionLink>
</>
)}
</>
);
}, [createdTimeAgo, transactionId, transactionRunId, triggerType]);

return (
<S.Section $justifyContent="flex-start">
Expand All @@ -23,19 +43,17 @@ const HeaderLeft = ({name, testId, triggerType}: IProps) => {
<S.InfoContainer>
<S.Row>
<S.Title data-cy="test-details-name">
{name} (v{run.testVersion})
{name} (v{testVersion})
</S.Title>
<Info
date={run?.createdAt ?? ''}
executionTime={run?.executionTime ?? 0}
date={createdAt ?? ''}
executionTime={executionTime ?? 0}
state={run.state}
totalSpans={run?.trace?.spans?.length ?? 0}
traceId={run?.traceId ?? ''}
totalSpans={trace?.spans?.length ?? 0}
traceId={traceId ?? ''}
/>
</S.Row>
<S.Text>
{triggerType}{`Ran ${createdTimeAgo}`}
</S.Text>
<S.Text>{description}</S.Text>
</S.InfoContainer>
</S.Section>
);
Expand Down
9 changes: 8 additions & 1 deletion web/src/components/RunDetailLayout/HeaderRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ const HeaderRight = ({testId, testVersion}: IProps) => {
Run Test
</Button>
)}
<RunActionsMenu isRunView resultId={run.id} testId={testId} testVersion={testVersion} />
<RunActionsMenu
isRunView
resultId={run.id}
testId={testId}
testVersion={testVersion}
transactionId={run.transactionId}
transactionRunId={run.transactionRunId}
/>
</S.Section>
);
};
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/RunDetailLayout/RunDetailLayout.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const Container = styled.div`
}
`;

export const TransactionLink = styled(Link)`
&& {
color: ${({theme}) => theme.color.textSecondary};
}
`;

export const ContainerHeader = styled.div`
background-color: ${({theme}) => theme.color.white};
border-bottom: ${({theme}) => `1px solid ${theme.color.borderLight}`};
Expand Down
4 changes: 4 additions & 0 deletions web/src/models/TestRun.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const TestRun = ({
metadata = {},
outputs = [],
environment = {},
transactionId = '',
transactionRunId = '',
}: TRawTestRun): TTestRun => {
return {
obtainedTraceAt,
Expand All @@ -74,6 +76,8 @@ const TestRun = ({
metadata,
outputs: outputs?.map(rawOutput => TestRunOutput(rawOutput)),
environment: Environment(environment),
transactionId,
transactionRunId,
};
};

Expand Down
2 changes: 2 additions & 0 deletions web/src/types/Generated.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,8 @@ export interface external {
value?: string;
}[];
metadata?: { [key: string]: string };
transactionId?: string;
transactionRunId?: string;
};
RunInformation: {
metadata?: { [key: string]: string } | null;
Expand Down

0 comments on commit 436e3af

Please sign in to comment.