Compare commits

...

5 Commits

Author SHA1 Message Date
benjamin wil 049db3eb69 Refactor keybinding tests
There was an order-dependent test failure that plagued a couple of my
recent pull requests:

    Failure:
    Default_keybindings#test_keybinding_unset
      [/home/runner/work/gollum/gollum/test/test_app.rb:1098]
    Minitest::Assertion: Expected: true
      Actual: false

This commit ensures that `default_keybinding` is set to `nil` before
each test, and that the first line of each test changes the
configuration to the setting under test explicitly.

I also refactored the teardown to `nil` out all instance values so
they'll all certainly be reset when the next set of tests is run.
2022-09-04 15:31:01 -06:00
benjamin wil 395bf26a4b Test localization for some views
In #1853, it was reported that some views are errorring out due to
missing translations. These tests exercise the translations for the
reported views.
2022-09-04 10:45:27 -06:00
benjamin wil d2be3a2347 Don't call nonexistent view method from I18n
The search view doesn't have a `#count` method, meaning this YAML
variable can't be filled properly.
2022-08-25 09:45:01 -07:00
benjamin wil f0b49bc175 Provide ENV to set a custom Chrome binary path
On my system, Chrome is not in the location that the
`Selenium::WebDriver` expects it to be by default. This configuration
setting lets a developer set the path to the Chrome binary explicitly if
necessary.
2022-08-25 09:45:01 -07:00
benjamin wil d66a46f044 Extract Capybara setup to a helper file
Any Capybara-related test setup has been moved to `capybara_helper.rb`.
Now we just must require this file in order to run tests with Capybara.

