Skip to content

Commit

Permalink
Update TestState component to include progress bar (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc authored May 19, 2022
1 parent 36386cd commit d9ff909
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ exports[`Router 1`] = `
class="ant-layout-content sc-bdvvtL cVXBSg"
>
<div
class="sc-iwjdpV NooTe"
class="sc-llYSUQ jPRqiW"
>
<h4
class="ant-typography sc-bBHxTw hNGPLR"
class="ant-typography sc-cxpSdN bbcJQg"
>
All Tests
</h4>
<div
class="sc-fKVqWL hXBhTv"
class="sc-iwjdpV NicDQ"
>
<span
class="ant-input-affix-wrapper sc-jJoQJp lKcrg"
class="ant-input-affix-wrapper sc-gWXbKe kPVVws"
>
<span
class="ant-input-prefix"
Expand Down Expand Up @@ -163,10 +163,10 @@ exports[`Router 1`] = `
/>
</span>
<div
class="sc-cxpSdN daEcoQ"
class="sc-iJKOTD bLqiN"
>
<button
class="ant-btn ant-btn-primary sc-kfPuZi"
class="ant-btn ant-btn-primary sc-bBHxTw"
data-cy="create-test-button"
data-tour="home_create_test"
type="button"
Expand All @@ -178,12 +178,12 @@ exports[`Router 1`] = `
</div>
</div>
<div
class="sc-ezbkAF gkHwYo"
class="sc-kLwhqv kFBBsa"
data-cy="test-list"
/>
</div>
<div
class="sc-bYoBSM kZlmwb"
class="sc-ikJyIC exAstU"
/>
</main>
</div>
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/ResultCard/ResultCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {format, parseISO} from 'date-fns';
import {RESULT_DATE_FORMAT} from '../../constants/Date.constants';
import {ITestRunResult} from '../../types/TestRunResult.types';
import TestStateBadge from '../TestStateBadge';
import TestState from '../TestState';
import * as S from './ResultCard.styled';
import ResultCardActions from './ResultCardActions';

Expand Down Expand Up @@ -35,8 +35,8 @@ const ResultCard: React.FC<IResultCardProps> = ({
<S.TextContainer>
<S.Text>{executionTime}s</S.Text>
</S.TextContainer>
<S.TextContainer>
<TestStateBadge data-cy={`test-run-result-status-${resultId}`} testState={state} />
<S.TextContainer data-cy={`test-run-result-status-${resultId}`}>
<TestState testState={state} />
</S.TextContainer>
<S.TextContainer>
<S.Text>{totalAssertionCount}</S.Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
exports[`TestCard 1`] = `
<div>
<div
class="sc-jrQzAO guQEPO"
class="sc-iqseJM fscQmy"
>
<div
class="sc-kDTinF iNqRfS"
class="sc-crHmcD dvudNn"
>
<span
aria-label="right"
Expand All @@ -30,38 +30,38 @@ exports[`TestCard 1`] = `
</svg>
</span>
<div
class="sc-crHmcD dqqtkd"
class="sc-bqiRlB ghwjXk"
>
<span
class="ant-typography sc-bqiRlB jCwMNy"
class="ant-typography sc-hBUSln fEhLhq"
>
</span>
</div>
<div
class="sc-crHmcD dqqtkd"
class="sc-bqiRlB ghwjXk"
>
<span
class="ant-typography sc-ksdxgE"
class="ant-typography sc-fotOHu"
>
GET
</span>
</div>
<div
class="sc-crHmcD dqqtkd"
class="sc-bqiRlB ghwjXk"
data-cy="test-url-2309ei30"
>
<span
class="ant-typography sc-ksdxgE"
class="ant-typography sc-fotOHu"
>
</span>
</div>
<div
class="sc-crHmcD dqqtkd"
class="sc-bqiRlB ghwjXk"
/>
<div
class="sc-egiyK hbItou"
class="sc-ksdxgE kMvHnp"
>
<button
class="ant-btn ant-btn-primary ant-btn-background-ghost"
Expand All @@ -79,7 +79,7 @@ exports[`TestCard 1`] = `
>
<span
aria-label="more"
class="anticon anticon-more sc-hBUSln"
class="anticon anticon-more sc-fFeiMQ"
role="img"
style="font-size: 24px; color: rgb(154, 163, 171); cursor: pointer;"
>
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/TestHeader/TestHeader.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const TestUrl = styled(Typography.Text).attrs({
export const StateText = styled(Typography.Text)`
&& {
margin-right: 8px;
color: 8c8c8c;
color: #8c8c8c;
}
`;

Expand All @@ -52,5 +52,7 @@ export const Content = styled.div`
`;

export const StateContainer = styled.div`
align-items: center;
display: flex;
justify-self: flex-end;
`;
8 changes: 4 additions & 4 deletions web/src/components/TestHeader/TestHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {TestState} from '../../constants/TestRunResult.constants';
import {TestState as TestStateEnum} from '../../constants/TestRunResult.constants';
import {ITest} from '../../types/Test.types';
import TestStateBadge from '../TestStateBadge';
import TestState from '../TestState';
import * as S from './TestHeader.styled';

interface ITestHeaderProps {
test: ITest;
onBack(): void;
testState?: TestState;
testState?: TestStateEnum;
}

const TestHeader: React.FC<ITestHeaderProps> = ({test: {name, serviceUnderTest}, onBack, testState}) => {
Expand All @@ -22,7 +22,7 @@ const TestHeader: React.FC<ITestHeaderProps> = ({test: {name, serviceUnderTest},
{testState && (
<S.StateContainer data-cy="test-run-result-status">
<S.StateText>Test status:</S.StateText>
<TestStateBadge style={{fontSize: 16}} testState={testState} />
<TestState testState={testState} />
</S.StateContainer>
)}
</S.TestHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
exports[`SpanAttributesTable 1`] = `
<div>
<div
class="sc-bdvvtL bQEEzU"
class="sc-dkPtRN giofdF"
>
<div
class="sc-jRQBWg bHOJVG"
class="sc-iCfMLu fxGWsx"
>
<span
aria-label="left"
class="anticon anticon-left sc-eCImPb jQaqRW"
class="anticon anticon-left sc-gKclnd dGddRj"
data-cy="test-header-back-button"
role="img"
tabindex="-1"
Expand All @@ -30,41 +30,44 @@ exports[`SpanAttributesTable 1`] = `
</svg>
</span>
<h4
class="ant-typography sc-gsDKAQ flnTLB"
class="ant-typography sc-hKwDye gXTdui"
data-cy="test-details-name"
>
</h4>
<span
class="ant-typography ant-typography-secondary sc-dkPtRN keTppE"
class="ant-typography ant-typography-secondary sc-eCImPb bTklbz"
>
GET
-
</span>
</div>
<div
class="sc-gKclnd iAZrTR"
class="sc-furwcr kLOQYj"
data-cy="test-run-result-status"
>
<span
class="ant-typography sc-hKwDye eSRBwq"
class="ant-typography sc-jRQBWg LTTZG"
>
Test status:
</span>
<span
class="ant-badge ant-badge-status ant-badge-not-a-wrapper"
style="font-size: 16px;"
<div
class="sc-bdvvtL hICooe"
>
<span
class="ant-badge-status-dot ant-badge-status-default"
/>
<span
class="ant-badge-status-text"
class="ant-badge ant-badge-status ant-badge-not-a-wrapper"
>
Created
<span
class="ant-badge-status-dot ant-badge-status-default"
/>
<span
class="ant-badge-status-text"
>
Created
</span>
</span>
</span>
</div>
</div>
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions web/src/components/TestState/TestState.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Typography} from 'antd';
import styled from 'styled-components';

export const Container = styled.div<{hasMinWidth?: boolean}>`
display: flex;
flex-direction: column;
height: 28px;
justify-content: center;
max-width: 204px;
min-width: ${({hasMinWidth}) => hasMinWidth && '115px'};
.ant-progress {
font-size: 6px;
line-height: 6px;
}
`;

export const Text = styled(Typography.Text)`
color: rgba(3, 24, 73, 0.3);
font-size: 12px;
margin-top: 2px;
`;
20 changes: 20 additions & 0 deletions web/src/components/TestState/TestState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import TestStateBadge from './TestStateBadge';
import TestStateProgress from './TestStateProgress';
import {TestStateMap} from '../../constants/TestRunResult.constants';
import {ITestRunResult} from '../../types/TestRunResult.types';

interface IProps {
testState: ITestRunResult['state'];
}

const TestState = ({testState}: IProps) => {
const {label, percent, status} = TestStateMap[testState];

return percent ? (
<TestStateProgress label={label} percent={percent} />
) : (
<TestStateBadge label={label} status={status} />
);
};

export default TestState;
15 changes: 15 additions & 0 deletions web/src/components/TestState/TestStateBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Badge} from 'antd';
import * as S from './TestState.styled';

interface IProps {
label: string;
status: 'success' | 'processing' | 'error' | 'default' | 'warning';
}

const TestStateBadge = ({label, status}: IProps) => (
<S.Container>
<Badge status={status} text={label} />
</S.Container>
);

export default TestStateBadge;
23 changes: 23 additions & 0 deletions web/src/components/TestState/TestStateProgress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Progress} from 'antd';
import * as S from './TestState.styled';

interface IProps {
label: string;
percent: number;
}

const TestStateProgress = ({label, percent}: IProps) => (
<S.Container hasMinWidth>
<Progress
percent={percent}
showInfo={false}
status="active"
strokeLinecap="square"
strokeWidth={6}
trailColor="rgba(154, 163, 171, 0.3)"
/>
<S.Text>{label}</S.Text>
</S.Container>
);

export default TestStateProgress;
21 changes: 21 additions & 0 deletions web/src/components/TestState/__tests__/TestState.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {render} from '@testing-library/react';
import TestState from '../TestState';
import {TestState as TestStateEnum, TestStateMap} from '../../../constants/TestRunResult.constants';

describe('TestState', () => {
it('should render badge component', () => {
const {container, getByText} = render(<TestState testState={TestStateEnum.CREATED} />);
const badge = container.getElementsByClassName('ant-badge');

expect(badge.length).toBe(1);
expect(getByText(TestStateMap.CREATED.label)).toBeInTheDocument();
});

it('should render progress component', () => {
const {container, getByText} = render(<TestState testState={TestStateEnum.EXECUTING} />);
const progress = container.getElementsByClassName('ant-progress');

expect(progress.length).toBe(1);
expect(getByText(TestStateMap.EXECUTING.label)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line no-restricted-exports
export {default} from './TestStateBadge';
export {default} from './TestState';
Loading

0 comments on commit d9ff909

Please sign in to comment.