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

Adm 889 - remove some 'name' column in DORA Metrics Detail page #1380

Merged
merged 8 commits into from
Apr 16, 2024
Prev Previous commit
ADM-889:[frontend] fix: fix title unit and test
  • Loading branch information
Rui7ing committed Apr 16, 2024
commit ea350c9ff9e12b21eb2f628b1a2f413c64df3a63
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', () => {
@@ -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', () => {
Original file line number Diff line number Diff line change
@@ -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 = () => (
14 changes: 13 additions & 1 deletion frontend/src/components/Common/ReportForTwoColumns/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
@@ -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>
@@ -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;
Loading