Skip to content

Commit

Permalink
Fix failing magnaCharta test in Safari
Browse files Browse the repository at this point in the history
- Updated the `cW` function to avoid truncating the calculated width, this matches the default behaviour in magnaCharta which does not restrict the number of decimal places
- Use the [toBeCloseTo](https://jasmine.github.io/api/5.6/matchers#toBeCloseTo) matcher and set the number of decimal points to check to 4

Fixes: #2229
  • Loading branch information
MartinJJones committed Feb 28, 2025
1 parent 14b41d8 commit c617ba0
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ describe('Magna charta', function () {
// widths are 65/max * val (65 by default)
var cW = function (max, val, padding) {
padding = padding || 0
var result = ((65 / max) * val + padding).toString()
// truncate the result to only 4 digits after the decimal place
// e.g. 27.0833333333 becomes 27.0833, 27.1 and 27 remain the same
var split = result.split('.')
if (split.length > 1) {
result = split[0] + '.' + split[1].substring(0, 4)
}
return result + '%'
var width = ((65 / max) * val + padding)
return `${width}%`
}

var single =
Expand Down Expand Up @@ -282,12 +276,15 @@ describe('Magna charta', function () {

it('the bar cells are given the right widths', function () {
var cells = graph.find('.mc-bar-cell')
expect(cells.get(0).style.width).toEqual(cW(12, 5))
expect(cells.get(1).style.width).toEqual(cW(12, 6))
expect(cells.get(2).style.width).toEqual(cW(12, 6))
expect(cells.get(3).style.width).toEqual(cW(12, 2))
expect(cells.get(4).style.width).toEqual(cW(12, 3))
expect(cells.get(5).style.width).toEqual(cW(12, 9))

for (var cell of cells) {
var cellText = cell.textContent
var cellWidth = cell.style.width
var calculatedWidth = parseFloat(cW(12, cellText))

expect(cellWidth).toContain('%')
expect(parseFloat(cellWidth)).toBeCloseTo(calculatedWidth, 4)
}
})

it('the bar cells are given classes denoting their index', function () {
Expand Down

0 comments on commit c617ba0

Please sign in to comment.