Commit 7b182226e290b02ec16bc77379199718959dc574

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent d1a9488c

add functional tests

plugins/community_hub/test/functional/community_hub_plugin_content_viewer_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,108 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +require 'content_viewer_controller'
  3 +
  4 +class ContentViewerController; def rescue_action(e) raise e end; end
  5 +
  6 +class ContentViewerControllerTest < ActionController::TestCase
  7 +
  8 + all_fixtures
  9 +
  10 + def setup
  11 + @controller = ContentViewerController.new
  12 + @request = ActionController::TestRequest.new
  13 + @response = ActionController::TestResponse.new
  14 +
  15 + @user = create_user('testinguser').person
  16 +
  17 + @environment = @user.environment
  18 +
  19 + @community = Community.create!(
  20 + :name => 'Sample community',
  21 + :identifier => 'sample-community',
  22 + :environment => @environment
  23 + )
  24 +
  25 + @hub = CommunityHubPlugin::Hub.new(
  26 + :abstract => 'abstract',
  27 + :body => 'body',
  28 + :name => 'test-hub',
  29 + :profile => community,
  30 + :last_changed_by_id => user.id
  31 + )
  32 +
  33 + @hub.save!
  34 +
  35 + end
  36 +
  37 + attr_reader :user, :environment, :community, :hub
  38 + should 'display live tab' do
  39 + get :view_page, @hub.url
  40 + assert_tag :tag => 'div', :attributes => { :id => 'left-tab' }
  41 + end
  42 +
  43 + should 'display mediation tab' do
  44 + get :view_page, @hub.url
  45 + assert_tag :tag => 'div', :attributes => { :id => 'right-tab' }
  46 + end
  47 +
  48 + should 'display auto scroll checkbox for live stream content' do
  49 + get :view_page, @hub.url
  50 + assert_tag :tag => 'div', :attributes => { :id => 'left-tab' }, :descendant => {
  51 + :tag => 'span', :descendant => {
  52 + :tag => 'input', :attributes => { :id => 'auto_scrolling', :type => 'checkbox' }
  53 + }
  54 + }
  55 + end
  56 +
  57 + should 'not display auto scroll setting for mediation content' do
  58 + get :view_page, @hub.url
  59 + assert_no_tag :tag => 'div', :attributes => { :id => 'right-tab' }, :descendant => {
  60 + :tag => 'span', :descendant => {
  61 + :tag => 'input', :attributes => { :id => 'auto_scrolling', :type => 'checkbox' }
  62 + }
  63 + }
  64 + end
  65 +
  66 + should 'not display message form if user is not logged' do
  67 + get :view_page, @hub.url
  68 + assert_no_tag :tag => 'div', :attributes => { :class => 'form-message' }
  69 + end
  70 +
  71 + should 'not display mediation form if user is not loged' do
  72 + get :view_page, @hub.url
  73 + assert_no_tag :tag => 'div', :attributes => { :class => 'form-mediation' }
  74 + end
  75 +
  76 + should 'display message form if user is logged' do
  77 + user = create_user('visitor')
  78 + login_as(user.login)
  79 + get :view_page, @hub.url
  80 + assert_tag :tag => 'div', :attributes => { :class => 'form-message' }
  81 + end
  82 +
  83 + should 'display mediation form if user is logged and is hub''s mediator' do
  84 + login_as(user.user.login)
  85 + get :view_page, @hub.url
  86 + assert_tag :tag => 'div', :attributes => { :class => 'form-mediation' }
  87 + end
  88 +
  89 + should 'not display mediation form if user is logged but is not hub''s mediator' do
  90 + visitor = create_user('visitor')
  91 + login_as(visitor.login)
  92 + assert_no_tag :tag => 'div', :attributes => { :class => 'form-mediation' }
  93 + end
  94 +
  95 + should 'display link to hub''s settings if user is mediator' do
  96 + login_as(user.user.login)
  97 + get :view_page, @hub.url
  98 + assert_tag :tag => 'div', :attributes => { :class => 'settings' }
  99 + end
  100 +
  101 + should 'not display link to hub''s settings if user is not mediator' do
  102 + visitor = create_user('visitor')
  103 + login_as(visitor.login)
  104 + get :view_page, @hub.url
  105 + assert_no_tag :tag => 'div', :attributes => { :class => 'settings' }
  106 + end
  107 +
  108 +end
