Commit e7f9dff2 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'fj-fix-bug-rendering-snippet-blob-markdown' into 'master'

Fix bug rendering BlobType markdown data

See merge request gitlab-org/gitlab!24960
parents bd2736fb 31e843e4
......@@ -8,11 +8,11 @@ module Types
description 'Represents the snippet blob'
present_using SnippetBlobPresenter
field :highlighted_data, GraphQL::STRING_TYPE,
field :rich_data, GraphQL::STRING_TYPE,
description: 'Blob highlighted data',
null: true
field :plain_highlighted_data, GraphQL::STRING_TYPE,
field :plain_data, GraphQL::STRING_TYPE,
description: 'Blob plain highlighted data',
null: true
......
# frozen_string_literal: true
class SnippetBlobPresenter < BlobPresenter
def highlighted_data
def rich_data
return if blob.binary?
highlight(plain: false)
if markup?
blob.rendered_markup
else
highlight(plain: false)
end
end
def plain_highlighted_data
def plain_data
return if blob.binary?
highlight(plain: true)
highlight(plain: !markup?)
end
def raw_path
......@@ -23,6 +27,10 @@ class SnippetBlobPresenter < BlobPresenter
private
def markup?
blob.rich_viewer&.partial_name == 'markup'
end
def snippet
blob.snippet
end
......
---
title: Fix bug rendering BlobType markdown data
merge_request: 24960
author:
type: fixed
......@@ -6757,11 +6757,6 @@ type SnippetBlob {
"""
binary: Boolean!
"""
Blob highlighted data
"""
highlightedData: String
"""
Blob mode
"""
......@@ -6780,13 +6775,18 @@ type SnippetBlob {
"""
Blob plain highlighted data
"""
plainHighlightedData: String
plainData: String
"""
Blob raw content endpoint path
"""
rawPath: String!
"""
Blob highlighted data
"""
richData: String
"""
Blob content rich viewer
"""
......
......@@ -7556,20 +7556,6 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "highlightedData",
"description": "Blob highlighted data",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "mode",
"description": "Blob mode",
......@@ -7613,7 +7599,7 @@
"deprecationReason": null
},
{
"name": "plainHighlightedData",
"name": "plainData",
"description": "Blob plain highlighted data",
"args": [
......@@ -7644,6 +7630,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "richData",
"description": "Blob highlighted data",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "richViewer",
"description": "Blob content rich viewer",
......
......@@ -1067,12 +1067,12 @@ Represents the snippet blob
| Name | Type | Description |
| --- | ---- | ---------- |
| `binary` | Boolean! | Shows whether the blob is binary |
| `highlightedData` | String | Blob highlighted data |
| `mode` | String | Blob mode |
| `name` | String | Blob name |
| `path` | String | Blob path |
| `plainHighlightedData` | String | Blob plain highlighted data |
| `plainData` | String | Blob plain highlighted data |
| `rawPath` | String! | Blob raw content endpoint path |
| `richData` | String | Blob highlighted data |
| `richViewer` | SnippetBlobViewer | Blob content rich viewer |
| `simpleViewer` | SnippetBlobViewer! | Blob content simple viewer |
| `size` | Int! | Blob size |
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
describe GitlabSchema.types['SnippetBlob'] do
it 'has the correct fields' do
expected_fields = [:highlighted_data, :plain_highlighted_data,
expected_fields = [:rich_data, :plain_data,
:raw_path, :size, :binary, :name, :path,
:simple_viewer, :rich_viewer, :mode]
......
......@@ -3,10 +3,10 @@
require 'spec_helper'
describe SnippetBlobPresenter do
describe '#highlighted_data' do
describe '#rich_data' do
let(:snippet) { build(:personal_snippet) }
subject { described_class.new(snippet.blob).highlighted_data }
subject { described_class.new(snippet.blob).rich_data }
it 'returns nil when the snippet blob is binary' do
allow(snippet.blob).to receive(:binary?).and_return(true)
......@@ -18,7 +18,7 @@ describe SnippetBlobPresenter do
snippet.file_name = 'test.md'
snippet.content = '*foo*'
expect(subject).to eq '<span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span>'
expect(subject).to eq '<p data-sourcepos="1:1-1:5" dir="auto"><em>foo</em></p>'
end
it 'returns syntax highlighted content' do
......@@ -37,10 +37,10 @@ describe SnippetBlobPresenter do
end
end
describe '#plain_highlighted_data' do
describe '#plain_data' do
let(:snippet) { build(:personal_snippet) }
subject { described_class.new(snippet.blob).plain_highlighted_data }
subject { described_class.new(snippet.blob).plain_data }
it 'returns nil when the snippet blob is binary' do
allow(snippet.blob).to receive(:binary?).and_return(true)
......@@ -52,7 +52,7 @@ describe SnippetBlobPresenter do
snippet.file_name = 'test.md'
snippet.content = '*foo*'
expect(subject).to eq '<span id="LC1" class="line" lang="">*foo*</span>'
expect(subject).to eq '<span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span>'
end
it 'returns plain syntax content' do
......
......@@ -67,7 +67,8 @@ describe 'Creating a Snippet' do
it 'returns the created Snippet' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(content)
expect(mutation_response['snippet']['blob']['richData']).to match(content)
expect(mutation_response['snippet']['blob']['plainData']).to match(content)
expect(mutation_response['snippet']['title']).to eq(title)
expect(mutation_response['snippet']['description']).to eq(description)
expect(mutation_response['snippet']['fileName']).to eq(file_name)
......@@ -92,7 +93,8 @@ describe 'Creating a Snippet' do
it 'returns the created Snippet' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(content)
expect(mutation_response['snippet']['blob']['richData']).to match(content)
expect(mutation_response['snippet']['blob']['plainData']).to match(content)
expect(mutation_response['snippet']['title']).to eq(title)
expect(mutation_response['snippet']['description']).to eq(description)
expect(mutation_response['snippet']['fileName']).to eq(file_name)
......
......@@ -56,7 +56,8 @@ describe 'Updating a Snippet' do
it 'returns the updated Snippet' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(updated_content)
expect(mutation_response['snippet']['blob']['richData']).to match(updated_content)
expect(mutation_response['snippet']['blob']['plainData']).to match(updated_content)
expect(mutation_response['snippet']['title']).to eq(updated_title)
expect(mutation_response['snippet']['description']).to eq(updated_description)
expect(mutation_response['snippet']['fileName']).to eq(updated_file_name)
......@@ -77,7 +78,8 @@ describe 'Updating a Snippet' do
it 'returns the Snippet with its original values' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(original_content)
expect(mutation_response['snippet']['blob']['richData']).to match(original_content)
expect(mutation_response['snippet']['blob']['plainData']).to match(original_content)
expect(mutation_response['snippet']['title']).to eq(original_title)
expect(mutation_response['snippet']['description']).to eq(original_description)
expect(mutation_response['snippet']['fileName']).to eq(original_file_name)
......
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