Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system tests for spam2 #8038

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/spam2/_nodes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ $(document).ready(function () {
<a class="badge btn badge-pill badge<% if node.status != 0 %>-danger<% else %>-secondary disabled<% end %> spam" data-remote="true" href="/moderate/spam/<%= node.id %>"><i class="fa fa-ban fa-white"></i> Spam post</a>
<a class="badge badge-pill badge-secondary ban a<%= node.author.id %>" <% if node.author.status == 0 %>style="display:none;"<% end %> data-remote="true" href="/ban/<%= node.author.id %>">Ban user</a>
<a class="badge badge-pill badge-secondary unban a-unban<%= node.author.id %>" <% if node.author.status == 1 %>style="display:none;"<% end %> data-remote="true" href="/unban/<%= node.author.id %>">Unban user</a>
<%= link_to "/notes/delete/#{node.id}", data: { confirm: 'Are you sure you want to delete "'+node.path+'"?' }, :remote => true, :class => "px-3 delete" do %>
<%= link_to "/notes/delete/#{node.id}", data: { confirm: "Are you sure you want to delete #{node.path}?" }, :remote => true, :class => "px-3 delete" do %>
<i class="fa fa-trash"></i>
<% end %>
<script>
Expand Down
176 changes: 156 additions & 20 deletions test/system/spam2_test.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,160 @@
require "application_system_test_case"

class SpamTest < ApplicationSystemTestCase
def setup
visit "/spam2"
click_on "Login"
fill_in 'user_session[username]', with: 'palpatine'
fill_in 'user_session[password]', with: 'secretive'
click_on "Log in"
end

test "Delete post in spam2" do
spam_page = nodes(:one)
visit spam_page.path
first("span[data-original-title='Tools']").click()
click_on "Spam"
visit "/spam2"
accept_confirm 'Are you sure you want to delete "'+spam_page.path+'"?' do
find("a[href='/notes/delete/#{spam_page.id}'").click()
end
assert_selector('div.alert', text: 'Node Deleted')
end
end

def setup
visit "/"
click_on "Login"
fill_in 'user_session[username]', with: 'palpatine'
fill_in 'user_session[password]', with: 'secretive'
click_on "Log in"
end

test "Delete node in spam2" do
spam_page = nodes(:first_timer_note)
visit "/spam2"
accept_confirm "Are you sure you want to delete #{spam_page.path}?" do
find("a[href='/notes/delete/#{spam_page.id}'").click()
end
assert_selector('div.alert', text: 'Node Deleted')
end

test "publish node in spam2" do
publish_page = nodes(:first_timer_note)
visit "/spam2"
find("a[href='/moderate/publish/#{publish_page.id}'").click()
page.assert_selector("div.alert", text: "Content published.")
end

test "spam post in spam2" do
spam_page = nodes(:first_timer_note)
visit "/spam2"
find("a[href='/moderate/spam/#{spam_page.id}'").click()
page.assert_selector("div.alert", text: "Content spammed.")
end

test "ban and unban authors in spam2" do
ban_page = nodes(:first_timer_note)
visit "/spam2"
within "#n#{ban_page.id}" do
find("a[href='/ban/#{ban_page.author.id}'").click()
end
visit "/profile/#{ban_page.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/unban/#{ban_page.author.id}'"
visit "/spam2"
within "#n#{ban_page.id}" do
find("a[href='/unban/#{ban_page.author.id}'").click()
end
visit "/profile/#{ban_page.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/ban/#{ban_page.author.id}'"
end

test "batch spam nodes" do
banned_page1 = nodes(:first_timer_note)
banned_page2 = nodes(:first_timer_question)
visit "/spam2"
# Click on the checkboxes of unmoderated nodes
within "#n#{banned_page1.id}" do
find(".selectedId").click()
end
within "#n#{banned_page2.id}" do
find(".selectedId").click()
end
find("#batch-spam").click()
page.assert_selector "div.alert-success"
#check if author is banned
visit "/profile/#{banned_page1.author.username}"
assert find("div.alert", text: "That user has been banned.")
find("a#info-ellipsis").click()
page.assert_selector "a[href='/unban/#{banned_page1.author.id}'"
visit "/profile/#{banned_page2.author.username}"
assert find("div.alert", text: "That user has been banned.")
find("a#info-ellipsis").click()
page.assert_selector "a[href='/unban/#{banned_page2.author.id}']"
end

test "Batch publish nodes" do
page1 = nodes(:first_timer_note)
page2 = nodes(:first_timer_question)
visit "/spam2"
within "#n#{page1.id}" do
find(".selectedId").click()
end
within "#n#{page2.id}" do
find(".selectedId").click()
end
find("#batch-publish").click()
page.assert_selector "div.alert-success"
visit "/profile/#{page1.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/ban/#{page1.author.id}'"
visit "/profile/#{page2.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/ban/#{page2.author.id}'"
end

test "batch delete nodes" do
page1 = nodes(:first_timer_note)
page2 = nodes(:first_timer_question)
visit "/spam2"
within "#n#{page1.id}" do
find(".selectedId").click()
end
within "#n#{page2.id}" do
find(".selectedId").click()
end
find("#delete-batch").click()
assert_selector('div.alert', text: '2 nodes deleted')
end

test "Batch ban and batch unban" do
page1 = nodes(:first_timer_note)
page2 = nodes(:first_timer_question)
visit "/spam2"
within "#n#{page1.id}" do
find(".selectedId").click()
end
within "#n#{page2.id}" do
find(".selectedId").click()
end
find("#batch-ban").click()
assert_selector('div.alert', text: '2 users banned.')
visit "/profile/#{page1.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/unban/#{page1.author.id}'"
visit "/profile/#{page2.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/unban/#{page2.author.id}'"

visit "/spam2"
within "#n#{page1.id}" do
find(".selectedId").click()
end
within "#n#{page2.id}" do
find(".selectedId").click()
end
find("#batch-unban").click()
assert_selector('div.alert', text: '2 users unbanned.')
visit "/profile/#{page1.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/ban/#{page1.author.id}'"
visit "/profile/#{page2.author.username}"
find("a#info-ellipsis").click()
page.assert_selector "a[href='/ban/#{page2.author.id}'"
end

test "select count" do
page1 = nodes(:first_timer_note)
page2 = nodes(:first_timer_question)
visit "/spam2"
within "#n#{page1.id}" do
find(".selectedId").click()
end
within "#n#{page2.id}" do
find(".selectedId").click()
end
assert_selector('#select-count', text: '2')
end
end