... ...
plugins/community_hub/test/functional/community_hub_plugin_public_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,124 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +require File.dirname(__FILE__) + '/../../controllers/public/community_hub_plugin_public_controller'
  3 +
  4 +class CommunityHubPluginPublicController; def rescue_action(e) raise e end; end
  5 +
  6 +class CommunityHubPluginPublicControllerTest < ActionController::TestCase
  7 +
  8 + all_fixtures
  9 +
  10 + def setup
  11 + @controller = CommunityHubPluginPublicController.new
  12 + @request = ActionController::TestRequest.new
  13 + @response = ActionController::TestResponse.new
  14 +
  15 + @user = create_user('testinguser').person
  16 +
  17 + @environment = @user.environment
  18 +
  19 + @community = Community.create!(
  20 + :name => 'Sample community',
  21 + :identifier => 'sample-community',
  22 + :environment => @environment
  23 + )
  24 +
  25 + @community.save!
  26 +
  27 + @hub = CommunityHubPlugin::Hub.new(
  28 + :abstract => 'abstract',
  29 + :body => 'body',
  30 + :name => 'test-hub',
  31 + :profile => community,
  32 + :last_changed_by_id => user.id
  33 + )
  34 +
  35 + @hub.save!
  36 +
  37 + end
  38 +
  39 + attr_reader :user, :environment, :community, :hub
  40 +
  41 + should 'display pin message flag if user is logged and hub\'s mediator' do
  42 + message = create_message( hub, user )
  43 + login_as(user.user.login)
  44 + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id }
  45 + assert_tag :tag => 'li', :attributes => { :class => 'pin' }
  46 + end
  47 +
  48 + should 'not display pin message flag if user is not hub'' mediator' do
  49 + message = create_message( hub, user )
  50 + visitor = create_user('visitor')
  51 + login_as(visitor.login)
  52 + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id }
  53 + assert_no_tag :tag => 'li', :attributes => { :class => 'pin' }
  54 + end
  55 +
  56 + should 'pin message flag is link if message has not been pinned' do
  57 + message = create_message( hub, user )
  58 + login_as(user.user.login)
  59 + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id }
  60 + assert_tag :tag => 'li', :attributes => { :class => 'pin' }, :descendant => {
  61 + :tag => 'a', :descendant => {
  62 + :tag => 'img', :attributes => { :class => 'not-pinned' }
  63 + }
  64 + }
  65 + end
  66 +
  67 + should 'ping message flag is not link if message has beem pinned' do
  68 + message = create_message( hub, user )
  69 + hub.pinned_messages += [message.id]
  70 + hub.save
  71 + login_as(user.user.login)
  72 + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id }
  73 + assert_tag :tag => 'li', :attributes => { :class => 'pin' }, :descendant => {
  74 + :tag => 'img', :attributes => { :class => 'pinned' }
  75 + }
  76 + end
  77 +
  78 + should 'display promote user flag if user is logged and hub\s mediator' do
  79 + mediation = create_mediation(hub, user, community)
  80 + login_as(user.user.login)
  81 + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id }
  82 + assert_tag :tag => 'li', :attributes => { :class => 'promote' }
  83 + end
  84 +
  85 + should 'not display promote user flag if user is not hub''s mediator' do
  86 + mediation = create_mediation(hub, user, community)
  87 + visitor = create_user('visitor')
  88 + login_as(visitor.login)
  89 + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id }
  90 + assert_no_tag :tag => 'li', :attributes => { :class => 'promote' }
  91 + end
  92 +
  93 + should 'promote user flag is link if user has not been promoted' do
  94 + visitor = create_user('visitor').person
  95 + mediation = create_mediation(hub, visitor, community)
  96 + login_as(user.user.login)
  97 + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id }
  98 + assert_tag :tag => 'li', :attributes => { :class => 'promote' }, :descendant => {
  99 + :tag => 'a', :descendant => {
  100 + :tag => 'img', :attributes => { :class => 'not-promoted' }
  101 + }
  102 + }
  103 + end
  104 +
  105 + should 'promote user flag is not link if user has been promoted' do
  106 + mediation = create_mediation(hub, user, community)
  107 + login_as(user.user.login)
  108 + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id }
  109 + assert_tag :tag => 'li', :attributes => { :class => 'promote' }, :descendant => {
  110 + :tag => 'img', :attributes => { :class => 'promoted' }
  111 + }
  112 + end
  113 +
  114 + should 'promote user flag is not link if user is hub''s owner' do
  115 + mediation = create_mediation(hub, user, community)
  116 + login_as(user.user.login)
  117 + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id }
  118 + assert_tag :tag => 'li', :attributes => { :class => 'promote' }, :descendant => {
  119 + :tag => 'img', :attributes => { :class => 'promoted' }
  120 + }
  121 + end
  122 +
  123 +end
  124 +
... ...
plugins/community_hub/test/test_helper.rb
... ... @@ -12,3 +12,27 @@ def create_mediation(hub, community)
12 12 mediation.save!
13 13 mediation
14 14 end
  15 +
  16 +def create_message(hub,user)
  17 + message = Comment.new
  18 + message.author = user
  19 + message.title = "hub-message-#{(Time.now.to_f * 1000).to_i}"
  20 + message.body = 'body'
  21 + message.article = hub
  22 + message.save!
  23 + message
  24 +end
  25 +
  26 +def create_mediation(hub, user, community)
  27 +
  28 + #raise community.inspect
  29 + mediation = CommunityHubPlugin::Mediation.new
  30 + mediation.name = CommunityHubPlugin::Mediation.timestamp
  31 + mediation.profile = community
  32 + mediation.last_changed_by = user
  33 + mediation.created_by_id = user.id
  34 + mediation.source = 'local'
  35 + mediation.parent_id = hub.id
  36 + mediation.save!
  37 + mediation
  38 +end
... ...