File: javascript_alert_spec.rb

package info (click to toggle)
ruby-uniform-notifier 1.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: ruby: 915; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe UniformNotifier::JavascriptAlert do
  it 'should not notify message' do
    expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to be_nil
  end

  it 'should notify message' do
    UniformNotifier.alert = true
    expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
      <script type="text/javascript">/*<![CDATA[*/
      alert( "javascript alert!" );
      /*]]>*/</script>
    CODE
  end

  it 'should accept custom attributes' do
    UniformNotifier.alert = { attributes: { :nonce => 'my-nonce', 'data-key' => :value } }
    expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
      <script type="text/javascript" nonce="my-nonce" data-key="value">/*<![CDATA[*/
      alert( "javascript alert!" );
      /*]]>*/</script>
    CODE
  end

  it 'should have default attributes if no attributes settings exist' do
    UniformNotifier.alert = {}
    expect(UniformNotifier::JavascriptAlert.inline_notify(title: 'javascript alert!')).to eq <<~CODE
      <script type="text/javascript">/*<![CDATA[*/
      alert( "javascript alert!" );
      /*]]>*/</script>
    CODE
  end
end