|
37 | 37 | expect(parsed.at("script:contains('function(value){return value + \" rabbits\"')")).not_to \
|
38 | 38 | be_nil
|
39 | 39 | end
|
40 |
| - end |
41 | 40 |
|
42 |
| - context '.render when defer = true' do |
43 |
| - it 'renders div and script elements' do |
44 |
| - html = described_class.render(options.merge({defer: true})) |
| 41 | + context 'when global options are set' do |
| 42 | + let(:default_options) { { tootip: true } } |
| 43 | + |
| 44 | + before do |
| 45 | + allow(ApexCharts.config) |
| 46 | + .to receive(:default_options) |
| 47 | + .and_return(default_options) |
| 48 | + end |
| 49 | + |
| 50 | + it 'renders a script with window.Apex initialization ' \ |
| 51 | + 'before rendering first chart' do |
| 52 | + html = described_class.render(options.merge(div: {id: 'chart-1'})) |
| 53 | + parsed = Nokogiri::HTML.parse(html) |
| 54 | + script = parsed.css('script') |
| 55 | + |
| 56 | + expect(script).not_to be_empty |
45 | 57 |
|
46 |
| - expect(html).to include 'var createChart = function()' |
47 |
| - expect(html).to include 'window.addEventListener' |
| 58 | + expect(script.text) |
| 59 | + .to include("window.Apex = #{default_options.to_json}") |
| 60 | + end |
48 | 61 | end
|
49 |
| - end |
50 | 62 |
|
51 |
| - context '.render when module = true' do |
52 |
| - it 'renders div and script elements' do |
53 |
| - html = described_class.render(options.merge({module: true})) |
| 63 | + context 'when defer = true' do |
| 64 | + it 'renders div and script elements' do |
| 65 | + html = described_class.render(options.merge({defer: true})) |
| 66 | + |
| 67 | + expect(html).to include 'var createChart = function()' |
| 68 | + expect(html).to include 'window.addEventListener' |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context 'when module = true' do |
| 73 | + it 'renders div and script elements' do |
| 74 | + html = described_class.render(options.merge({module: true})) |
54 | 75 |
|
55 |
| - expect(html).to include 'type="module"' |
| 76 | + expect(html).to include 'type="module"' |
| 77 | + end |
56 | 78 | end
|
57 | 79 | end
|
58 | 80 | end
|
0 commit comments