Skip to content

Commit

Permalink
ADM-889:[frontend] fix: fix title unit and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui7ing committed Apr 16, 2024
1 parent 3967a68 commit ea350c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReportForThreeColumns from '@src/components/Common/ReportForThreeColumns';
import { LEAD_TIME_FOR_CHANGES, LOADING, VELOCITY } from '../../fixtures';
import { render, screen } from '@testing-library/react';
import { LOADING, VELOCITY } from '../../fixtures';

describe('Report for three columns', () => {
it('should show loading when data is empty', () => {
Expand All @@ -17,9 +17,11 @@ describe('Report for three columns', () => {
{ id: 2, name: 'name3', valuesList: [{ name: 'test3', value: '3' }] },
];

render(<ReportForThreeColumns title={VELOCITY} fieldName='fieldName' listName='listName' data={mockData} />);
render(
<ReportForThreeColumns title={LEAD_TIME_FOR_CHANGES} fieldName='fieldName' listName='listName' data={mockData} />,
);

expect(screen.getByTestId(VELOCITY)).toBeInTheDocument();
expect(screen.getByTestId(LEAD_TIME_FOR_CHANGES)).toBeInTheDocument();
});

it('should show table when data name contains emoji', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ export const ReportForThreeColumns = ({
});

const getTitleUnit = (title: string) => {
return title === METRICS_TITLE.LEAD_TIME_FOR_CHANGES || title === METRICS_TITLE.DEV_MEAN_TIME_TO_RECOVERY
? REPORT_SUFFIX_UNITS.HOURS
: title === METRICS_TITLE.DEPLOYMENT_FREQUENCY
? REPORT_SUFFIX_UNITS.DEPLOYMENTS_DAY
: '';
return title === METRICS_TITLE.LEAD_TIME_FOR_CHANGES ? REPORT_SUFFIX_UNITS.HOURS : '';
};

const renderLoading = () => (
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/Common/ReportForTwoColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { ReportDataWithTwoColumns } from '@src/hooks/reportMapper/reportUIDataStructure';
import { EmojiWrap, StyledAvatar, StyledTypography } from '@src/constants/emojis/style';
import { getEmojiUrls, removeExtraEmojiName } from '@src/constants/emojis/emoji';
import { METRICS_TITLE, REPORT_SUFFIX_UNITS } from '@src/constants/resources';
import { ReportSelectionTitle } from '@src/containers/MetricsStep/style';
import { Table, TableBody, TableHead, TableRow } from '@mui/material';
import React, { Fragment } from 'react';
Expand Down Expand Up @@ -65,7 +66,7 @@ export const ReportForTwoColumns = ({ title, data }: ReportForTwoColumnsProps) =
<TableHead>
<TableRow id={title}>
<StyledTableCell>Name</StyledTableCell>
<StyledTableCell>Value</StyledTableCell>
<StyledTableCell>{`Value${getTitleUnit(title)}`}</StyledTableCell>
</TableRow>
</TableHead>
<TableBody key={title}>{renderRows()}</TableBody>
Expand All @@ -75,4 +76,15 @@ export const ReportForTwoColumns = ({ title, data }: ReportForTwoColumnsProps) =
);
};

const getTitleUnit = (title: string) => {
switch (title) {
case METRICS_TITLE.DEV_MEAN_TIME_TO_RECOVERY:
return REPORT_SUFFIX_UNITS.HOURS;
case METRICS_TITLE.DEPLOYMENT_FREQUENCY:
return REPORT_SUFFIX_UNITS.DEPLOYMENTS_DAY;
default:
return '';
}
};

export default ReportForTwoColumns;

0 comments on commit ea350c9

Please sign in to comment.