cirandas.net

ref: master

plugins/admin_notifications/test/functional/home_controller_test.rb


  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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require 'test_helper'

class HomeController; def rescue_action(e) raise e end;
end

class HomeControllerTest < ActionController::TestCase
  def setup
    @controller = HomeController.new

    @person = create_user('person').person

    @environment = Environment.default
    @environment.enable_plugin('AdminNotificationsPlugin')
    @environment.save!
  end

  attr_accessor :person

  should 'an active notification be displayed on home page for a logged in user' do
    login_as(@person.user.login)
    @notification = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is a Notification Message",
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )
     get :index
     assert_match /Hello, this is a Notification Message/, @response.body
  end


  should 'an active notification not be displayed on home page for unlogged user' do
    @notification = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is a Notification Message",
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )
     get :index
     assert_no_match /Hello, this is a Notification Message/, @response.body
  end

  should 'an active notification be displayed on home page for unlogged user' do
    @notification = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is a Notification Message",
                      :display_to_all_users => true,
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )
     get :index
     assert_match /Hello, this is a Notification Message/, @response.body
  end

  should 'only display the notification with display_to_all_users option for unlogged user ' do
    @notification1 = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is an old Notification Message",
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )

    @notification2 = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is a new Notification Message",
                      :display_to_all_users => true,
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )


     get :index
     assert_no_match /Hello, this is a Notification Message/, @response.body
     assert_match /Hello, this is a new Notification Message/, @response.body
  end

  should 'an inactive notification not be displayed on home page' do
    @notification = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is a Notification Message",
                      :active => false,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )
     get :index
     assert_no_match /Hello, this is a Notification Message/, @response.body
  end


  should 'an active notification not be displayed to a logged in user after been closed by him' do
    login_as(@person.user.login)
    @notification = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Hello, this is a Notification Message",
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )
     @notification.users << @person.user
     @notification.save!
     assert_equal true, @notification.users.include?(@person.user)
     get :index
     assert_no_match /Hello, this is a Notification Message/, @response.body
  end

  should 'a notification be displayed with a Popup' do
    login_as(@person.user.login)
    @notification = AdminNotificationsPlugin::Notification.create(
                      :target => @environment,
                      :message => "Message",
                      :display_popup => true,
                      :active => true,
                      :type => "AdminNotificationsPlugin::DangerNotification"
                    )
     assert_equal true, @notification.display_popup?

     get :index
     assert_no_match /div id="cboxWrapper"/, @response.body
  end
end