diff --git a/config/environments/test.rb b/config/environments/test.rb index 9434e4c..759f825 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -61,3 +61,7 @@ Rails.application.configure do # Needed (at least) for devise.rb to determine the oauth2 callback URL config.base_url = ENV['DEBSHOTS_BASE_URL'] || 'http://localhost:3000' end + +# Set base URL to be used in links in mails +# https://github.com/rails/rails/issues/29992 +Rails.application.default_url_options = { host: 'localhost', port: 3000 } diff --git a/test/controllers/packages_controller_test.rb b/test/controllers/packages_controller_test.rb index 2cd206d..873097a 100644 --- a/test/controllers/packages_controller_test.rb +++ b/test/controllers/packages_controller_test.rb @@ -1,15 +1,17 @@ require 'test_helper' class PackagesControllerTest < ActionController::TestCase - test "should get index" do + test "should get index and contain dummy package-4" do get :grid assert_response :success + assert_select 'div', 'package-4' end - # test "should get with_screenshots" do - # get :with_screenshots - # assert_response :success - # end + test "should get list view with_screenshots and find Firefox" do + get :list, params: { show: 'with' } + assert_response :success + assert_select 'div', 'A program to browse web sites.' + end # test "should get without_screenshots" do # get :without_screenshots diff --git a/test/fixtures/screenshots.yml b/test/fixtures/screenshots.yml index 866dbc4..ac7a416 100644 --- a/test/fixtures/screenshots.yml +++ b/test/fixtures/screenshots.yml @@ -1,17 +1,10 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html -# one: -# version: MyString -# created_at: 2013-07-27 13:29:55 -# uploaderhash: MyString -# uploaderip: MyString -# approved: -# description: MyString - -# two: -# version: MyString -# created_at: 2013-07-27 13:29:55 -# uploaderhash: MyString -# uploaderip: MyString -# approved: -# description: MyString +firefox_screenshot_approved: + package: firefox + version: "68.1" + approved: true + created_at: 2020-12-10 + updated_at: 2020-12-11 + description: "Some description text" + user: normal diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 6ca6461..24edb60 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -12,9 +12,10 @@ normal: name: Norman Normal created_at: 2018-06-01 updated_at: 2018-06-01 - email: mortal@debian.ork + email: mortal@example.org sign_in_count: 3 provider: local + pseudo: true encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %> debian: diff --git a/test/system/uploads_test.rb b/test/system/uploads_test.rb index 1d6a863..64c5af2 100644 --- a/test/system/uploads_test.rb +++ b/test/system/uploads_test.rb @@ -4,27 +4,34 @@ class UploadsTest < ApplicationSystemTestCase test "upload broken screenshot anonymously and get error message" do visit package_path(name: 'firefox') click_on 'Upload a screenshot' - attach_file 'file[]', Rails.root.join('test/fixtures/files/large-broken.png') - click_on 'Start upload' + # The actual file field is hidden in favor of a more beautiful button -> visible=false + attach_file 'file[]', Rails.root.join('test/fixtures/files/large-broken.png'), visible: false + # Upload starts automatically through Javascript trigger assert_text 'large-broken.png must be a valid' end - # test "upload png screenshot anonymously and await moderation" do - # visit package_path(name: 'firefox') - # click_on 'Upload a screenshot' - # img_count_before = page.find_all('img').count - # attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png') - # click_on 'Start upload' - # img_count_after = page.find_all('img').count - # assert_equal img_count_after, img_count_before + 1 + test "upload png screenshot anonymously and await moderation" do + visit package_path(name: 'firefox') + img_count_before = page.find_all('img').count + click_on 'Upload a screenshot' + attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png'), visible: false - # # Screenshot must be moderated - # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first - # assert_equal newest_screenshot.approved, 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') + assert page.has_content?('needs to be approved') - # # Clean up - # newest_screenshot.destroy - # end + img_count_after = page.find_all('img').count + assert_equal img_count_after, img_count_before + 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 + end # test "upload screenshot as Debian SSO user and get auto-approval" do # sign_in users(:debian)