Skip to content

Commit

Permalink
Handle single combination in limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 19, 2021
1 parent 935ca65 commit c70492e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/combination/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { titleColor, noteColor } from '../report/utils/colors.js'
import { omitCombNoDimensions } from './filter.js'
import { getCombinationIds } from './ids.js'

// Retrieve error message prefix showing a combination's dimension ids
export const getCombinationPrefix = function (combination, noDimensions) {
const combinationName = getCombinationName(combination, noDimensions)
return combinationName === '' ? '' : `In ${combinationName}:\n`
}

// Retrieve string with each combination's dimension id.
// This is in contrast with `combinationTitle`:
// - `combinationTitle*` uses dimensions titles, which is more useful at
Expand Down
7 changes: 3 additions & 4 deletions src/history/compare/limit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCombinationName } from '../../combination/name.js'
import { getCombinationPrefix } from '../../combination/name.js'
import { UserError } from '../../error/main.js'
import { matchSelectors } from '../../select/match.js'

Expand Down Expand Up @@ -74,12 +74,11 @@ const isBelowThreshold = function (diff, threshold, higher) {
// `getCombinationName` passes an empty `noDimensions` since `dimensions` are
// already filtered out `programmaticResult`.
const getLimitError = function ({ diff, threshold, higher, combination }) {
const combinationName = getCombinationName(combination, [])
const combinationPrefix = getCombinationPrefix(combination, [])
const thresholdStr = threshold * PERCENTAGE_RATIO
const diffStr = serializeDiff(diff)
const higherStr = higher ? 'higher' : 'lower'
return `In ${combinationName}:
The combination should be at most ${thresholdStr}% ${higherStr} but it is ${diffStr}% ${higherStr}.`
return `${combinationPrefix}The combination should be at most ${thresholdStr}% ${higherStr} but it is ${diffStr}% ${higherStr}.`
}

const serializeDiff = function (diff) {
Expand Down

0 comments on commit c70492e

Please sign in to comment.