Skip to content

Commit

Permalink
Merge pull request #346 from dmacvicar/fix_flickering_test
Browse files Browse the repository at this point in the history
Fix flickering search test
  • Loading branch information
Chris Kowalczyk committed Jun 22, 2018
2 parents 3cc3b15 + 90be335 commit 36faa02
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/models/seeker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.search(query, baseproject, project = nil, exclude_filter = nil, exclude
xpath_items << "contains-ic(@name, " + substring_words + ")"
end
words.select {|word| word.match(/^".+"$/) }.map {|word| word.gsub("\"", "") }.each do |word|
xpath_items << "@name = '#{word.gsub(/['"()]/, "")}' "
xpath_items << "@name = '#{word.gsub(/['"()]/, "")}'"
end
xpath_items << "path/project='#{baseproject}'" unless baseproject.blank?
xpath_items << "not(contains-ic(@project, '#{exclude_filter}'))" if (!exclude_filter.blank? && project.blank?)
Expand Down
2 changes: 2 additions & 0 deletions app/views/package/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= render :partial => 'search/default_searches' if @search_term %>
<% if @packages.blank? %>
<div class="py-5">
<div class="container">
Expand Down
7 changes: 7 additions & 0 deletions app/views/search/_default_searches.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if DEFAULT_SEARCHES[@search_term] %>
<div id="search-result-error" >
<div id="msg" class="alert alert-info"/>
<%=DEFAULT_SEARCHES[@search_term].html_safe %>
</div>
</div>
<% end %>
8 changes: 1 addition & 7 deletions app/views/search/_find_results.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<div id="search-result" class="py-3">
<div class="container">

<% if DEFAULT_SEARCHES[@search_term] %>
<div id="search-result-error" >
<div id="msg" class="alert alert-info"/>
<%=DEFAULT_SEARCHES[@search_term].html_safe %>
</div>
</div>
<% end %>
<%= render :partial => 'search/default_searches' if @search_term %>
<%= render :partial => 'search/category_header' if @category %>
Expand Down
36 changes: 22 additions & 14 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,27 @@ def stub_search_random(term, baseproject, opts = {})
repo = baseproject.tr(':', '_')
project = "home:#{user}"
filepath = "#{project.gsub(':', ':/')}/#{repo}/#{arch}/#{file}"
xml.binary do
xml.name bin
xml.project project
xml.package pkg
xml.repository repo
xml.version ver
xml.release rel
xml.arch arch
xml.filename file
xml.filepath filepath
xml.baseproject project
xml.type 'rpm'
exact_match_builder = Nokogiri::XML::Builder.new do |exact_xml|
exact_xml.collection(matches: 1) do
[xml, exact_xml].each do |x|
x.binary do
x.name bin
x.project project
x.package pkg
x.repository repo
x.version ver
x.release rel
x.arch arch
x.filename file
x.filepath filepath
x.baseproject project
x.type 'rpm'
end
end
end
end
xpath = "@name = '#{bin}'"
stub_content("https://api.opensuse.org/search/published/binary/id?match=#{URI.escape(xpath)}", exact_match_builder.to_xml)
builder_fileinfo = Nokogiri::XML::Builder.new do |info_xml|
info_xml.fileinfo(filename: file) do
info_xml.name bin
Expand All @@ -71,13 +79,13 @@ def stub_search_random(term, baseproject, opts = {})
end
end
stub_content("https://api.opensuse.org/published/#{project}/#{repo}/#{arch}/#{file}?view=fileinfo", builder_fileinfo.to_xml)
stub_content("https://api.opensuse.org/source/#{project}/_attribute/OBS:QualityCategory", "<attributes/>")
end
end
end
# rubocop:enable Metrics/BlockLength

xpath = "@project = '#{baseproject}' and contains-ic(@name, '#{term}') and path/project='#{baseproject}'"
stub_content("api.opensuse.org/search/published/binary/id?match=#{URI.escape(xpath)}", builder.to_xml)
stub_content("https://api.opensuse.org/search/published/binary/id?match=#{URI.escape(xpath)}", builder.to_xml)
end

Expand All @@ -92,7 +100,7 @@ def stub_search_random(term, baseproject, opts = {})

stub_remote_file("https://download.opensuse.org/tumbleweed/repo/oss/repodata/#{APPDATA_CHECKSUM}-appdata.xml.gz", "appdata.xml.gz")
stub_remote_file("https://download.opensuse.org/tumbleweed/repo/non-oss/repodata/#{APPDATA_NON_OSS_CHECKSUM}-appdata.xml.gz", "appdata-non-oss.xml.gz")
stub_remote_file("https://api.opensuse.org/search/published/binary/id?match=@name%20=%20'pidgin'%20", "pidgin.xml")
stub_remote_file("https://api.opensuse.org/search/published/binary/id?match=@name%20=%20'pidgin'", "pidgin.xml")
stub_remote_file("https://api.opensuse.org/published/openSUSE:13.1/standard/i586/pidgin-2.10.7-4.1.3.i586.rpm?view=fileinfo", "pidgin-fileinfo.xml")
stub_content("https://api.opensuse.org/source/openSUSE:13.1/_attribute/OBS:QualityCategory", "<attributes/>")
end
Expand Down

0 comments on commit 36faa02

Please sign in to comment.