diff --git a/spec/javascripts/govuk_publishing_components/lib/govspeak/magna-charta-spec.js b/spec/javascripts/govuk_publishing_components/lib/govspeak/magna-charta-spec.js index 75554fce91..ecc3716735 100644 --- a/spec/javascripts/govuk_publishing_components/lib/govspeak/magna-charta-spec.js +++ b/spec/javascripts/govuk_publishing_components/lib/govspeak/magna-charta-spec.js @@ -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 = @@ -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 () {