1
0

Added system tests under Redmine 4

This commit is contained in:
cryptogopher 2020-08-08 15:39:13 +02:00
parent c79e03d0f4
commit 66a364d017
7 changed files with 140 additions and 2 deletions

View File

@ -1,4 +1,5 @@
class CreateSchema < ActiveRecord::Migration
class CreateSchema <
(Rails::VERSION::MAJOR < 5 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2])
def change
create_table :quantities do |t|
t.references :project

View File

@ -1,4 +1,5 @@
class LoadDefaults < ActiveRecord::Migration
class LoadDefaults <
(Rails::VERSION::MAJOR < 5 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2])
def change
reversible do |dir|
dir.up do

View File

@ -1,6 +1,7 @@
(Rails::VERSION::MAJOR < 5 ? ActionDispatch : ActiveSupport)::Reloader.to_prepare do
Project.include BodyTracking::ProjectPatch
CollectiveIdea.include BodyTracking::AwesomeNestedSetPatch
ActionController::TestCase.include BodyTracking::PluginFixturesLoader if Rails.env == 'test'
end
Redmine::Plugin.register :body_tracking do

View File

@ -0,0 +1,10 @@
module BodyTracking::PluginFixturesLoader
def self.included(base)
base.class_eval do
def self.plugin_fixtures(*symbols)
fixtures_dir = File.expand_path('../../test/fixtures/', __FILE__)
ActiveRecord::Fixtures.create_fixtures(fixtures_dir, symbols)
end
end
end
end

View File

@ -0,0 +1,96 @@
# Required for Puma to start in test env for system tests
# (RAILS_ENV=test does not work)
ENV["RACK_ENV"] = "test"
# Load the Redmine helper
require File.expand_path('../../../../test/application_system_test_case', __FILE__)
class BodyTrackingSystemTestCase < ApplicationSystemTestCase
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = DOWNLOADS_PATH
profile['browser.download.folderList'] = 2
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
profile['pdfjs.disabled'] = true
driven_by :selenium, using: :headless_firefox, screen_size: [1280, 720], options: {
profile: profile
}
Capybara.configure do |config|
config.save_path = './tmp/screenshots/'
end
fixtures :projects
# fixtures :users, :email_addresses, :trackers, :projects,
# :roles, :members, :member_roles, :enabled_modules
plugin_fixtures :targets
include AbstractController::Translation
def logout_user
click_link t(:label_logout)
assert_current_path home_path
assert_link t(:label_login)
end
def create_recurrence(issue=issues(:issue_01), **attributes)
#attributes[:mode] ||= :weekly
t_base = 'issues.recurrences.form'
visit issue_path(issue)
assert_difference ['all("#recurrences tr").length', 'IssueRecurrence.count'], 1 do
within '#issue_recurrences' do
click_link t(:button_add)
attributes.each do |k, v|
value = case k
when :mode
interval = t("#{t_base}.mode_intervals.#{v}")
description = t("#{t_base}.mode_descriptions.#{v}")
"#{interval}(s)" + (description.present? ? ", #{description}" : '')
when :anchor_to_start
t("#{t_base}.#{k.to_s}.#{v}")
else
t("#{t_base}.#{k.to_s.pluralize}.#{v}")
end
select strip_tags(value), from: "recurrence_#{k}"
end
click_button t(:button_add)
end
# status_code not supported by Selenium
assert_current_path issue_path(issue)
assert_selector '#recurrence-errors', visible: :all, exact_text: ''
end
IssueRecurrence.last
end
def destroy_recurrence(recurrence)
visit issue_path(recurrence.issue)
assert_difference ['all("#recurrences tr").length', 'IssueRecurrence.count'], -1 do
within "#recurrences tr[id=recurrence-#{recurrence.id}]" do
click_link t(:button_delete)
end
# status_code not supported by Selenium
assert_current_path issue_path(recurrence.issue)
assert_selector '#recurrence-errors', visible: :all, exact_text: ''
end
end
def close_issue(issue)
assert !issue.closed?
closed_on = issue.closed_on
status = IssueStatus.all.where(is_closed: true).first
visit edit_issue_path(issue)
within 'form#issue-form' do
select status.name, from: t(:field_status)
click_button t(:button_submit)
end
issue.reload
assert_equal status.id, issue.status_id
assert_not_nil issue.closed_on
assert_not_equal closed_on, issue.closed_on
assert issue.closed?
end
end

2
test/fixtures/targets.yml vendored Normal file
View File

@ -0,0 +1,2 @@
targets_01:
condition: '=='

View File

@ -0,0 +1,27 @@
require File.expand_path('../../application_system_test_case', __FILE__)
class TargetsTest < BodyTrackingSystemTestCase
def setup
super
@project1 = projects(:projects_001)
log_user 'alice', 'foo'
end
def teardown
logout_user
super
end
def test_index
assert_not_equal 0, @project1.targets.count
visit project_targets_path(@project1)
assert_current_path project_targets_path(@project1)
end
def test_index_without_targets
#assert_equal 0, @project1.targets.count
#assert_selector 'div#targets', visible: :yes, exact_text: l(:label_no_data)
end
end