diff --git a/lib/apex_charts/config/default_options.rb b/lib/apex_charts/config/default_options.rb index e81b386..4ebef3e 100644 --- a/lib/apex_charts/config/default_options.rb +++ b/lib/apex_charts/config/default_options.rb @@ -5,7 +5,7 @@ module Config module DefaultOptions def default_options=(options) @default_options = - ApexCharts::OptionsBuilder.new(nil, options).build_general_options + ApexCharts::OptionsBuilder.new(nil, options).build_global_options end def default_options diff --git a/lib/apex_charts/options_builder.rb b/lib/apex_charts/options_builder.rb index 8cb7443..c27621a 100644 --- a/lib/apex_charts/options_builder.rb +++ b/lib/apex_charts/options_builder.rb @@ -17,6 +17,11 @@ def initialize(sample, options) @built = {} end + def build_global_options + build_chart + build_general_options + end + def build_options build_chart build_div @@ -45,7 +50,7 @@ def build_general_options build_tooltip build_xaxis build_yaxis - built.compact + built.compact! end def build_div diff --git a/spec/options_builder/global_spec.rb b/spec/options_builder/global_spec.rb new file mode 100644 index 0000000..225911d --- /dev/null +++ b/spec/options_builder/global_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +RSpec.describe '#build_global_options' do + let(:sample) { nil } + let(:options) { + { + chart: {background: '#ddd', height: 350}, + id: 'an-html-element-id', + var: 'aVariableName', + class: 'the-div-class', + style: 'css-style', + chart_id: 'a-chart-id', + group: 'group-name', + height: 300, + width: 400, + stacked: true, + animations: true, + sparkline: true, + background: '#ccc', + fore_color: '#fc9' + } + } + let(:ob) { + ApexCharts::OptionsBuilder.new(sample, options) + } + let(:expected_built) { + { + chart: { + id: 'a-chart-id', + animations: {enabled: true}, + background: '#ddd', + foreColor: '#fc9', + group: 'group-name', + height: 350, + width: 400, + sparkline: {enabled: true}, + stacked: true + }, + defer: false, + module: false + } + } + + it 'exclude div related key-values' do + ob.build_global_options + expect(ob.built).to match(expected_built) + end +end