ref: master
plugins/comment_paragraph/test/unit/comment_paragraph_plugin_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 |
require_relative '../test_helper' include ActionView::Helpers::FormTagHelper class CommentParagraphPluginTest < ActiveSupport::TestCase def setup @environment = Environment.default @user = create_user('testuser').person context = mock() context.stubs(:user).returns(@user) @plugin = CommentParagraphPlugin.new(context) end attr_reader :environment, :plugin, :user should 'have a name' do assert_not_equal Noosfero::Plugin.plugin_name, CommentParagraphPlugin::plugin_name end should 'describe yourself' do assert_not_equal Noosfero::Plugin.plugin_description, CommentParagraphPlugin::plugin_description end should 'have a js file' do assert !plugin.js_files.blank? end should 'have stylesheet' do assert plugin.stylesheet? end should 'not add comment_paragraph_selected_area if comment_paragraph_selected_area is blank' do comment = Comment.new comment.comment_paragraph_selected_area = "" comment.paragraph_uuid = 2 cpp = CommentParagraphPlugin.new prok = cpp.comment_form_extra_contents({:comment=>comment, :paragraph_uuid=>4}) assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect) end should 'display button to toggle comment paragraph for users which can edit the article' do profile = fast_create(Profile) article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) assert_not_equal [], plugin.article_extra_toolbar_buttons(article) end should 'not display button to toggle comment paragraph for users which can not edit the article' do profile = fast_create(Profile) article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(false) assert_equal [], plugin.article_extra_toolbar_buttons(article) end should 'not display button to toggle comment paragraph if plugin is not enabled' do profile = fast_create(Profile) article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(false) assert_equal [], plugin.article_extra_toolbar_buttons(article) end should 'display Activate Comments title if comment paragraph plugin is activated' do profile = fast_create(Profile) article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(false) assert_equal 'Activate Comments', plugin.article_extra_toolbar_buttons(article).first[:title] end should 'display Deactivate Comments title if comment paragraph plugin is deactivated' do profile = fast_create(Profile) article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(true) assert_equal 'Deactivate Comments', plugin.article_extra_toolbar_buttons(article).first[:title] end should 'display export comments button when comment paragraph plugin is activated' do profile = fast_create(Profile) article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) article.expects(:comment_paragraph_plugin_activated?).at_least_once.returns(true) assert_includes plugin.article_extra_toolbar_buttons(article).map {|b| b[:title]}, 'Export Comments' end should 'not display button to toggle comment paragraph if article is a discussion' do profile = fast_create(Profile) article = fast_create(CommentParagraphPlugin::Discussion, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) assert_equal [], plugin.article_extra_toolbar_buttons(article) end end |