class-spec.ts 2.4 KB

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