core.helpers.tests.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. describe('Core helper tests', function() {
  2. var helpers;
  3. beforeAll(function() {
  4. helpers = window.Chart.helpers;
  5. });
  6. it('should filter an array', function() {
  7. var data = [-10, 0, 6, 0, 7];
  8. var callback = function(item) {
  9. return item > 2;
  10. };
  11. expect(helpers.where(data, callback)).toEqual([6, 7]);
  12. expect(helpers.findNextWhere(data, callback)).toEqual(6);
  13. expect(helpers.findNextWhere(data, callback, 2)).toBe(7);
  14. expect(helpers.findNextWhere(data, callback, 4)).toBe(undefined);
  15. expect(helpers.findPreviousWhere(data, callback)).toBe(7);
  16. expect(helpers.findPreviousWhere(data, callback, 3)).toBe(6);
  17. expect(helpers.findPreviousWhere(data, callback, 0)).toBe(undefined);
  18. });
  19. it('should get the correct sign', function() {
  20. expect(helpers.sign(0)).toBe(0);
  21. expect(helpers.sign(10)).toBe(1);
  22. expect(helpers.sign(-5)).toBe(-1);
  23. });
  24. it('should correctly determine if two numbers are essentially equal', function() {
  25. expect(helpers.almostEquals(0, Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
  26. expect(helpers.almostEquals(1, 1.1, 0.0001)).toBe(false);
  27. expect(helpers.almostEquals(1e30, 1e30 + Number.EPSILON, 0)).toBe(false);
  28. expect(helpers.almostEquals(1e30, 1e30 + Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
  29. });
  30. it('should correctly determine if a numbers are essentially whole', function() {
  31. expect(helpers.almostWhole(0.99999, 0.0001)).toBe(true);
  32. expect(helpers.almostWhole(0.9, 0.0001)).toBe(false);
  33. expect(helpers.almostWhole(1234567890123, 0.0001)).toBe(true);
  34. expect(helpers.almostWhole(1234567890123.001, 0.0001)).toBe(false);
  35. });
  36. it('should generate integer ids', function() {
  37. var uid = helpers.uid();
  38. expect(uid).toEqual(jasmine.any(Number));
  39. expect(helpers.uid()).toBe(uid + 1);
  40. expect(helpers.uid()).toBe(uid + 2);
  41. expect(helpers.uid()).toBe(uid + 3);
  42. });
  43. it('should detect a number', function() {
  44. expect(helpers.isNumber(123)).toBe(true);
  45. expect(helpers.isNumber('123')).toBe(true);
  46. expect(helpers.isNumber(null)).toBe(false);
  47. expect(helpers.isNumber(NaN)).toBe(false);
  48. expect(helpers.isNumber(undefined)).toBe(false);
  49. expect(helpers.isNumber('cbc')).toBe(false);
  50. });
  51. it('should convert between radians and degrees', function() {
  52. expect(helpers.toRadians(180)).toBe(Math.PI);
  53. expect(helpers.toRadians(90)).toBe(0.5 * Math.PI);
  54. expect(helpers.toDegrees(Math.PI)).toBe(180);
  55. expect(helpers.toDegrees(Math.PI * 3 / 2)).toBe(270);
  56. });
  57. it('should get the correct number of decimal places', function() {
  58. expect(helpers._decimalPlaces(100)).toBe(0);
  59. expect(helpers._decimalPlaces(1)).toBe(0);
  60. expect(helpers._decimalPlaces(0)).toBe(0);
  61. expect(helpers._decimalPlaces(0.01)).toBe(2);
  62. expect(helpers._decimalPlaces(-0.01)).toBe(2);
  63. expect(helpers._decimalPlaces('1')).toBe(undefined);
  64. expect(helpers._decimalPlaces('')).toBe(undefined);
  65. expect(helpers._decimalPlaces(undefined)).toBe(undefined);
  66. expect(helpers._decimalPlaces(12345678.1234)).toBe(4);
  67. expect(helpers._decimalPlaces(1234567890.1234567)).toBe(7);
  68. });
  69. it('should get an angle from a point', function() {
  70. var center = {
  71. x: 0,
  72. y: 0
  73. };
  74. expect(helpers.getAngleFromPoint(center, {
  75. x: 0,
  76. y: 10
  77. })).toEqual({
  78. angle: Math.PI / 2,
  79. distance: 10,
  80. });
  81. expect(helpers.getAngleFromPoint(center, {
  82. x: Math.sqrt(2),
  83. y: Math.sqrt(2)
  84. })).toEqual({
  85. angle: Math.PI / 4,
  86. distance: 2
  87. });
  88. expect(helpers.getAngleFromPoint(center, {
  89. x: -1.0 * Math.sqrt(2),
  90. y: -1.0 * Math.sqrt(2)
  91. })).toEqual({
  92. angle: Math.PI * 1.25,
  93. distance: 2
  94. });
  95. });
  96. it('should spline curves', function() {
  97. expect(helpers.splineCurve({
  98. x: 0,
  99. y: 0
  100. }, {
  101. x: 1,
  102. y: 1
  103. }, {
  104. x: 2,
  105. y: 0
  106. }, 0)).toEqual({
  107. previous: {
  108. x: 1,
  109. y: 1,
  110. },
  111. next: {
  112. x: 1,
  113. y: 1,
  114. }
  115. });
  116. expect(helpers.splineCurve({
  117. x: 0,
  118. y: 0
  119. }, {
  120. x: 1,
  121. y: 1
  122. }, {
  123. x: 2,
  124. y: 0
  125. }, 1)).toEqual({
  126. previous: {
  127. x: 0,
  128. y: 1,
  129. },
  130. next: {
  131. x: 2,
  132. y: 1,
  133. }
  134. });
  135. });
  136. it('should spline curves with monotone cubic interpolation', function() {
  137. var dataPoints = [
  138. {_model: {x: 0, y: 0, skip: false}},
  139. {_model: {x: 3, y: 6, skip: false}},
  140. {_model: {x: 9, y: 6, skip: false}},
  141. {_model: {x: 12, y: 60, skip: false}},
  142. {_model: {x: 15, y: 60, skip: false}},
  143. {_model: {x: 18, y: 120, skip: false}},
  144. {_model: {x: null, y: null, skip: true}},
  145. {_model: {x: 21, y: 180, skip: false}},
  146. {_model: {x: 24, y: 120, skip: false}},
  147. {_model: {x: 27, y: 125, skip: false}},
  148. {_model: {x: 30, y: 105, skip: false}},
  149. {_model: {x: 33, y: 110, skip: false}},
  150. {_model: {x: 33, y: 110, skip: false}},
  151. {_model: {x: 36, y: 170, skip: false}}
  152. ];
  153. helpers.splineCurveMonotone(dataPoints);
  154. expect(dataPoints).toEqual([{
  155. _model: {
  156. x: 0,
  157. y: 0,
  158. skip: false,
  159. controlPointNextX: 1,
  160. controlPointNextY: 2
  161. }
  162. },
  163. {
  164. _model: {
  165. x: 3,
  166. y: 6,
  167. skip: false,
  168. controlPointPreviousX: 2,
  169. controlPointPreviousY: 6,
  170. controlPointNextX: 5,
  171. controlPointNextY: 6
  172. }
  173. },
  174. {
  175. _model: {
  176. x: 9,
  177. y: 6,
  178. skip: false,
  179. controlPointPreviousX: 7,
  180. controlPointPreviousY: 6,
  181. controlPointNextX: 10,
  182. controlPointNextY: 6
  183. }
  184. },
  185. {
  186. _model: {
  187. x: 12,
  188. y: 60,
  189. skip: false,
  190. controlPointPreviousX: 11,
  191. controlPointPreviousY: 60,
  192. controlPointNextX: 13,
  193. controlPointNextY: 60
  194. }
  195. },
  196. {
  197. _model: {
  198. x: 15,
  199. y: 60,
  200. skip: false,
  201. controlPointPreviousX: 14,
  202. controlPointPreviousY: 60,
  203. controlPointNextX: 16,
  204. controlPointNextY: 60
  205. }
  206. },
  207. {
  208. _model: {
  209. x: 18,
  210. y: 120,
  211. skip: false,
  212. controlPointPreviousX: 17,
  213. controlPointPreviousY: 100
  214. }
  215. },
  216. {
  217. _model: {
  218. x: null,
  219. y: null,
  220. skip: true
  221. }
  222. },
  223. {
  224. _model: {
  225. x: 21,
  226. y: 180,
  227. skip: false,
  228. controlPointNextX: 22,
  229. controlPointNextY: 160
  230. }
  231. },
  232. {
  233. _model: {
  234. x: 24,
  235. y: 120,
  236. skip: false,
  237. controlPointPreviousX: 23,
  238. controlPointPreviousY: 120,
  239. controlPointNextX: 25,
  240. controlPointNextY: 120
  241. }
  242. },
  243. {
  244. _model: {
  245. x: 27,
  246. y: 125,
  247. skip: false,
  248. controlPointPreviousX: 26,
  249. controlPointPreviousY: 125,
  250. controlPointNextX: 28,
  251. controlPointNextY: 125
  252. }
  253. },
  254. {
  255. _model: {
  256. x: 30,
  257. y: 105,
  258. skip: false,
  259. controlPointPreviousX: 29,
  260. controlPointPreviousY: 105,
  261. controlPointNextX: 31,
  262. controlPointNextY: 105
  263. }
  264. },
  265. {
  266. _model: {
  267. x: 33,
  268. y: 110,
  269. skip: false,
  270. controlPointPreviousX: 32,
  271. controlPointPreviousY: 110,
  272. controlPointNextX: 33,
  273. controlPointNextY: 110
  274. }
  275. },
  276. {
  277. _model: {
  278. x: 33,
  279. y: 110,
  280. skip: false,
  281. controlPointPreviousX: 33,
  282. controlPointPreviousY: 110,
  283. controlPointNextX: 34,
  284. controlPointNextY: 110
  285. }
  286. },
  287. {
  288. _model: {
  289. x: 36,
  290. y: 170,
  291. skip: false,
  292. controlPointPreviousX: 35,
  293. controlPointPreviousY: 150
  294. }
  295. }]);
  296. });
  297. it('should get the next or previous item in an array', function() {
  298. var testData = [0, 1, 2];
  299. expect(helpers.nextItem(testData, 0, false)).toEqual(1);
  300. expect(helpers.nextItem(testData, 2, false)).toEqual(2);
  301. expect(helpers.nextItem(testData, 2, true)).toEqual(0);
  302. expect(helpers.nextItem(testData, 1, true)).toEqual(2);
  303. expect(helpers.nextItem(testData, -1, false)).toEqual(0);
  304. expect(helpers.previousItem(testData, 0, false)).toEqual(0);
  305. expect(helpers.previousItem(testData, 0, true)).toEqual(2);
  306. expect(helpers.previousItem(testData, 2, false)).toEqual(1);
  307. expect(helpers.previousItem(testData, 1, true)).toEqual(0);
  308. });
  309. it('should return the width of the longest text in an Array and 2D Array', function() {
  310. var context = window.createMockContext();
  311. var font = "normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
  312. var arrayOfThings1D = ['FooBar', 'Bar'];
  313. var arrayOfThings2D = [['FooBar_1', 'Bar_2'], 'Foo_1'];
  314. // Regardless 'FooBar' is the longest label it should return (characters * 10)
  315. expect(helpers.longestText(context, font, arrayOfThings1D, {})).toEqual(60);
  316. expect(helpers.longestText(context, font, arrayOfThings2D, {})).toEqual(80);
  317. // We check to make sure we made the right calls to the canvas.
  318. expect(context.getCalls()).toEqual([{
  319. name: 'measureText',
  320. args: ['FooBar']
  321. }, {
  322. name: 'measureText',
  323. args: ['Bar']
  324. }, {
  325. name: 'measureText',
  326. args: ['FooBar_1']
  327. }, {
  328. name: 'measureText',
  329. args: ['Bar_2']
  330. }, {
  331. name: 'measureText',
  332. args: ['Foo_1']
  333. }]);
  334. });
  335. it('compare text with current longest and update', function() {
  336. var context = window.createMockContext();
  337. var data = {};
  338. var gc = [];
  339. var longest = 70;
  340. expect(helpers.measureText(context, data, gc, longest, 'foobar')).toEqual(70);
  341. expect(helpers.measureText(context, data, gc, longest, 'foobar_')).toEqual(70);
  342. expect(helpers.measureText(context, data, gc, longest, 'foobar_1')).toEqual(80);
  343. // We check to make sure we made the right calls to the canvas.
  344. expect(context.getCalls()).toEqual([{
  345. name: 'measureText',
  346. args: ['foobar']
  347. }, {
  348. name: 'measureText',
  349. args: ['foobar_']
  350. }, {
  351. name: 'measureText',
  352. args: ['foobar_1']
  353. }]);
  354. });
  355. it('count look at all the labels and return maximum number of lines', function() {
  356. window.createMockContext();
  357. var arrayOfThings1 = ['Foo', 'Bar'];
  358. var arrayOfThings2 = [['Foo', 'Bar'], 'Foo'];
  359. var arrayOfThings3 = [['Foo', 'Bar', 'Boo'], ['Foo', 'Bar'], 'Foo'];
  360. expect(helpers.numberOfLabelLines(arrayOfThings1)).toEqual(1);
  361. expect(helpers.numberOfLabelLines(arrayOfThings2)).toEqual(2);
  362. expect(helpers.numberOfLabelLines(arrayOfThings3)).toEqual(3);
  363. });
  364. it ('should get the maximum width and height for a node', function() {
  365. // Create div with fixed size as a test bed
  366. var div = document.createElement('div');
  367. div.style.width = '200px';
  368. div.style.height = '300px';
  369. document.body.appendChild(div);
  370. // Create the div we want to get the max size for
  371. var innerDiv = document.createElement('div');
  372. div.appendChild(innerDiv);
  373. expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
  374. expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
  375. document.body.removeChild(div);
  376. });
  377. it ('should get the maximum width and height for a node in a ShadowRoot', function() {
  378. // Create div with fixed size as a test bed
  379. var div = document.createElement('div');
  380. div.style.width = '200px';
  381. div.style.height = '300px';
  382. document.body.appendChild(div);
  383. if (!div.attachShadow) {
  384. // Shadow DOM is not natively supported
  385. return;
  386. }
  387. var shadow = div.attachShadow({mode: 'closed'});
  388. // Create the div we want to get the max size for
  389. var innerDiv = document.createElement('div');
  390. shadow.appendChild(innerDiv);
  391. expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
  392. expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
  393. document.body.removeChild(div);
  394. });
  395. it ('should get the maximum width of a node that has a max-width style', function() {
  396. // Create div with fixed size as a test bed
  397. var div = document.createElement('div');
  398. div.style.width = '200px';
  399. div.style.height = '300px';
  400. document.body.appendChild(div);
  401. // Create the div we want to get the max size for and set a max-width style
  402. var innerDiv = document.createElement('div');
  403. innerDiv.style.maxWidth = '150px';
  404. div.appendChild(innerDiv);
  405. expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
  406. document.body.removeChild(div);
  407. });
  408. it ('should get the maximum height of a node that has a max-height style', function() {
  409. // Create div with fixed size as a test bed
  410. var div = document.createElement('div');
  411. div.style.width = '200px';
  412. div.style.height = '300px';
  413. document.body.appendChild(div);
  414. // Create the div we want to get the max size for and set a max-height style
  415. var innerDiv = document.createElement('div');
  416. innerDiv.style.maxHeight = '150px';
  417. div.appendChild(innerDiv);
  418. expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
  419. document.body.removeChild(div);
  420. });
  421. it ('should get the maximum width of a node when the parent has a max-width style', function() {
  422. // Create div with fixed size as a test bed
  423. var div = document.createElement('div');
  424. div.style.width = '200px';
  425. div.style.height = '300px';
  426. document.body.appendChild(div);
  427. // Create an inner wrapper around our div we want to size and give that a max-width style
  428. var parentDiv = document.createElement('div');
  429. parentDiv.style.maxWidth = '150px';
  430. div.appendChild(parentDiv);
  431. // Create the div we want to get the max size for
  432. var innerDiv = document.createElement('div');
  433. parentDiv.appendChild(innerDiv);
  434. expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
  435. document.body.removeChild(div);
  436. });
  437. it ('should get the maximum height of a node when the parent has a max-height style', function() {
  438. // Create div with fixed size as a test bed
  439. var div = document.createElement('div');
  440. div.style.width = '200px';
  441. div.style.height = '300px';
  442. document.body.appendChild(div);
  443. // Create an inner wrapper around our div we want to size and give that a max-height style
  444. var parentDiv = document.createElement('div');
  445. parentDiv.style.maxHeight = '150px';
  446. div.appendChild(parentDiv);
  447. // Create the div we want to get the max size for
  448. var innerDiv = document.createElement('div');
  449. innerDiv.style.height = '300px'; // make it large
  450. parentDiv.appendChild(innerDiv);
  451. expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
  452. document.body.removeChild(div);
  453. });
  454. it ('should get the maximum width of a node that has a percentage max-width style', function() {
  455. // Create div with fixed size as a test bed
  456. var div = document.createElement('div');
  457. div.style.width = '200px';
  458. div.style.height = '300px';
  459. document.body.appendChild(div);
  460. // Create the div we want to get the max size for and set a max-width style
  461. var innerDiv = document.createElement('div');
  462. innerDiv.style.maxWidth = '50%';
  463. div.appendChild(innerDiv);
  464. expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
  465. document.body.removeChild(div);
  466. });
  467. it ('should get the maximum height of a node that has a percentage max-height style', function() {
  468. // Create div with fixed size as a test bed
  469. var div = document.createElement('div');
  470. div.style.width = '200px';
  471. div.style.height = '300px';
  472. document.body.appendChild(div);
  473. // Create the div we want to get the max size for and set a max-height style
  474. var innerDiv = document.createElement('div');
  475. innerDiv.style.maxHeight = '50%';
  476. div.appendChild(innerDiv);
  477. expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
  478. document.body.removeChild(div);
  479. });
  480. it ('should get the maximum width of a node when the parent has a percentage max-width style', function() {
  481. // Create div with fixed size as a test bed
  482. var div = document.createElement('div');
  483. div.style.width = '200px';
  484. div.style.height = '300px';
  485. document.body.appendChild(div);
  486. // Create an inner wrapper around our div we want to size and give that a max-width style
  487. var parentDiv = document.createElement('div');
  488. parentDiv.style.maxWidth = '50%';
  489. div.appendChild(parentDiv);
  490. // Create the div we want to get the max size for
  491. var innerDiv = document.createElement('div');
  492. parentDiv.appendChild(innerDiv);
  493. expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
  494. document.body.removeChild(div);
  495. });
  496. it ('should get the maximum height of a node when the parent has a percentage max-height style', function() {
  497. // Create div with fixed size as a test bed
  498. var div = document.createElement('div');
  499. div.style.width = '200px';
  500. div.style.height = '300px';
  501. document.body.appendChild(div);
  502. // Create an inner wrapper around our div we want to size and give that a max-height style
  503. var parentDiv = document.createElement('div');
  504. parentDiv.style.maxHeight = '50%';
  505. div.appendChild(parentDiv);
  506. var innerDiv = document.createElement('div');
  507. innerDiv.style.height = '300px'; // make it large
  508. parentDiv.appendChild(innerDiv);
  509. expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
  510. document.body.removeChild(div);
  511. });
  512. it ('should leave styled height and width on canvas if explicitly set', function() {
  513. var chart = window.acquireChart({}, {
  514. canvas: {
  515. height: 200,
  516. width: 200,
  517. style: 'height: 400px; width: 400px;'
  518. }
  519. });
  520. helpers.retinaScale(chart, true);
  521. var canvas = chart.canvas;
  522. expect(canvas.style.height).toBe('400px');
  523. expect(canvas.style.width).toBe('400px');
  524. });
  525. it ('Should get padding of parent as number (pixels) when defined as percent (returns incorrectly in IE11)', function() {
  526. // Create div with fixed size as a test bed
  527. var div = document.createElement('div');
  528. div.style.width = '300px';
  529. div.style.height = '300px';
  530. document.body.appendChild(div);
  531. // Inner DIV to have 5% padding of parent
  532. var innerDiv = document.createElement('div');
  533. div.appendChild(innerDiv);
  534. var canvas = document.createElement('canvas');
  535. innerDiv.appendChild(canvas);
  536. // No padding
  537. expect(helpers.getMaximumWidth(canvas)).toBe(300);
  538. // test with percentage
  539. innerDiv.style.padding = '5%';
  540. expect(helpers.getMaximumWidth(canvas)).toBe(270);
  541. // test with pixels
  542. innerDiv.style.padding = '10px';
  543. expect(helpers.getMaximumWidth(canvas)).toBe(280);
  544. document.body.removeChild(div);
  545. });
  546. describe('Color helper', function() {
  547. function isColorInstance(obj) {
  548. return typeof obj === 'object' && obj.hasOwnProperty('values') && obj.values.hasOwnProperty('rgb');
  549. }
  550. it('should return a color when called with a color', function() {
  551. expect(isColorInstance(helpers.color('rgb(1, 2, 3)'))).toBe(true);
  552. });
  553. it('should return a color when called with a CanvasGradient instance', function() {
  554. var context = document.createElement('canvas').getContext('2d');
  555. var gradient = context.createLinearGradient(0, 1, 2, 3);
  556. expect(isColorInstance(helpers.color(gradient))).toBe(true);
  557. });
  558. });
  559. describe('Background hover color helper', function() {
  560. it('should return a CanvasPattern when called with a CanvasPattern', function(done) {
  561. var dots = new Image();
  562. dots.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAD1BMVEUAAAD///////////////+PQt5oAAAABXRSTlMAHlFhZsfk/BEAAAAqSURBVHgBY2BgZGJmYmSAAUYWEIDzmcBcJhiXGcxlRpPFrhdmMiqgvX0AcGIBEUAo6UAAAAAASUVORK5CYII=';
  563. dots.onload = function() {
  564. var chartContext = document.createElement('canvas').getContext('2d');
  565. var patternCanvas = document.createElement('canvas');
  566. var patternContext = patternCanvas.getContext('2d');
  567. var pattern = patternContext.createPattern(dots, 'repeat');
  568. patternContext.fillStyle = pattern;
  569. var backgroundColor = helpers.getHoverColor(chartContext.createPattern(patternCanvas, 'repeat'));
  570. expect(backgroundColor instanceof CanvasPattern).toBe(true);
  571. done();
  572. };
  573. });
  574. it('should return a CanvasGradient when called with a CanvasGradient', function() {
  575. var context = document.createElement('canvas').getContext('2d');
  576. var gradient = context.createLinearGradient(0, 1, 2, 3);
  577. expect(helpers.getHoverColor(gradient) instanceof CanvasGradient).toBe(true);
  578. });
  579. it('should return a modified version of color when called with a color', function() {
  580. var originalColorRGB = 'rgb(70, 191, 189)';
  581. expect(helpers.getHoverColor('#46BFBD')).not.toEqual(originalColorRGB);
  582. });
  583. });
  584. });