System test added to verify auto-approval of screenshots from moderators
This commit is contained in:
parent
47df4d8afd
commit
86bfff58f2
3 changed files with 60 additions and 9 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
- if can?(:destroy, screenshot) || can?(:approve, screenshot)
|
- if can?(:destroy, screenshot) || can?(:approve, screenshot)
|
||||||
.text
|
.text
|
||||||
span.label.secondary
|
span.label.secondary.adminlabel
|
||||||
= status_text(screenshot)
|
= status_text(screenshot)
|
||||||
|
|
||||||
.button-group.small.align-center
|
.button-group.small.align-center
|
||||||
|
|
|
||||||
7
test/fixtures/users.yml
vendored
7
test/fixtures/users.yml
vendored
|
|
@ -18,11 +18,12 @@ normal:
|
||||||
pseudo: true
|
pseudo: true
|
||||||
encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %>
|
encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %>
|
||||||
|
|
||||||
debian:
|
moderator:
|
||||||
name: Detlef Debian
|
name: Detlef Debian
|
||||||
created_at: 2018-01-01
|
created_at: 2018-01-01
|
||||||
updated_at: 2018-01-01
|
updated_at: 2018-01-01
|
||||||
email: detlef@debian.org
|
email: detlef@debian.org
|
||||||
sign_in_count: 0
|
sign_in_count: 0
|
||||||
provider: salsa
|
provider: local
|
||||||
encrypted_password: nil
|
moderator_role: true
|
||||||
|
encrypted_password: <%= Devise::Encryptor.digest(User, 'moderatorsecret') %>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ class UploadsTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
test "upload png screenshot anonymously and await moderation" do
|
test "upload png screenshot anonymously and await moderation" do
|
||||||
visit package_path(name: 'firefox')
|
visit package_path(name: 'firefox')
|
||||||
img_count_before = page.find_all('img').count
|
img_count1 = page.find_all('img').count
|
||||||
|
#Rails::logger.debug "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 1=#{img_count1}"
|
||||||
|
|
||||||
click_on 'Upload a screenshot'
|
click_on 'Upload a screenshot'
|
||||||
attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png'), visible: false
|
attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png'), visible: false
|
||||||
|
|
||||||
|
|
@ -22,17 +24,65 @@ class UploadsTest < ApplicationSystemTestCase
|
||||||
assert page.has_content?('Uploaded by you')
|
assert page.has_content?('Uploaded by you')
|
||||||
assert page.has_content?('needs to be approved')
|
assert page.has_content?('needs to be approved')
|
||||||
|
|
||||||
img_count_after = page.find_all('img').count
|
img_count2 = page.find_all('img').count
|
||||||
assert_equal img_count_after, img_count_before + 1
|
#Rails::logger.debug "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 1=#{img_count2}"
|
||||||
|
|
||||||
|
assert_equal img_count2, img_count1 + 1
|
||||||
|
|
||||||
# Screenshot must be moderated
|
# Screenshot must be moderated
|
||||||
newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
|
||||||
assert_equal newest_screenshot.approved, false
|
assert_equal newest_screenshot.approved, false
|
||||||
|
|
||||||
# Clean up
|
# Delete the screenshot
|
||||||
newest_screenshot.destroy
|
click_on 'Delete'
|
||||||
|
page.accept_alert
|
||||||
|
|
||||||
|
# Wait for redirect to details page
|
||||||
|
assert page.has_content?('Homepage')
|
||||||
|
img_count3 = page.find_all('img').count
|
||||||
|
#Rails::logger.debug "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 1=#{img_count3}"
|
||||||
|
|
||||||
|
assert_equal img_count3, img_count1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "upload png screenshot as moderator and expect auto-approval" do
|
||||||
|
|
||||||
|
# Delete all screenshots for the Firefox package
|
||||||
|
Package.find_by_name(:firefox).screenshots.delete_all
|
||||||
|
|
||||||
|
# Sign in
|
||||||
|
visit new_user_session_path
|
||||||
|
fill_in 'user[email]', with: users(:moderator).email
|
||||||
|
fill_in 'user[password]', with: 'moderatorsecret'
|
||||||
|
click_on 'Sign in'
|
||||||
|
|
||||||
|
# Get details page of Firefox package
|
||||||
|
visit package_path(name: 'firefox')
|
||||||
|
|
||||||
|
click_on 'Upload a screenshot'
|
||||||
|
attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png'), visible: false
|
||||||
|
|
||||||
|
# Upload starts automatically when file is selected.
|
||||||
|
# Wait for upload to complete.
|
||||||
|
# https://github.com/teamcapybara/capybara#asynchronous-javascript-ajax-and-friends
|
||||||
|
assert page.has_content?('Uploaded by you')
|
||||||
|
|
||||||
|
# Find a label reading "Public"
|
||||||
|
assert_selector '.adminlabel', text: /Public/
|
||||||
|
|
||||||
|
# Check if the screenshot is auto-approved
|
||||||
|
newest_screenshot = Package.find_by_name(:firefox).screenshots.first
|
||||||
|
assert_equal newest_screenshot.approved, true
|
||||||
|
|
||||||
|
# Delete the screenshot
|
||||||
|
click_on 'Delete'
|
||||||
|
page.accept_alert
|
||||||
|
|
||||||
|
# Wait for redirect to details page
|
||||||
|
assert page.has_content?('Homepage')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# test "upload screenshot as Debian SSO user and get auto-approval" do
|
# test "upload screenshot as Debian SSO user and get auto-approval" do
|
||||||
# sign_in users(:debian)
|
# sign_in users(:debian)
|
||||||
# visit upload_path(name: 'firefox')
|
# visit upload_path(name: 'firefox')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue