We were using the form and then showing it with JavaScript when advanced search terms were present. Now we hide it with JavaScript when no advanced search are present. This means users without JavaScript (including users with JavaScript enabled but bad internet connections preventing the JavaScript to load) can now access the form. The other main difference between the two versions is the way the form flashes while JavaScript is loading. Previously, the form would always be hidden when no terms had been introduced. However, when these terms were present, after submitting the form it would briefly be hidden and then shown again. Now the opposite happens. When advanced search terms are present, the form is shown at all times. However, when they aren't, the form is briefly shown before it disappears. Here the previous behavior is arguably better because most of the time these terms will not be present. So basically we're significantly improving the experience of some users at the cost of slightly worsen the experience of other users. We're also hiding the button to show the form when JavaScript is disabled, since in this scenario it's useless. We're using the `hidden` attribute so hidden buttons can be detected in CSS.
54 lines
1.5 KiB
Ruby
54 lines
1.5 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Shared::AdvancedSearchComponent, type: :component do
|
|
let(:component) { Shared::AdvancedSearchComponent.new }
|
|
|
|
context "JavaScript disabled" do
|
|
it "renders the form" do
|
|
render_inline component
|
|
|
|
expect(page).to have_button "Filter"
|
|
end
|
|
|
|
it "hides the button to show the form" do
|
|
render_inline component
|
|
|
|
expect(page).to have_button "Advanced search", visible: :hidden
|
|
end
|
|
end
|
|
|
|
describe "SDG filter" do
|
|
before do
|
|
Setting["feature.sdg"] = true
|
|
Setting["sdg.process.proposals"] = true
|
|
|
|
allow(component).to receive(:controller_path).and_return("proposals")
|
|
end
|
|
|
|
it "does not render when the feature is disabled" do
|
|
Setting["feature.sdg"] = false
|
|
|
|
render_inline component
|
|
|
|
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
|
expect(page).not_to have_selector "#advanced_search_target", visible: :all
|
|
end
|
|
|
|
it "does not render when the SDG process feature is disabled" do
|
|
Setting["sdg.process.proposals"] = false
|
|
|
|
render_inline component
|
|
|
|
expect(page).not_to have_selector "#advanced_search_goal", visible: :all
|
|
expect(page).not_to have_selector "#advanced_search_target", visible: :all
|
|
end
|
|
|
|
it "renders when both features are enabled" do
|
|
render_inline component
|
|
|
|
expect(page).to have_selector "#advanced_search_goal", visible: :all
|
|
expect(page).to have_selector "#advanced_search_target", visible: :all
|
|
end
|
|
end
|
|
end
|