From 7b182226e290b02ec16bc77379199718959dc574 Mon Sep 17 00:00:00 2001 From: Francisco Marcelo de Araújo Lima Júnior Date: Thu, 29 May 2014 19:30:50 -0300 Subject: [PATCH] add functional tests --- plugins/community_hub/test/functional/community_hub_plugin_content_viewer_controller_test.rb | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_hub/test/functional/community_hub_plugin_public_controller_test.rb | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_hub/test/test_helper.rb | 24 ++++++++++++++++++++++++ 3 files changed, 256 insertions(+), 0 deletions(-) create mode 100644 plugins/community_hub/test/functional/community_hub_plugin_content_viewer_controller_test.rb create mode 100644 plugins/community_hub/test/functional/community_hub_plugin_public_controller_test.rb diff --git a/plugins/community_hub/test/functional/community_hub_plugin_content_viewer_controller_test.rb b/plugins/community_hub/test/functional/community_hub_plugin_content_viewer_controller_test.rb new file mode 100644 index 0000000..c2cbf35 --- /dev/null +++ b/plugins/community_hub/test/functional/community_hub_plugin_content_viewer_controller_test.rb @@ -0,0 +1,108 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'content_viewer_controller' + +class ContentViewerController; def rescue_action(e) raise e end; end + +class ContentViewerControllerTest < ActionController::TestCase + + all_fixtures + + def setup + @controller = ContentViewerController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @user = create_user('testinguser').person + + @environment = @user.environment + + @community = Community.create!( + :name => 'Sample community', + :identifier => 'sample-community', + :environment => @environment + ) + + @hub = CommunityHubPlugin::Hub.new( + :abstract => 'abstract', + :body => 'body', + :name => 'test-hub', + :profile => community, + :last_changed_by_id => user.id + ) + + @hub.save! + + end + + attr_reader :user, :environment, :community, :hub + should 'display live tab' do + get :view_page, @hub.url + assert_tag :tag => 'div', :attributes => { :id => 'left-tab' } + end + + should 'display mediation tab' do + get :view_page, @hub.url + assert_tag :tag => 'div', :attributes => { :id => 'right-tab' } + end + + should 'display auto scroll checkbox for live stream content' do + get :view_page, @hub.url + assert_tag :tag => 'div', :attributes => { :id => 'left-tab' }, :descendant => { + :tag => 'span', :descendant => { + :tag => 'input', :attributes => { :id => 'auto_scrolling', :type => 'checkbox' } + } + } + end + + should 'not display auto scroll setting for mediation content' do + get :view_page, @hub.url + assert_no_tag :tag => 'div', :attributes => { :id => 'right-tab' }, :descendant => { + :tag => 'span', :descendant => { + :tag => 'input', :attributes => { :id => 'auto_scrolling', :type => 'checkbox' } + } + } + end + + should 'not display message form if user is not logged' do + get :view_page, @hub.url + assert_no_tag :tag => 'div', :attributes => { :class => 'form-message' } + end + + should 'not display mediation form if user is not loged' do + get :view_page, @hub.url + assert_no_tag :tag => 'div', :attributes => { :class => 'form-mediation' } + end + + should 'display message form if user is logged' do + user = create_user('visitor') + login_as(user.login) + get :view_page, @hub.url + assert_tag :tag => 'div', :attributes => { :class => 'form-message' } + end + + should 'display mediation form if user is logged and is hub''s mediator' do + login_as(user.user.login) + get :view_page, @hub.url + assert_tag :tag => 'div', :attributes => { :class => 'form-mediation' } + end + + should 'not display mediation form if user is logged but is not hub''s mediator' do + visitor = create_user('visitor') + login_as(visitor.login) + assert_no_tag :tag => 'div', :attributes => { :class => 'form-mediation' } + end + + should 'display link to hub''s settings if user is mediator' do + login_as(user.user.login) + get :view_page, @hub.url + assert_tag :tag => 'div', :attributes => { :class => 'settings' } + end + + should 'not display link to hub''s settings if user is not mediator' do + visitor = create_user('visitor') + login_as(visitor.login) + get :view_page, @hub.url + assert_no_tag :tag => 'div', :attributes => { :class => 'settings' } + end + +end diff --git a/plugins/community_hub/test/functional/community_hub_plugin_public_controller_test.rb b/plugins/community_hub/test/functional/community_hub_plugin_public_controller_test.rb new file mode 100644 index 0000000..15978b8 --- /dev/null +++ b/plugins/community_hub/test/functional/community_hub_plugin_public_controller_test.rb @@ -0,0 +1,124 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/public/community_hub_plugin_public_controller' + +class CommunityHubPluginPublicController; def rescue_action(e) raise e end; end + +class CommunityHubPluginPublicControllerTest < ActionController::TestCase + + all_fixtures + + def setup + @controller = CommunityHubPluginPublicController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @user = create_user('testinguser').person + + @environment = @user.environment + + @community = Community.create!( + :name => 'Sample community', + :identifier => 'sample-community', + :environment => @environment + ) + + @community.save! + + @hub = CommunityHubPlugin::Hub.new( + :abstract => 'abstract', + :body => 'body', + :name => 'test-hub', + :profile => community, + :last_changed_by_id => user.id + ) + + @hub.save! + + end + + attr_reader :user, :environment, :community, :hub + + should 'display pin message flag if user is logged and hub\'s mediator' do + message = create_message( hub, user ) + login_as(user.user.login) + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'pin' } + end + + should 'not display pin message flag if user is not hub'' mediator' do + message = create_message( hub, user ) + visitor = create_user('visitor') + login_as(visitor.login) + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id } + assert_no_tag :tag => 'li', :attributes => { :class => 'pin' } + end + + should 'pin message flag is link if message has not been pinned' do + message = create_message( hub, user ) + login_as(user.user.login) + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'pin' }, :descendant => { + :tag => 'a', :descendant => { + :tag => 'img', :attributes => { :class => 'not-pinned' } + } + } + end + + should 'ping message flag is not link if message has beem pinned' do + message = create_message( hub, user ) + hub.pinned_messages += [message.id] + hub.save + login_as(user.user.login) + xhr :get, :newer_comments, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'pin' }, :descendant => { + :tag => 'img', :attributes => { :class => 'pinned' } + } + end + + should 'display promote user flag if user is logged and hub\s mediator' do + mediation = create_mediation(hub, user, community) + login_as(user.user.login) + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'promote' } + end + + should 'not display promote user flag if user is not hub''s mediator' do + mediation = create_mediation(hub, user, community) + visitor = create_user('visitor') + login_as(visitor.login) + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id } + assert_no_tag :tag => 'li', :attributes => { :class => 'promote' } + end + + should 'promote user flag is link if user has not been promoted' do + visitor = create_user('visitor').person + mediation = create_mediation(hub, visitor, community) + login_as(user.user.login) + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'promote' }, :descendant => { + :tag => 'a', :descendant => { + :tag => 'img', :attributes => { :class => 'not-promoted' } + } + } + end + + should 'promote user flag is not link if user has been promoted' do + mediation = create_mediation(hub, user, community) + login_as(user.user.login) + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'promote' }, :descendant => { + :tag => 'img', :attributes => { :class => 'promoted' } + } + end + + should 'promote user flag is not link if user is hub''s owner' do + mediation = create_mediation(hub, user, community) + login_as(user.user.login) + xhr :get, :newer_articles, { :latest_post => 0, :hub => hub.id } + assert_tag :tag => 'li', :attributes => { :class => 'promote' }, :descendant => { + :tag => 'img', :attributes => { :class => 'promoted' } + } + end + +end + diff --git a/plugins/community_hub/test/test_helper.rb b/plugins/community_hub/test/test_helper.rb index e6572fc..4aedadb 100644 --- a/plugins/community_hub/test/test_helper.rb +++ b/plugins/community_hub/test/test_helper.rb @@ -12,3 +12,27 @@ def create_mediation(hub, community) mediation.save! mediation end + +def create_message(hub,user) + message = Comment.new + message.author = user + message.title = "hub-message-#{(Time.now.to_f * 1000).to_i}" + message.body = 'body' + message.article = hub + message.save! + message +end + +def create_mediation(hub, user, community) + + #raise community.inspect + mediation = CommunityHubPlugin::Mediation.new + mediation.name = CommunityHubPlugin::Mediation.timestamp + mediation.profile = community + mediation.last_changed_by = user + mediation.created_by_id = user.id + mediation.source = 'local' + mediation.parent_id = hub.id + mediation.save! + mediation +end -- libgit2 0.21.2