Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql/types/snippets/blob_viewer_type_spec.rb')
-rw-r--r--spec/graphql/types/snippets/blob_viewer_type_spec.rb81
1 files changed, 81 insertions, 0 deletions
diff --git a/spec/graphql/types/snippets/blob_viewer_type_spec.rb b/spec/graphql/types/snippets/blob_viewer_type_spec.rb
index a51d09813ab..841e22451db 100644
--- a/spec/graphql/types/snippets/blob_viewer_type_spec.rb
+++ b/spec/graphql/types/snippets/blob_viewer_type_spec.rb
@@ -3,10 +3,91 @@
require 'spec_helper'
describe GitlabSchema.types['SnippetBlobViewer'] do
+ let_it_be(:snippet) { create(:personal_snippet, :repository) }
+ let_it_be(:blob) { snippet.repository.blob_at('HEAD', 'files/images/6049019_460s.jpg') }
+
it 'has the correct fields' do
expected_fields = [:type, :load_async, :too_large, :collapsed,
:render_error, :file_type, :loading_partial_name]
expect(described_class).to have_graphql_fields(*expected_fields)
end
+
+ it { expect(described_class.fields['type'].type).to be_non_null }
+ it { expect(described_class.fields['loadAsync'].type).to be_non_null }
+ it { expect(described_class.fields['collapsed'].type).to be_non_null }
+ it { expect(described_class.fields['tooLarge'].type).to be_non_null }
+ it { expect(described_class.fields['renderError'].type).not_to be_non_null }
+ it { expect(described_class.fields['fileType'].type).to be_non_null }
+ it { expect(described_class.fields['loadingPartialName'].type).to be_non_null }
+
+ shared_examples 'nil field converted to false' do
+ subject { GitlabSchema.execute(query, context: { current_user: snippet.author }).as_json }
+
+ before do
+ allow_next_instance_of(SnippetPresenter) do |instance|
+ allow(instance).to receive(:blob).and_return(blob)
+ end
+ end
+
+ it 'returns false' do
+ snippet_blob = subject.dig('data', 'snippets', 'edges')[0].dig('node', 'blob')
+
+ expect(snippet_blob['path']).to eq blob.path
+ expect(blob_attribute).to be_nil
+ expect(snippet_blob['simpleViewer'][attribute]).to eq false
+ end
+ end
+
+ describe 'collapsed' do
+ it_behaves_like 'nil field converted to false' do
+ let(:query) do
+ %(
+ query {
+ snippets(ids:"#{snippet.to_global_id}"){
+ edges {
+ node {
+ blob {
+ path
+ simpleViewer {
+ collapsed
+ }
+ }
+ }
+ }
+ }
+ }
+ )
+ end
+
+ let(:attribute) { 'collapsed' }
+ let(:blob_attribute) { blob.simple_viewer.collapsed? }
+ end
+ end
+
+ describe 'tooLarge' do
+ it_behaves_like 'nil field converted to false' do
+ let(:query) do
+ %(
+ query {
+ snippets(ids:"#{snippet.to_global_id}"){
+ edges {
+ node {
+ blob {
+ path
+ simpleViewer {
+ tooLarge
+ }
+ }
+ }
+ }
+ }
+ }
+ )
+ end
+
+ let(:attribute) { 'tooLarge' }
+ let(:blob_attribute) { blob.simple_viewer.too_large? }
+ end
+ end
end