I also moved the `#console_log` helper to this file to showcase how
other global helper methods could be defined in this file.
2022-08-25 09:45:01 -07:00
6 changed files with 115 additions and 28 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ en:
title: "Overview of %{ref}"
precious/views/search:
aria:
show_all: "Show all %{count} hits in this page"
show_all: Show all hits on this page
back_to_top: Back to Top
no_results: There are no results for your search
search_results_for: Search results for
+23
View File
@@ -0,0 +1,23 @@
require_relative 'helper'
require 'selenium-webdriver'
require 'capybara/dsl'
Selenium::WebDriver::Chrome.path = ENV['CHROME_PATH'] if ENV['CHROME_PATH']
CAPYBARA_DRIVER =
if ENV['CI']
:selenium_chrome_headless
else
ENV.fetch('CAPYBARA_DRIVER', :selenium_chrome).to_sym
end
Capybara.default_driver = CAPYBARA_DRIVER
Capybara.enable_aria_label = true
Capybara.server = :webrick
def console_log(page, level = :severe)
page.driver.browser.logs.get(:browser).select { |log| log.level == level.to_s.upcase }
end
-1
View File
@@ -32,7 +32,6 @@ ENV['RACK_ENV'] = 'test'
require 'gollum'
require 'gollum/app'
CAPYBARA_DRIVER = ENV['CI'] ? :selenium_chrome_headless : ENV.fetch('CAPYBARA_DRIVER', :selenium_chrome).to_sym
# Disable the metadata feature
$METADATA = false
+6 -11
View File
@@ -1,9 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
require 'selenium-webdriver'
require 'capybara/dsl'
Capybara.default_driver = ::CAPYBARA_DRIVER
Capybara.server = :webrick
require_relative '../capybara_helper'
def console_log(page, level = :severe)
page.driver.browser.logs.get(:browser).select{|log| log.level == level.to_s.upcase }
@@ -21,7 +16,7 @@ end
context 'Frontend with mathjax' do
include Capybara::DSL
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
@@ -29,21 +24,21 @@ context 'Frontend with mathjax' do
Precious::App.set(:wiki_options, {mathjax: true})
Capybara.app = Precious::App
end
test 'no unexpected errors on /' do
visit '/'
log = console_log(page)
assert_only_expected_errors(log)
end
test 'no unexpected errors on /create/' do
visit '/create/Foobar'
log = console_log(page)
assert_only_expected_errors(log)
end
teardown do
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
end
+61
View File
@@ -0,0 +1,61 @@
require_relative '../capybara_helper'
context 'Localized frontend' do
include Capybara::DSL
setup do
@path = cloned_testpath "examples/lotr.git"
@wiki = Gollum::Wiki.new(@path)
Precious::App.set :gollum_path, @path
Precious::App.set :wiki_options, {mathjax: true}
Capybara.app = Precious::App
end
test 'can visit search results page' do
visit '/gollum/search'
fill_in('Search', with: 'something-to-return-no-results')
.native
.send_keys(:return)
assert_includes page.text,
'Search results for something-to-return-no-results'
assert_includes page.text,
'There are no results for your search something-to-return-no-results.'
click_on 'Back to Top'
visit '/gollum/search'
fill_in('Search', with: 'Bilbo').native.send_keys(:return)
assert_includes page.text, 'Search results for Bilbo'
click_on 'Show all hits on this page'
click_on 'Bilbo-Baggins.md'
assert page.current_path, '/Bilbo-Baggins.md'
end
test 'can visit overview page' do
visit "/gollum/overview"
assert_includes page.text, 'Overview of master'
assert_includes page.text, 'Home'
click_on 'Back to Top'
click_on 'Bilbo-Baggins.md'
assert page.current_path, '/Bilbo-Baggins.md'
end
teardown do
@path = nil
@wiki = nil
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
+24 -15
View File
@@ -1082,59 +1082,68 @@ context "Default keybindings" do
include Rack::Test::Methods
setup do
@path = cloned_testpath("examples/empty.git")
@wiki = Gollum::Wiki.new(@path)
@path = cloned_testpath "examples/empty.git"
@wiki = Gollum::Wiki.new @path
@url = '/gollum/create/test'
Precious::App.set(:gollum_path, @path)
Precious::App.set :gollum_path, @path
Precious::App.set :wiki_options, {default_keybinding: nil}
end
teardown do
FileUtils.rm_rf(@path)
Precious::App.set(:wiki_options, {default_keybinding: nil})
FileUtils.rm_rf @path
@path = nil
@wiki = nil
@url = nil
end
test 'keybinding unset' do
get @url
assert_equal last_response.body.include?('selected="selected" value="default"'), false
assert_equal last_response.body.include?('selected="selected" value="vim"'), false
assert_equal last_response.body.include?('selected="selected" value="emacs"'), false
end
test 'keybinding `dne`' do
# dne := does not exist
Precious::App.set(:wiki_options, {:default_keybinding => 'dne'})
test 'nonexistent keybinding' do
Precious::App.set :wiki_options, {:default_keybinding => 'does-not-exist'}
get @url
assert_equal last_response.body.include?('selected="selected" value="default"'), false
assert_equal last_response.body.include?('selected="selected" value="vim"'), false
assert_equal last_response.body.include?('selected="selected" value="emacs"'), false
Precious::App.set(:wiki_options, {:default_keybinding => 'none'})
end
test 'keybinding `default`' do
Precious::App.set(:wiki_options, {:default_keybinding => 'default'})
Precious::App.set :wiki_options, {:default_keybinding => 'default'}
get @url
assert_equal last_response.body.include?('selected="selected" value="default"'), true
assert_equal last_response.body.include?('selected="selected" value="vim"'), false
assert_equal last_response.body.include?('selected="selected" value="emacs"'), false
Precious::App.set(:wiki_options, {:default_keybinding => 'none'})
end
test 'keybinding `vim`' do
Precious::App.set(:wiki_options, {:default_keybinding => 'vim'})
Precious::App.set :wiki_options, {:default_keybinding => 'vim'}
get @url
assert_equal last_response.body.include?('selected="selected" value="default"'), false
assert_equal last_response.body.include?('selected="selected" value="vim"'), true
assert_equal last_response.body.include?('selected="selected" value="emacs"'), false
Precious::App.set(:wiki_options, {:default_keybinding => 'none'})
end
test 'keybinding `emacs`' do
Precious::App.set(:wiki_options, {:default_keybinding => 'emacs'})
Precious::App.set :wiki_options, {:default_keybinding => 'emacs'}
get @url
assert_equal last_response.body.include?('selected="selected" value="default"'), false
assert_equal last_response.body.include?('selected="selected" value="vim"'), false
assert_equal last_response.body.include?('selected="selected" value="emacs"'), true
Precious::App.set(:wiki_options, {:default_keybinding => 'none'})
end
def app