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

Adds metrics table to Compare page, creates Metric component #1284

Merged
merged 6 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds MetricUtils tests
  • Loading branch information
rileyjbauer committed May 6, 2019
commit f1e52d95a63553610140ace9a30f280f0f353919
2 changes: 1 addition & 1 deletion frontend/src/lib/CompareUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import CompareUtils from './CompareUtils';
import { ApiRun, ApiRunMetric } from '../apis/run';
import { ApiRun } from '../apis/run';
import { Workflow } from 'third_party/argo-ui/argo_template';

describe('CompareUtils', () => {
Expand Down
59 changes: 59 additions & 0 deletions frontend/src/lib/MetricUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import MetricUtils from './MetricUtils';
import { RunMetricFormat } from '../apis/run';

describe('MetricUtils', () => {

describe('getMetricDisplayString', () => {

it('returns an empty string when no metric is provided', () => {
expect(MetricUtils.getMetricDisplayString()).toEqual('');
});

it('returns an empty string when metric has no number value', () => {
expect(MetricUtils.getMetricDisplayString({})).toEqual('');
});

it('returns a formatted string to three decimal places when metric has number value', () => {
expect(MetricUtils.getMetricDisplayString({ number_value: 0.1234 })).toEqual('0.123');
});

it('returns a formatted string to specified decimal places', () => {
expect(MetricUtils.getMetricDisplayString({ number_value: 0.1234 }, 2)).toEqual('0.12');
});

it('returns a formatted string when metric has format percentage and has number value', () => {
expect(MetricUtils.getMetricDisplayString({
format: RunMetricFormat.PERCENTAGE,
number_value: 0.12341234
})
).toEqual('12.341%');
});

it('returns a formatted string to specified decimal places when metric has format percentage', () => {
expect(MetricUtils.getMetricDisplayString(
{
format: RunMetricFormat.PERCENTAGE,
number_value: 0.12341234
},
1)
).toEqual('12.3%');
});
});

});
2 changes: 2 additions & 0 deletions frontend/src/lib/MetricUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ function getMetricDisplayString(metric?: ApiRunMetric, decimalPlaces = 3): strin
if (!metric || metric.number_value === undefined) {
return '';
}

if (metric.format === RunMetricFormat.PERCENTAGE) {
return (metric.number_value * 100).toFixed(decimalPlaces) + '%';
}

return metric.number_value.toFixed(decimalPlaces);
}

Expand Down