Commit c70993fd authored by James Lopez's avatar James Lopez

Merge branch 'test-help-markdown-rendering-as-view-tests' into 'master'

Test Markdown rendering in Help page with view tests

See merge request gitlab-org/gitlab!30490
parents af4bb5e9 e52c2490
......@@ -84,7 +84,6 @@
- "{,ee/}rubocop/**/*"
- "{,ee/}spec/**/*"
- "doc/README.md" # Some RSpec test rely on this file
- "doc/administration/raketasks/maintenance.md" # Some RSpec test rely on this file
.code-patterns: &code-patterns
- "{package.json,yarn.lock}"
......@@ -128,7 +127,6 @@
- "{,ee/}rubocop/**/*"
- "{,ee/}spec/**/*"
- "doc/README.md" # Some RSpec test rely on this file
- "doc/administration/raketasks/maintenance.md" # Some RSpec test rely on this file
.code-qa-patterns: &code-qa-patterns
- "{package.json,yarn.lock}"
......@@ -171,7 +169,6 @@
- "{,ee/}rubocop/**/*"
- "{,ee/}spec/**/*"
- "doc/README.md" # Some RSpec test rely on this file
- "doc/administration/raketasks/maintenance.md" # Some RSpec test rely on this file
# QA changes
- ".dockerignore"
- "qa/**/*"
......
......@@ -26,7 +26,7 @@ class HelpController < ApplicationController
respond_to do |format|
format.any(:markdown, :md, :html) do
# Note: We are purposefully NOT using `Rails.root.join`
# Note: We are purposefully NOT using `Rails.root.join` because of https://gitlab.com/gitlab-org/gitlab/-/issues/216028.
path = File.join(Rails.root, 'doc', "#{@path}.md")
if File.exist?(path)
......@@ -42,7 +42,7 @@ class HelpController < ApplicationController
# Allow access to specific media files in the doc folder
format.any(:png, :gif, :jpeg, :mp4, :mp3) do
# Note: We are purposefully NOT using `Rails.root.join`
# Note: We are purposefully NOT using `Rails.root.join` because of https://gitlab.com/gitlab-org/gitlab/-/issues/216028.
path = File.join(Rails.root, 'doc', "#{@path}.#{params[:format]}")
if File.exist?(path)
......
......@@ -99,6 +99,7 @@ describe HelpController do
context 'for Markdown formats' do
context 'when requested file exists' do
before do
expect(File).to receive(:read).and_return(fixture_file('blockquote_fence_after.md'))
get :show, params: { path: 'ssh/README' }, format: :md
end
......@@ -108,7 +109,7 @@ describe HelpController do
it 'renders HTML' do
expect(response).to render_template('show.html.haml')
expect(response.content_type).to eq 'text/html'
expect(response.media_type).to eq 'text/html'
end
end
......@@ -129,7 +130,7 @@ describe HelpController do
},
format: :png
expect(response).to be_successful
expect(response.content_type).to eq 'image/png'
expect(response.media_type).to eq 'image/png'
expect(response.headers['Content-Disposition']).to match(/^inline;/)
end
end
......@@ -168,6 +169,6 @@ describe HelpController do
end
def stub_readme(content)
allow(File).to receive(:read).and_return(content)
expect(File).to receive(:read).and_return(content)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Dashboard Help' do
before do
sign_in(create(:user))
end
context 'documentation' do
it 'renders correctly markdown' do
visit help_page_path("administration/raketasks/maintenance")
expect(page).to have_content('Gather GitLab and system information')
node = find('.documentation h2 a#user-content-check-gitlab-configuration')
expect(node[:href]).to eq '#check-gitlab-configuration'
expect(find(:xpath, "#{node.path}/..").text).to eq 'Check GitLab configuration'
end
end
end
......@@ -53,6 +53,18 @@ describe 'help/index' do
end
end
describe 'Markdown rendering' do
before do
assign(:help_index, 'Welcome to [GitLab](https://about.gitlab.com/) Documentation.')
end
it 'renders Markdown' do
render
expect(rendered).to have_link('GitLab', href: 'https://about.gitlab.com/')
end
end
def stub_user(user = double)
allow(view).to receive(:user_signed_in?).and_return(user)
end
......
# frozen_string_literal: true
require 'spec_helper'
describe 'help/show' do
describe 'Markdown rendering' do
before do
assign(:path, 'ssh/README')
assign(:markdown, 'Welcome to [GitLab](https://about.gitlab.com/) Documentation.')
end
it 'renders Markdown' do
render
expect(rendered).to have_link('GitLab', href: 'https://about.gitlab.com/')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment