Fix test suite

This commit is contained in:
Christoph Haas 2021-03-02 00:51:24 +01:00
parent 2b24083653
commit 47df4d8afd
5 changed files with 44 additions and 37 deletions

View file

@ -61,3 +61,7 @@ Rails.application.configure do
# Needed (at least) for devise.rb to determine the oauth2 callback URL # Needed (at least) for devise.rb to determine the oauth2 callback URL
config.base_url = ENV['DEBSHOTS_BASE_URL'] || 'http://localhost:3000' config.base_url = ENV['DEBSHOTS_BASE_URL'] || 'http://localhost:3000'
end 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 }

View file

@ -1,15 +1,17 @@
require 'test_helper' require 'test_helper'
class PackagesControllerTest < ActionController::TestCase class PackagesControllerTest < ActionController::TestCase
test "should get index" do test "should get index and contain dummy package-4" do
get :grid get :grid
assert_response :success assert_response :success
assert_select 'div', 'package-4'
end end
# test "should get with_screenshots" do test "should get list view with_screenshots and find Firefox" do
# get :with_screenshots get :list, params: { show: 'with' }
# assert_response :success assert_response :success
# end assert_select 'div', 'A program to browse web sites.'
end
# test "should get without_screenshots" do # test "should get without_screenshots" do
# get :without_screenshots # get :without_screenshots

View file

@ -1,17 +1,10 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
# one: firefox_screenshot_approved:
# version: MyString package: firefox
# created_at: 2013-07-27 13:29:55 version: "68.1"
# uploaderhash: MyString approved: true
# uploaderip: MyString created_at: 2020-12-10
# approved: updated_at: 2020-12-11
# description: MyString description: "Some description text"
user: normal
# two:
# version: MyString
# created_at: 2013-07-27 13:29:55
# uploaderhash: MyString
# uploaderip: MyString
# approved:
# description: MyString

View file

@ -12,9 +12,10 @@ normal:
name: Norman Normal name: Norman Normal
created_at: 2018-06-01 created_at: 2018-06-01
updated_at: 2018-06-01 updated_at: 2018-06-01
email: mortal@debian.ork email: mortal@example.org
sign_in_count: 3 sign_in_count: 3
provider: local provider: local
pseudo: true
encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %> encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %>
debian: debian:

View file

@ -4,27 +4,34 @@ class UploadsTest < ApplicationSystemTestCase
test "upload broken screenshot anonymously and get error message" do test "upload broken screenshot anonymously and get error message" do
visit package_path(name: 'firefox') visit package_path(name: 'firefox')
click_on 'Upload a screenshot' click_on 'Upload a screenshot'
attach_file 'file[]', Rails.root.join('test/fixtures/files/large-broken.png') # The actual file field is hidden in favor of a more beautiful button -> visible=false
click_on 'Start upload' 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' assert_text 'large-broken.png must be a valid'
end end
# 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')
# click_on 'Upload a screenshot' img_count_before = page.find_all('img').count
# img_count_before = page.find_all('img').count click_on 'Upload a screenshot'
# attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png') attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png'), visible: false
# click_on 'Start upload'
# img_count_after = page.find_all('img').count
# assert_equal img_count_after, img_count_before + 1
# # Screenshot must be moderated # Upload starts automatically when file is selected.
# newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first # Wait for upload to complete.
# assert_equal newest_screenshot.approved, false # 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 img_count_after = page.find_all('img').count
# newest_screenshot.destroy assert_equal img_count_after, img_count_before + 1
# end
# 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 # test "upload screenshot as Debian SSO user and get auto-approval" do
# sign_in users(:debian) # sign_in users(:debian)