From 29af24432772f0464883b8c5743d970f4e3a63d2 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Fri, 30 Oct 2020 21:51:56 +0100 Subject: [PATCH] Migrating tests to system tests --- test/functional/browse_test.rb | 14 ------- test/functional/login_test.rb | 28 ------------- test/functional/upload_test.rb | 74 ---------------------------------- test/system/users_test.rb | 28 ++++++++++++- 4 files changed, 27 insertions(+), 117 deletions(-) delete mode 100644 test/functional/browse_test.rb delete mode 100644 test/functional/login_test.rb delete mode 100644 test/functional/upload_test.rb diff --git a/test/functional/browse_test.rb b/test/functional/browse_test.rb deleted file mode 100644 index bd543ec..0000000 --- a/test/functional/browse_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'test_helper' - -class BrowserBrowseTest < ActionDispatch::IntegrationTest - test "user can see home page" do - visit root_path - page.must_have_content /This website lets you browse screenshots of [\d,]+ software packages/ - end - - test "user can browse packages" do - visit packages_grid_path - page.must_have_content /Previous/ - page.must_have_link href: packages_grid_path(page: 2) - end -end diff --git a/test/functional/login_test.rb b/test/functional/login_test.rb deleted file mode 100644 index 57a259e..0000000 --- a/test/functional/login_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'test_helper' - -class BrowserBrowseTest < ActionDispatch::IntegrationTest - test "login and check profile page" do - visit root_path - click_link 'Login' - - within 'form' do - fill_in 'email address', with: users(:normal).email - fill_in 'password', with: 'normalsecret' - click_button 'Log in' - end - - assert_equal 200, status_code - assert_current_path my_welcome_path - page.must_have_content 'You are now logged in' - - click_on 'profile page' - page.must_have_content users(:normal).email - end - - test "guest can browse packages" do - visit packages_grid_path - assert_equal 200, status_code - page.must_have_content /Previous/ - page.must_have_link href: packages_grid_path(page: 2) - end -end diff --git a/test/functional/upload_test.rb b/test/functional/upload_test.rb deleted file mode 100644 index 250f206..0000000 --- a/test/functional/upload_test.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'test_helper' - -class BrowserBrowseTest < ActionDispatch::IntegrationTest - 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' - page.must_have_content 'The image large-broken.png is not 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 - - # 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) - visit upload_path(name: 'firefox') - 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 - - # Screenshot is instantly public - newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first - assert_equal newest_screenshot.approved, true - - # Clean up - newest_screenshot.destroy - sign_out users(:debian) - end - - test "upload screenshot anonymously, login in, get screenshots assigned" do - visit upload_path(name: 'firefox') - attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png') - click_on 'Start upload' - - # Screenshot has not yet a user assigned - newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first - assert_nil newest_screenshot.user - - # Login (sign_in is just a stub and would not call the callbacks!) - visit root_path - click_link 'Login' - within 'form' do - fill_in 'email address', with: users(:normal).email - fill_in 'password', with: 'normalsecret' - click_button 'Log in' - end - - # Check if screenshot was assigned to the user - newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first - assert_equal newest_screenshot.user, users(:normal) - - # Clean up - newest_screenshot.destroy - sign_out users(:debian) - end - -end diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 2bbe0a2..e220f07 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -4,11 +4,37 @@ class UsersTest < ApplicationSystemTestCase test "go to login page" do visit new_user_session_path - fill_in 'user[email]', with: 'admin@debian.ork' + fill_in 'user[email]', with: users(:admin).email fill_in 'user[password]', with: 'adminsecret' click_on 'commit' assert_text 'Signed in successfully' end + + # TODO: these cases must be changed to the Rails System Tests syntax + # test "login and check profile page" do + # visit root_path + # click_link 'Login' + + # within 'form' do + # fill_in 'email address', with: users(:normal).email + # fill_in 'password', with: 'normalsecret' + # click_button 'Log in' + # end + + # assert_equal 200, status_code + # assert_current_path my_welcome_path + # page.must_have_content 'You are now logged in' + + # click_on 'profile page' + # page.must_have_content users(:normal).email + # end + + # test "guest can browse packages" do + # visit packages_grid_path + # assert_equal 200, status_code + # page.must_have_content /Previous/ + # page.must_have_link href: packages_grid_path(page: 2) + # end end