summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeff Morgan <zeff.morgan@gmail.com>2018-12-04 01:03:58 -0500
committerZeff Morgan <zeff.morgan@gmail.com>2018-12-09 22:45:07 -0500
commitf4be8684190a8c5b3c7afe896a4d77af7cf9bf3b (patch)
tree832a2c12c19e23075c355d1ac14426ecab62b8a3
parenteeb0e98df8f038a6498f6388c515fa7d3c136ee4 (diff)
downloadgitlab-ce-zeff.morgan/52696-raw-diff-patch-requests.tar.gz
Add tests for plain diff/email patch optionszeff.morgan/52696-raw-diff-patch-requests
Add spec file using before(:context) to reduce test time. With testing almost identical things, unnecessary to make them completely atomic. Includes two helper methods. Since the raw_content method is the only function needed on that page, created the method in the spec instead of adding another page object. Setup new project/commit page object and update project/show to add go_to_commit method. The go_to_commit method is near duplicate of go_to_file method, but decided to split them off to reduce overall refactoring and simplify language. Also add selectors to commit box partial and update qa.rb to load new page object.
-rw-r--r--app/views/projects/commit/_commit_box.html.haml6
-rw-r--r--qa/qa.rb4
-rw-r--r--qa/qa/page/project/commit/show.rb27
-rw-r--r--qa/qa/page/project/show.rb6
-rw-r--r--qa/qa/specs/features/browser_ui/3_create/repository/user_views_raw_diff_patch_requests_spec.rb61
5 files changed, 101 insertions, 3 deletions
diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml
index aab5712d197..2a919a767c0 100644
--- a/app/views/projects/commit/_commit_box.html.haml
+++ b/app/views/projects/commit/_commit_box.html.haml
@@ -28,7 +28,7 @@
= link_to project_tree_path(@project, @commit), class: "btn btn-default append-right-10 d-none d-sm-none d-md-inline" do
#{ _('Browse files') }
.dropdown.inline
- %a.btn.btn-default.dropdown-toggle{ data: { toggle: "dropdown" } }
+ %a.btn.btn-default.dropdown-toggle.qa-options-button{ data: { toggle: "dropdown" } }
%span= _('Options')
= icon('caret-down')
%ul.dropdown-menu.dropdown-menu-right
@@ -48,8 +48,8 @@
%li.dropdown-header
#{ _('Download') }
- unless @commit.parents.length > 1
- %li= link_to s_("DownloadCommit|Email Patches"), project_commit_path(@project, @commit, format: :patch)
- %li= link_to s_("DownloadCommit|Plain Diff"), project_commit_path(@project, @commit, format: :diff)
+ %li= link_to s_("DownloadCommit|Email Patches"), project_commit_path(@project, @commit, format: :patch), class: "qa-email-patches"
+ %li= link_to s_("DownloadCommit|Plain Diff"), project_commit_path(@project, @commit, format: :diff), class: "qa-plain-diff"
.commit-box{ data: { project_path: project_path(@project) } }
%h3.commit-title
diff --git a/qa/qa.rb b/qa/qa.rb
index aa0b78b37e8..d9b8e66c174 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -158,6 +158,10 @@ module QA
autoload :Activity, 'qa/page/project/activity'
autoload :Menu, 'qa/page/project/menu'
+ module Commit
+ autoload :Show, 'qa/page/project/commit/show'
+ end
+
module Import
autoload :Github, 'qa/page/project/import/github'
end
diff --git a/qa/qa/page/project/commit/show.rb b/qa/qa/page/project/commit/show.rb
new file mode 100644
index 00000000000..9770b8a657c
--- /dev/null
+++ b/qa/qa/page/project/commit/show.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module QA
+ module Page
+ module Project
+ module Commit
+ class Show < Page::Base
+ view 'app/views/projects/commit/_commit_box.html.haml' do
+ element :options_button
+ element :email_patches
+ element :plain_diff
+ end
+
+ def select_email_patches
+ click_element :options_button
+ click_element :email_patches
+ end
+
+ def select_plain_diff
+ click_element :options_button
+ click_element :plain_diff
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb
index d6dddf03ffb..4ddf806009f 100644
--- a/qa/qa/page/project/show.rb
+++ b/qa/qa/page/project/show.rb
@@ -61,6 +61,12 @@ module QA
end
end
+ def go_to_commit(commit_msg)
+ within_element(:file_tree) do
+ click_on commit_msg
+ end
+ end
+
def switch_to_branch(branch_name)
find_element(:branches_select).click
diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/user_views_raw_diff_patch_requests_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/user_views_raw_diff_patch_requests_spec.rb
new file mode 100644
index 00000000000..75ad18a4111
--- /dev/null
+++ b/qa/qa/specs/features/browser_ui/3_create/repository/user_views_raw_diff_patch_requests_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+module QA
+ context 'Create' do
+ describe 'Commit data' do
+ before(:context) do
+ Runtime::Browser.visit(:gitlab, Page::Main::Login)
+ Page::Main::Login.perform(&:sign_in_using_credentials)
+
+ @project = Resource::Repository::ProjectPush.fabricate! do |push|
+ push.file_name = 'README.md'
+ push.file_content = '# This is a test project'
+ push.commit_message = 'Add README.md'
+ end
+
+ # first file added has no parent commit, thus no diff data
+ # add second file to repo to enable diff from initial commit
+ @commit_message = 'Add second file'
+
+ @project.visit!
+ Page::Project::Show.perform(&:create_new_file!)
+ Page::File::Form.perform do |f|
+ f.add_name('second')
+ f.add_content('second file content')
+ f.add_commit_message(@commit_message)
+ f.commit_changes
+ end
+ end
+
+ def view_commit
+ @project.visit!
+ Page::Project::Show.perform do |page|
+ page.go_to_commit(@commit_message)
+ end
+ end
+
+ def raw_content
+ find('pre').text
+ end
+
+ it 'user views raw email patch' do
+ view_commit
+
+ Page::Project::Commit::Show.perform(&:select_email_patches)
+
+ expect(page).to have_content('From: Administrator <admin@example.com>')
+ expect(page).to have_content('Subject: [PATCH] Add second file')
+ expect(page).to have_content('diff --git a/second b/second')
+ end
+
+ it 'user views raw commit diff' do
+ view_commit
+
+ Page::Project::Commit::Show.perform(&:select_plain_diff)
+
+ expect(raw_content).to start_with('diff --git a/second b/second')
+ expect(page).to have_content('+second file content')
+ end
+ end
+ end
+end