@@ -25,42 +25,47 @@ import DateWithFormatter from '../src/utils/DateWithFormatter';
2525import testData from './testData' ;
2626import { ProviderWrapper } from './testHelpers' ;
2727
28- describe ( 'sanitizeHeaderId' , ( ) => {
29- test ( 'should sanitize percent sign' , ( ) => {
30- expect ( sanitizeHeaderId ( '%pct_nice' ) ) . toBe ( 'percentpct_nice' ) ;
31- } ) ;
28+ test ( 'sanitizeHeaderId should sanitize percent sign' , ( ) => {
29+ expect ( sanitizeHeaderId ( '%pct_nice' ) ) . toBe ( 'percentpct_nice' ) ;
30+ } ) ;
3231
33- test ( 'should sanitize hash/pound sign' , ( ) => {
34- expect ( sanitizeHeaderId ( '# metric_1' ) ) . toBe ( 'hash_metric_1' ) ;
35- } ) ;
32+ test ( 'sanitizeHeaderId should sanitize hash/pound sign' , ( ) => {
33+ expect ( sanitizeHeaderId ( '# metric_1' ) ) . toBe ( 'hash_metric_1' ) ;
34+ } ) ;
3635
37- test ( 'should sanitize delta symbol' , ( ) => {
38- expect ( sanitizeHeaderId ( '△ delta' ) ) . toBe ( 'delta_delta' ) ;
39- } ) ;
36+ test ( 'sanitizeHeaderId should sanitize delta symbol' , ( ) => {
37+ expect ( sanitizeHeaderId ( '△ delta' ) ) . toBe ( 'delta_delta' ) ;
38+ } ) ;
4039
41- test ( 'should replace spaces with underscores' , ( ) => {
42- expect ( sanitizeHeaderId ( 'Main metric_1' ) ) . toBe ( 'Main_metric_1' ) ;
43- expect ( sanitizeHeaderId ( 'multiple spaces' ) ) . toBe ( 'multiple_spaces' ) ;
44- } ) ;
40+ test ( 'sanitizeHeaderId should replace spaces with underscores' , ( ) => {
41+ expect ( sanitizeHeaderId ( 'Main metric_1' ) ) . toBe ( 'Main_metric_1' ) ;
42+ expect ( sanitizeHeaderId ( 'multiple spaces' ) ) . toBe ( 'multiple_spaces' ) ;
43+ } ) ;
4544
46- test ( 'should handle multiple special characters' , ( ) => {
47- expect ( sanitizeHeaderId ( '% #△ test' ) ) . toBe ( 'percent_hashdelta_test' ) ;
48- expect ( sanitizeHeaderId ( '% # △ test' ) ) . toBe ( 'percent_hash_delta_test' ) ;
49- } ) ;
45+ test ( 'sanitizeHeaderId should handle multiple special characters' , ( ) => {
46+ expect ( sanitizeHeaderId ( '% #△ test' ) ) . toBe ( 'percent_hashdelta_test' ) ;
47+ expect ( sanitizeHeaderId ( '% # △ test' ) ) . toBe ( 'percent_hash_delta_test' ) ;
48+ } ) ;
5049
51- test ( 'should preserve alphanumeric, underscore, and hyphen' , ( ) => {
52- expect ( sanitizeHeaderId ( 'valid-name_123' ) ) . toBe ( 'valid-name_123' ) ;
53- } ) ;
50+ test ( 'sanitizeHeaderId should preserve alphanumeric, underscore, and hyphen' , ( ) => {
51+ expect ( sanitizeHeaderId ( 'valid-name_123' ) ) . toBe ( 'valid-name_123' ) ;
52+ } ) ;
5453
55- test ( 'should replace other special characters with underscore' , ( ) => {
56- expect ( sanitizeHeaderId ( 'col@name!test' ) ) . toBe ( 'col_name_test' ) ;
57- expect ( sanitizeHeaderId ( 'test.column' ) ) . toBe ( 'test_column' ) ;
58- } ) ;
54+ test ( 'sanitizeHeaderId should replace other special characters with underscore' , ( ) => {
55+ expect ( sanitizeHeaderId ( 'col@name!test' ) ) . toBe ( 'col_name_test' ) ;
56+ expect ( sanitizeHeaderId ( 'test.column' ) ) . toBe ( 'test_column' ) ;
57+ } ) ;
5958
60- test ( 'should handle edge cases' , ( ) => {
61- expect ( sanitizeHeaderId ( '' ) ) . toBe ( '' ) ;
62- expect ( sanitizeHeaderId ( 'simple' ) ) . toBe ( 'simple' ) ;
63- } ) ;
59+ test ( 'sanitizeHeaderId should handle edge cases' , ( ) => {
60+ expect ( sanitizeHeaderId ( '' ) ) . toBe ( '' ) ;
61+ expect ( sanitizeHeaderId ( 'simple' ) ) . toBe ( 'simple' ) ;
62+ } ) ;
63+
64+ test ( 'sanitizeHeaderId should collapse consecutive underscores' , ( ) => {
65+ expect ( sanitizeHeaderId ( 'test @@ space' ) ) . toBe ( 'test_space' ) ;
66+ expect ( sanitizeHeaderId ( 'col___name' ) ) . toBe ( 'col_name' ) ;
67+ expect ( sanitizeHeaderId ( 'a b c' ) ) . toBe ( 'a_b_c' ) ;
68+ expect ( sanitizeHeaderId ( 'test@@name' ) ) . toBe ( 'test_name' ) ;
6469} ) ;
6570
6671describe ( 'plugin-chart-table' , ( ) => {
@@ -645,11 +650,11 @@ describe('plugin-chart-table', () => {
645650 header . textContent ?. includes ( 'Sum of Num' ) ,
646651 ) ;
647652 expect ( sumHeader ) . toBeDefined ( ) ;
648- expect ( sumHeader ?. id ) . toBe ( 'header-sum__num ' ) ; // Falls back to column.key, not verbose label
653+ expect ( sumHeader ?. id ) . toBe ( 'header-sum_num ' ) ; // Falls back to column.key, consecutive underscores collapsed
649654
650655 // Verify cells reference this header correctly
651656 const sumCells = container . querySelectorAll (
652- 'td[aria-labelledby="header-sum__num "]' ,
657+ 'td[aria-labelledby="header-sum_num "]' ,
653658 ) ;
654659 expect ( sumCells . length ) . toBeGreaterThan ( 0 ) ;
655660
0 commit comments