2019-08-22 10:57:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-01 17:01:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::SnippetSearchResults do
|
2019-09-09 13:46:24 +00:00
|
|
|
include SearchHelpers
|
|
|
|
|
2020-04-29 09:10:04 +00:00
|
|
|
let_it_be(:snippet) { create(:snippet, content: 'foo', file_name: 'foo') }
|
2021-04-03 00:09:02 +00:00
|
|
|
|
2019-09-30 15:08:09 +00:00
|
|
|
let(:results) { described_class.new(snippet.author, 'foo') }
|
2016-03-01 17:01:09 +00:00
|
|
|
|
|
|
|
describe '#snippet_titles_count' do
|
|
|
|
it 'returns the amount of matched snippet titles' do
|
2019-09-30 15:08:09 +00:00
|
|
|
expect(results.limited_snippet_titles_count).to eq(1)
|
2016-03-01 17:01:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-15 17:59:57 +00:00
|
|
|
describe '#formatted_count' do
|
2020-04-29 09:10:04 +00:00
|
|
|
it 'returns the expected formatted count' do
|
|
|
|
expect(results).to receive(:limited_snippet_titles_count).and_return(1234)
|
|
|
|
expect(results.formatted_count('snippet_titles')).to eq(max_limited_count)
|
2019-07-15 17:59:57 +00:00
|
|
|
end
|
|
|
|
end
|
2020-05-07 21:09:26 +00:00
|
|
|
|
2020-10-08 15:08:17 +00:00
|
|
|
describe '#highlight_map' do
|
|
|
|
it 'returns the expected highlight map' do
|
|
|
|
expect(results.highlight_map('snippet_titles')).to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-07 21:09:26 +00:00
|
|
|
describe '#objects' do
|
|
|
|
it 'uses page and per_page to paginate results' do
|
|
|
|
snippet2 = create(:snippet, :public, content: 'foo', file_name: 'foo')
|
|
|
|
|
|
|
|
expect(results.objects('snippet_titles', page: 1, per_page: 1).to_a).to eq([snippet2])
|
|
|
|
expect(results.objects('snippet_titles', page: 2, per_page: 1).to_a).to eq([snippet])
|
|
|
|
expect(results.objects('snippet_titles', page: 1, per_page: 2).count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2016-03-01 17:01:09 +00:00
|
|
|
end
|