class-spec.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. describe('c3 chart class', function () {
  2. 'use strict';
  3. var chart;
  4. var args = {
  5. data: {
  6. columns: [
  7. ['data1', 30, 200, 100, 400, 150, 250],
  8. ['data2 prefix', 50, 20, 10, 40, 15, 25],
  9. ['data3 мужчины', 150, 120, 110, 140, 115, 125]
  10. ]
  11. }
  12. };
  13. beforeEach(function (done) {
  14. chart = window.initChart(chart, args, done);
  15. });
  16. describe('internal.generateTargetClass', function () {
  17. it('should not replace any characters', function () {
  18. var input = 'data1',
  19. expected = '-' + input,
  20. suffix = chart.internal.generateTargetClass(input);
  21. expect(suffix).toBe(expected);
  22. });
  23. it('should replace space to "-"', function () {
  24. var input = 'data1 suffix',
  25. expected = '-data1-suffix',
  26. suffix = chart.internal.generateTargetClass(input);
  27. expect(suffix).toBe(expected);
  28. });
  29. it('should replace space to "-" with multibyte characters', function () {
  30. var input = 'data1 suffix 日本語',
  31. expected = '-data1-suffix-日本語',
  32. suffix = chart.internal.generateTargetClass(input);
  33. expect(suffix).toBe(expected);
  34. });
  35. it('should not replace special characters', function () {
  36. var input = 'data1 !@#$%^&*()_=+,.<>"\':;[]/|?~`{}\\',
  37. expected = '-data1-!@#$%^&*()_=+,.<>"\':;[]/|?~`{}\\',
  38. suffix = chart.internal.generateTargetClass(input);
  39. expect(suffix).toBe(expected);
  40. });
  41. });
  42. describe('internal.getTargetSelectorSuffix', function () {
  43. it('should escape special characters', function () {
  44. var input = 'data1 !@#$%^&*()_=+,.<>"\':;[]/|?~`{}\\',
  45. expected = '-data1-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\=\\+\\,\\.\\<\\>\\"\\\'\\:\\;\\[\\]\\/\\|\\?\\~\\`\\{\\}\\\\',
  46. suffix = chart.internal.getTargetSelectorSuffix(input);
  47. expect(suffix).toBe(expected);
  48. });
  49. });
  50. describe('multibyte characters on chart', function () {
  51. it('should replace space to "-" with multibyte characters', function () {
  52. var selector = '.c3-target-data3-мужчины';
  53. expect(chart.internal.main.select(selector).size()).toBe(1);
  54. });
  55. });
  56. });