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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-19 03:09:15 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-19 03:09:15 +0300
commit60f63d15794e62c4bac9756445f618cd9acb8654 (patch)
tree30c2b2dc678995dd332b32672f9faa460fabdb79 /spec/support
parent93d7441cc98c1db55797a2181a3d9f4b3d26d82c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb36
-rw-r--r--spec/support/shared_examples/banzai/filters/inline_embeds_shared_examples.rb48
-rw-r--r--spec/support/shared_examples/banzai/filters/inline_metrics_redactor_shared_examples.rb28
-rw-r--r--spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb92
4 files changed, 204 insertions, 0 deletions
diff --git a/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb b/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb
new file mode 100644
index 00000000000..e744c3d0abb
--- /dev/null
+++ b/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+RSpec.shared_context 'group and project boards query context' do
+ let_it_be(:user) { create :user }
+ let(:current_user) { user }
+ let(:params) { '' }
+ let(:board_parent_type) { board_parent.class.to_s.downcase }
+ let(:start_cursor) { graphql_data[board_parent_type]['boards']['pageInfo']['startCursor'] }
+ let(:end_cursor) { graphql_data[board_parent_type]['boards']['pageInfo']['endCursor'] }
+
+ def query(board_params = params)
+ graphql_query_for(
+ board_parent_type,
+ { 'fullPath' => board_parent.full_path },
+ <<~BOARDS
+ boards(#{board_params}) {
+ pageInfo {
+ startCursor
+ endCursor
+ }
+ edges {
+ node {
+ #{all_graphql_fields_for('boards'.classify)}
+ }
+ }
+ }
+ BOARDS
+ )
+ end
+
+ def grab_names(data = boards_data)
+ data.map do |board|
+ board.dig('node', 'name')
+ end
+ end
+end
diff --git a/spec/support/shared_examples/banzai/filters/inline_embeds_shared_examples.rb b/spec/support/shared_examples/banzai/filters/inline_embeds_shared_examples.rb
new file mode 100644
index 00000000000..599161abbfe
--- /dev/null
+++ b/spec/support/shared_examples/banzai/filters/inline_embeds_shared_examples.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+# Expects 2 attributes to be defined:
+# trigger_url - Url expected to trigger the insertion of a placeholder.
+# dashboard_url - Url expected to be present in the placeholder.
+RSpec.shared_examples 'a metrics embed filter' do
+ let(:input) { %(<a href="#{url}">example</a>) }
+ let(:doc) { filter(input) }
+
+ context 'when the document has an external link' do
+ let(:url) { 'https://foo.com' }
+
+ it 'leaves regular non-metrics links unchanged' do
+ expect(doc.to_s).to eq(input)
+ end
+ end
+
+ context 'when the document contains an embeddable link' do
+ let(:url) { trigger_url }
+
+ it 'leaves the original link unchanged' do
+ expect(unescape(doc.at_css('a').to_s)).to eq(input)
+ end
+
+ it 'appends a metrics charts placeholder' do
+ node = doc.at_css('.js-render-metrics')
+ expect(node).to be_present
+
+ expect(node.attribute('data-dashboard-url').to_s).to eq(dashboard_url)
+ end
+
+ context 'in a paragraph' do
+ let(:paragraph) { %(This is an <a href="#{url}">example</a> of metrics.) }
+ let(:input) { %(<p>#{paragraph}</p>) }
+
+ it 'appends a metrics charts placeholder after the enclosing paragraph' do
+ expect(unescape(doc.at_css('p').to_s)).to include(paragraph)
+ expect(doc.at_css('.js-render-metrics')).to be_present
+ end
+ end
+ end
+
+ # Nokogiri escapes the URLs, but we don't care about that
+ # distinction for the purposes of these filters
+ def unescape(html)
+ CGI.unescapeHTML(html)
+ end
+end
diff --git a/spec/support/shared_examples/banzai/filters/inline_metrics_redactor_shared_examples.rb b/spec/support/shared_examples/banzai/filters/inline_metrics_redactor_shared_examples.rb
new file mode 100644
index 00000000000..d283b3a3b27
--- /dev/null
+++ b/spec/support/shared_examples/banzai/filters/inline_metrics_redactor_shared_examples.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'a supported metrics dashboard url' do
+ context 'no user is logged in' do
+ it 'redacts the placeholder' do
+ expect(doc.to_s).to be_empty
+ end
+ end
+
+ context 'the user does not have permission do see charts' do
+ let(:doc) { filter(input, current_user: build(:user)) }
+
+ it 'redacts the placeholder' do
+ expect(doc.to_s).to be_empty
+ end
+ end
+
+ context 'the user has requisite permissions' do
+ let(:user) { create(:user) }
+ let(:doc) { filter(input, current_user: user) }
+
+ it 'leaves the placeholder' do
+ project.add_maintainer(user)
+
+ expect(doc.to_s).to eq(input)
+ end
+ end
+end
diff --git a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb
new file mode 100644
index 00000000000..6044fefd2f7
--- /dev/null
+++ b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb
@@ -0,0 +1,92 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'group and project boards query' do
+ include GraphqlHelpers
+
+ it_behaves_like 'a working graphql query' do
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+ end
+
+ context 'when the user does not have access to the board parent' do
+ it 'returns nil' do
+ create(:board, resource_parent: board_parent, name: 'A')
+
+ post_graphql(query)
+
+ expect(graphql_data[board_parent_type]).to be_nil
+ end
+ end
+
+ context 'when no permission to read board' do
+ it 'does not return any boards' do
+ board_parent.add_guest(current_user)
+ board = create(:board, resource_parent: board_parent, name: 'A')
+
+ allow(Ability).to receive(:allowed?).and_call_original
+ allow(Ability).to receive(:allowed?).with(user, :read_board, board).and_return(false)
+
+ post_graphql(query, current_user: current_user)
+
+ expect(boards_data).to be_empty
+ end
+ end
+
+ context 'when user can read the board parent' do
+ before do
+ board_parent.add_reporter(current_user)
+ end
+
+ it 'does not create a default board' do
+ post_graphql(query, current_user: current_user)
+
+ expect(boards_data).to be_empty
+ end
+
+ describe 'sorting and pagination' do
+ context 'when using default sorting' do
+ let!(:board_B) { create(:board, resource_parent: board_parent, name: 'B') }
+ let!(:board_C) { create(:board, resource_parent: board_parent, name: 'C') }
+ let!(:board_a) { create(:board, resource_parent: board_parent, name: 'a') }
+ let!(:board_A) { create(:board, resource_parent: board_parent, name: 'A') }
+
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ it_behaves_like 'a working graphql query'
+
+ context 'when ascending' do
+ let(:boards) { [board_a, board_A, board_B, board_C] }
+ let(:expected_boards) do
+ if board_parent.multiple_issue_boards_available?
+ boards
+ else
+ [boards.first]
+ end
+ end
+
+ it 'sorts boards' do
+ expect(grab_names).to eq expected_boards.map(&:name)
+ end
+
+ context 'when paginating' do
+ let(:params) { 'first: 2' }
+
+ it 'sorts boards' do
+ expect(grab_names).to eq expected_boards.first(2).map(&:name)
+
+ cursored_query = query("after: \"#{end_cursor}\"")
+ post_graphql(cursored_query, current_user: current_user)
+
+ response_data = JSON.parse(response.body)['data'][board_parent_type]['boards']['edges']
+
+ expect(grab_names(response_data)).to eq expected_boards.drop(2).first(2).map(&:name)
+ end
+ end
+ end
+ end
+ end
+ end
+end