Skip to content

Commit

Permalink
The measurement value and target of metrics with unit minutes and the…
Browse files Browse the repository at this point in the history
…ir scale set to percentage were formatted incorrectly (e.g. "0:50%" instead of "50%"). Fixes #1480. (#1481)
  • Loading branch information
fniessink authored Sep 22, 2020
1 parent bff5039 commit 5b92a14
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
4 changes: 2 additions & 2 deletions components/frontend/src/metric/Measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "./Measurement.css";

export function Measurement(props) {
function MeasurementValue() {
const value = metric.value && metric_type.unit === "minutes" ? format_minutes(metric.value) : metric.value || "?";
const value = metric.value && metric_type.unit === "minutes" && metric.scale !== "percentage" ? format_minutes(metric.value) : metric.value || "?";
const now = new Date();
const measurement_timestring = (latest_measurement && latest_measurement.end) || now.toISOString();
const start = (latest_measurement && new Date(latest_measurement.start)) || now;
Expand All @@ -34,7 +34,7 @@ export function Measurement(props) {
}
const debt = metric.accept_debt ? ` (debt accepted${debt_end})` : "";
let target = get_metric_target(metric);
if (target && metric_type.unit === "minutes") {
if (target && metric_type.unit === "minutes" && metric.scale !== "percentage") {
target = format_minutes(target)
}
return `${metric_direction} ${target}${metric_unit}${debt}`
Expand Down
60 changes: 40 additions & 20 deletions components/frontend/src/metric/Measurement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Table } from 'semantic-ui-react';
import { mount } from 'enzyme';
import { Measurement } from './Measurement';

const report = {
let report = {
report_uuid: "report_uuid",
subjects: {
subject_uuid: {
Expand All @@ -15,33 +15,53 @@ const report = {
tags: [],
type: "violations",
sources: [],
status: null,
status: "target_not_met",
value: "50",
recent_measurements: [{sources: [{name: "Source", source_uuid: "1"}]}]
}
}
}
}
};
const data_model = { metrics: { violations: { name: "Metric type", direction: "<", tags: [] } } };
const data_model = {
metrics: {
stability: { name: "Stability", unit: "minutes", direction: "<", tags: [] },
violations: { name: "Metric type", unit: "violations", direction: "<", tags: [] }
}
};

it('renders the source', () => {
const wrapper = mount(<Table><Table.Body><Measurement
hiddenColumns={[]}
report={report}
reports={[report]}
metric_uuid="metric_uuid"
subject_uuid="subject_uuid"
datamodel={data_model} /></Table.Body></Table>);
function measurement() {
return (
mount(<Table><Table.Body><Measurement
hiddenColumns={[]}
report={report}
reports={[report]}
metric_uuid="metric_uuid"
subject_uuid="subject_uuid"
datamodel={data_model} /></Table.Body></Table>
)
)
}

it('renders the metric', () => {
const wrapper = measurement();
expect(wrapper.find("TableCell").at(1).text()).toBe("Metric");
expect(wrapper.find("TableCell").at(4).text()).toBe("50 violations");
expect(wrapper.find("TableCell").at(5).text()).toBe("≦ 0 violations");
expect(wrapper.find("TableCell").at(6).find("SourceStatus").prop("source").name).toBe("Source");
});

it('renders the metric name', () => {
const wrapper = mount(<Table><Table.Body><Measurement
hiddenColumns={[]}
report={report}
reports={[report]}
metric_uuid="metric_uuid"
subject_uuid="subject_uuid"
datamodel={data_model} /></Table.Body></Table>);
expect(wrapper.find("TableCell").at(1).text()).toBe("Metric");
it('renders the minutes', () => {
report.subjects.subject_uuid.metrics.metric_uuid.type = "stability";
const wrapper = measurement();
expect(wrapper.find("TableCell").at(4).text()).toBe("0:50 minutes");
expect(wrapper.find("TableCell").at(5).text()).toBe("≦ 0:00 minutes");
});

it('renders the minutes as percentage', () => {
report.subjects.subject_uuid.metrics.metric_uuid.type = "stability";
report.subjects.subject_uuid.metrics.metric_uuid.scale = "percentage";
const wrapper = measurement();
expect(wrapper.find("TableCell").at(4).text()).toBe("50% minutes");
expect(wrapper.find("TableCell").at(5).text()).toBe("≦ 0% minutes");
});
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- When exporting quality reports to PDF, hide the same metric table rows and columns in the PDF as hidden by the user in the user interface. Closes [#1466](https://github.com/ICTU/quality-time/issues/1466).
- In addition to the trend, target, source, comment, and tags columns, also allow for hiding the status and measurement columns in metric tables. Closes [#1474](https://github.com/ICTU/quality-time/issues/1474).

### Fixed

- The measurement value and target of metrics with unit minutes and their scale set to percentage were formatted incorrectly (e.g. "0:50%" instead of "50%"). Fixes [#1480](https://github.com/ICTU/quality-time/issues/1480).

## [3.6.0] - [2020-09-19]

### Changed
Expand Down

0 comments on commit 5b92a14

Please sign in to comment.