]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add regression test for legend layout issue (#5776)
authorJan Tagscherer <3198913+jtagscherer@users.noreply.github.com>
Wed, 14 Nov 2018 10:12:57 +0000 (11:12 +0100)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Wed, 14 Nov 2018 10:12:57 +0000 (11:12 +0100)
test/specs/plugin.legend.tests.js

index 924276587f0ffb8da96f8985d414e12bb5bdd10e..b6bb1a894265f43845074fc6543b5e2dd36bfb0d 100644 (file)
@@ -525,6 +525,43 @@ describe('Legend block tests', function() {
                });
        });
 
+       it('should not draw legend items outside of the chart bounds', function() {
+               var chart = window.acquireChart(
+                       {
+                               type: 'line',
+                               data: {
+                                       datasets: [1, 2, 3].map(function(n) {
+                                               return {
+                                                       label: 'dataset' + n,
+                                                       data: []
+                                               };
+                                       }),
+                                       labels: []
+                               },
+                               options: {
+                                       legend: {
+                                               position: 'right'
+                                       }
+                               }
+                       },
+                       {
+                               canvas: {
+                                       width: 512,
+                                       height: 105
+                               }
+                       }
+               );
+
+               // Check some basic assertions about the test setup
+               expect(chart.width).toBe(512);
+               expect(chart.legend.legendHitBoxes.length).toBe(3);
+
+               // Check whether any legend items reach outside the established bounds
+               chart.legend.legendHitBoxes.forEach(function(item) {
+                       expect(item.left + item.width).toBeLessThanOrEqual(chart.width);
+               });
+       });
+
        describe('config update', function() {
                it ('should update the options', function() {
                        var chart = acquireChart({