diff --git a/app/views/packages/_admin_buttons.slim b/app/views/packages/_admin_buttons.slim index f85f7eb..fe92b6d 100644 --- a/app/views/packages/_admin_buttons.slim +++ b/app/views/packages/_admin_buttons.slim @@ -2,7 +2,7 @@ - if can?(:destroy, screenshot) || can?(:approve, screenshot) .text - span.label.secondary + span.label.secondary.adminlabel = status_text(screenshot) .button-group.small.align-center diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 24edb60..fdd6a4f 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -18,11 +18,12 @@ normal: pseudo: true encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %> -debian: +moderator: name: Detlef Debian created_at: 2018-01-01 updated_at: 2018-01-01 email: detlef@debian.org sign_in_count: 0 - provider: salsa - encrypted_password: nil + provider: local + moderator_role: true + encrypted_password: <%= Devise::Encryptor.digest(User, 'moderatorsecret') %> diff --git a/test/system/uploads_test.rb b/test/system/uploads_test.rb index 64c5af2..5da22c9 100644 --- a/test/system/uploads_test.rb +++ b/test/system/uploads_test.rb @@ -12,7 +12,9 @@ class UploadsTest < ApplicationSystemTestCase test "upload png screenshot anonymously and await moderation" do 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' 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?('needs to be approved') - img_count_after = page.find_all('img').count - assert_equal img_count_after, img_count_before + 1 + img_count2 = page.find_all('img').count + #Rails::logger.debug "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 1=#{img_count2}" + + assert_equal img_count2, img_count1 + 1 # Screenshot must be moderated newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first assert_equal newest_screenshot.approved, false - # Clean up - newest_screenshot.destroy + # Delete the screenshot + 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 + 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 # sign_in users(:debian) # visit upload_path(name: 'firefox')