From 5b92a143dc2d93e9f0e792de5524073446d15ca6 Mon Sep 17 00:00:00 2001 From: Frank Niessink Date: Tue, 22 Sep 2020 20:30:55 +0200 Subject: [PATCH] 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. (#1481) --- components/frontend/src/metric/Measurement.js | 4 +- .../frontend/src/metric/Measurement.test.js | 60 ++++++++++++------- docs/CHANGELOG.md | 4 ++ 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/components/frontend/src/metric/Measurement.js b/components/frontend/src/metric/Measurement.js index 9afbab2db0..8e2d2f8ecb 100644 --- a/components/frontend/src/metric/Measurement.js +++ b/components/frontend/src/metric/Measurement.js @@ -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; @@ -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}` diff --git a/components/frontend/src/metric/Measurement.test.js b/components/frontend/src/metric/Measurement.test.js index 0666763f35..691de0c40b 100644 --- a/components/frontend/src/metric/Measurement.test.js +++ b/components/frontend/src/metric/Measurement.test.js @@ -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: { @@ -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(
); +function measurement() { + return ( + mount(
+ ) + ) +} + +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(
); - 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"); }); \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c62c71b5bf..28b7cb1371 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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