2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 12:17:43 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe 'Embedded Snippets' do
|
2020-07-27 12:09:50 +00:00
|
|
|
let_it_be(:snippet) { create(:personal_snippet, :public, :repository) }
|
2021-06-29 03:07:32 +00:00
|
|
|
|
2020-07-27 12:09:50 +00:00
|
|
|
let(:blobs) { snippet.blobs.first(3) }
|
2018-03-17 12:17:43 +00:00
|
|
|
|
|
|
|
it 'loads snippet', :js do
|
2020-07-27 12:09:50 +00:00
|
|
|
expect_any_instance_of(Snippet).to receive(:blobs).and_return(blobs)
|
|
|
|
|
|
|
|
script_url = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}#{snippet_path(snippet, format: 'js')}"
|
2018-03-19 13:30:53 +00:00
|
|
|
embed_body = "<html><body><script src=\"#{script_url}\"></script></body></html>"
|
2018-03-17 12:17:43 +00:00
|
|
|
|
2018-03-19 13:30:53 +00:00
|
|
|
rack_app = proc do
|
|
|
|
['200', { 'Content-Type' => 'text/html' }, [embed_body]]
|
|
|
|
end
|
2018-03-17 12:17:43 +00:00
|
|
|
|
2018-03-19 13:30:53 +00:00
|
|
|
server = Capybara::Server.new(rack_app)
|
|
|
|
server.boot
|
2018-03-17 12:17:43 +00:00
|
|
|
|
2018-03-19 13:30:53 +00:00
|
|
|
visit("http://#{server.host}:#{server.port}/embedded_snippet.html")
|
2018-03-17 12:17:43 +00:00
|
|
|
|
2020-07-27 12:09:50 +00:00
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
blobs.each do |blob|
|
|
|
|
expect(page).to have_content(blob.path)
|
|
|
|
expect(page.find(".snippet-file-content .blob-content[data-blob-id='#{blob.id}'] code")).to have_content(blob.data.squish)
|
2021-07-08 18:09:32 +00:00
|
|
|
expect(page).to have_link('Open raw', href: %r{-/snippets/#{snippet.id}/raw/master/#{blob.path}})
|
|
|
|
expect(page).to have_link('Download', href: %r{-/snippets/#{snippet.id}/raw/master/#{blob.path}\?inline=false})
|
2020-07-27 12:09:50 +00:00
|
|
|
end
|
|
|
|
end
|
2018-03-17 12:17:43 +00:00
|
|
|
end
|
|
|
|
end
|