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

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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)