@@ -53,6 +53,42 @@ describe('Export Csv', () => {
53
53
expect . stringContaining ( '.csv' )
54
54
)
55
55
} )
56
+ it ( 'export csv from simple bar chart with numeric series names should call triggerDownload with csv encoded file data' , ( ) => {
57
+ var options = {
58
+ chart : {
59
+ height : 380 ,
60
+ width : "100%" ,
61
+ type : "bar"
62
+ } ,
63
+ series : [
64
+ {
65
+ name : 2022 ,
66
+ data : [ 1 , 2 ]
67
+ } ,
68
+ {
69
+ name : 2023 ,
70
+ data : [ 2 , 3 ]
71
+ }
72
+ ] ,
73
+ xaxis : {
74
+ categories : [ "Category 1" , "Category 2" ]
75
+ }
76
+ } ;
77
+ const csvData = "category,2022,2023\n" +
78
+ "Category 1,,2\n" +
79
+ "Category 2,,3"
80
+ const chart = createChartWithOptions ( options )
81
+ chart . w . globals . collapsedSeriesIndices = [ 0 ]
82
+ const exports = new Exports ( chart . ctx )
83
+ jest . spyOn ( Exports . prototype , 'triggerDownload' )
84
+ exports . exportToCSV ( chart . w . config . series , 'fileName' )
85
+ expect ( Exports . prototype . triggerDownload ) . toHaveBeenCalledTimes ( 1 )
86
+ expect ( Exports . prototype . triggerDownload ) . toHaveBeenCalledWith (
87
+ expect . stringContaining ( encodeURIComponent ( csvData ) ) ,
88
+ expect . toBeUndefined ,
89
+ expect . stringContaining ( '.csv' )
90
+ )
91
+ } )
56
92
it ( 'export csv from simple line chart with two series should call triggerDownload with csv encoded file data' , ( ) => {
57
93
const series = [ { name : 'series 1' , data : [ 0 , 1 ] } , { name : 'series 2' , data : [ 1 , 2 ] } ]
58
94
const csvData = "category,series 1,series 2\n" +
@@ -69,6 +105,22 @@ describe('Export Csv', () => {
69
105
expect . stringContaining ( '.csv' )
70
106
)
71
107
} )
108
+ it ( 'export csv from simple line chart with numeric series names should call triggerDownload with csv encoded file data' , ( ) => {
109
+ const series = [ { name : 2022 , data : [ 0 , 1 ] } , { name : 2023 , data : [ 1 , 2 ] } ]
110
+ const csvData = "category,2022,2023\n" +
111
+ "1,0,1\n" +
112
+ "2,1,2"
113
+ const chart = createChart ( 'line' , series )
114
+ const exports = new Exports ( chart . ctx )
115
+ jest . spyOn ( Exports . prototype , 'triggerDownload' )
116
+ exports . exportToCSV ( chart . w . config . series , 'fileName' )
117
+ expect ( Exports . prototype . triggerDownload ) . toHaveBeenCalledTimes ( 1 )
118
+ expect ( Exports . prototype . triggerDownload ) . toHaveBeenCalledWith (
119
+ expect . stringContaining ( encodeURIComponent ( csvData ) ) ,
120
+ expect . toBeUndefined ,
121
+ expect . stringContaining ( '.csv' )
122
+ )
123
+ } )
72
124
it ( "export csv from simple line chart with two x y series should call triggerDownload with csv encoded file data" , ( ) => {
73
125
const series = [ {
74
126
name : 'series 1' ,
0 commit comments