diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-12-15 14:59:35 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2018-01-26 12:03:25 -0200 |
commit | 3a1e06d6a2494af5449abfee9fb49d56a0f3fe00 (patch) | |
tree | c80c0441eba26485bff647729c8bc1ca4e349e25 /qa | |
parent | af95ba2fb481be62722438e5d93b074b1d3f89cb (diff) | |
download | gitlab-ce-3a1e06d6a2494af5449abfee9fb49d56a0f3fe00.tar.gz |
Create merge request specqa_78_create_merge_request
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa.rb | 5 | ||||
-rw-r--r-- | qa/qa/factory/dependency.rb | 7 | ||||
-rw-r--r-- | qa/qa/factory/resource/merge_request.rb | 49 | ||||
-rw-r--r-- | qa/qa/page/base.rb | 8 | ||||
-rw-r--r-- | qa/qa/page/merge_request/new.rb | 31 | ||||
-rw-r--r-- | qa/qa/page/project/show.rb | 8 | ||||
-rw-r--r-- | qa/qa/specs/features/merge_request/create_spec.rb | 17 | ||||
-rw-r--r-- | qa/spec/factory/dependency_spec.rb | 13 |
8 files changed, 133 insertions, 5 deletions
@@ -28,6 +28,7 @@ module QA autoload :Sandbox, 'qa/factory/resource/sandbox' autoload :Group, 'qa/factory/resource/group' autoload :Project, 'qa/factory/resource/project' + autoload :MergeRequest, 'qa/factory/resource/merge_request' autoload :DeployKey, 'qa/factory/resource/deploy_key' autoload :Runner, 'qa/factory/resource/runner' autoload :PersonalAccessToken, 'qa/factory/resource/personal_access_token' @@ -125,6 +126,10 @@ module QA autoload :PersonalAccessTokens, 'qa/page/profile/personal_access_tokens' end + module MergeRequest + autoload :New, 'qa/page/merge_request/new' + end + module Admin autoload :Settings, 'qa/page/admin/settings' end diff --git a/qa/qa/factory/dependency.rb b/qa/qa/factory/dependency.rb index d0e85a68237..fc5dc82ce29 100644 --- a/qa/qa/factory/dependency.rb +++ b/qa/qa/factory/dependency.rb @@ -16,20 +16,21 @@ module QA def build! return if overridden? - Builder.new(@signature).fabricate!.tap do |product| + Builder.new(@signature, @factory).fabricate!.tap do |product| @factory.public_send("#{@name}=", product) end end class Builder - def initialize(signature) + def initialize(signature, caller_factory) @factory = signature.factory @block = signature.block + @caller_factory = caller_factory end def fabricate! @factory.fabricate! do |factory| - @block&.call(factory) + @block&.call(factory, @caller_factory) end end end diff --git a/qa/qa/factory/resource/merge_request.rb b/qa/qa/factory/resource/merge_request.rb new file mode 100644 index 00000000000..ce04e904aaf --- /dev/null +++ b/qa/qa/factory/resource/merge_request.rb @@ -0,0 +1,49 @@ +require 'securerandom' + +module QA + module Factory + module Resource + class MergeRequest < Factory::Base + attr_accessor :title, + :description, + :source_branch, + :target_branch + + dependency Factory::Resource::Project, as: :project do |project| + project.name = 'project-with-merge-request' + end + + dependency Factory::Repository::Push, as: :target do |push, factory| + push.project = factory.project + push.branch_name = "master:#{factory.target_branch}" + end + + dependency Factory::Repository::Push, as: :source do |push, factory| + push.project = factory.project + push.branch_name = "#{factory.target_branch}:#{factory.source_branch}" + push.file_name = "added_file.txt" + push.file_content = "File Added" + end + + def initialize + @title = 'QA test - merge request' + @description = 'This is a test merge request' + @source_branch = "qa-test-feature-#{SecureRandom.hex(8)}" + @target_branch = "master" + end + + def fabricate! + project.visit! + + Page::Project::Show.act { new_merge_request } + + Page::MergeRequest::New.perform do |page| + page.fill_title(@title) + page.fill_description(@description) + page.create_merge_request + end + end + end + end + end +end diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 81ba80cdbaf..73aa23262da 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -40,12 +40,16 @@ module QA page.within(selector) { yield } if block_given? end + def find_element(name) + find(element_selector_css(name)) + end + def click_element(name) find_element(name).click end - def find_element(name) - find(element_selector_css(name)) + def fill_element(name, content) + find_element(name).set(content) end def within_element(name) diff --git a/qa/qa/page/merge_request/new.rb b/qa/qa/page/merge_request/new.rb new file mode 100644 index 00000000000..ec94ff4ac98 --- /dev/null +++ b/qa/qa/page/merge_request/new.rb @@ -0,0 +1,31 @@ +module QA + module Page + module MergeRequest + class New < Page::Base + view 'app/views/shared/issuable/_form.html.haml' do + element :issuable_create_button + end + + view 'app/views/shared/issuable/form/_title.html.haml' do + element :issuable_form_title + end + + view 'app/views/shared/form_elements/_description.html.haml' do + element :issuable_form_description + end + + def create_merge_request + click_element :issuable_create_button + end + + def fill_title(title) + fill_element :issuable_form_title, title + end + + def fill_description(description) + fill_element :issuable_form_description, description + end + end + end + end +end diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 5e66e40a0b5..24eb29ceb4c 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -11,6 +11,10 @@ module QA element :project_repository_location, 'text_field_tag :project_clone' end + view 'app/views/projects/_last_push.html.haml' do + element :create_merge_request + end + view 'app/views/projects/_home_panel.html.haml' do element :project_name end @@ -31,6 +35,10 @@ module QA find('.qa-project-name').text end + def new_merge_request + click_element :create_merge_request + end + def wait_for_push sleep 5 refresh diff --git a/qa/qa/specs/features/merge_request/create_spec.rb b/qa/qa/specs/features/merge_request/create_spec.rb new file mode 100644 index 00000000000..fbf9a4d17e5 --- /dev/null +++ b/qa/qa/specs/features/merge_request/create_spec.rb @@ -0,0 +1,17 @@ +module QA + feature 'creates a merge request', :core do + scenario 'user creates a new merge request' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + + Factory::Resource::MergeRequest.fabricate! do |merge_request| + merge_request.title = 'This is a merge request' + merge_request.description = 'Great feature' + end + + expect(page).to have_content('This is a merge request') + expect(page).to have_content('Great feature') + expect(page).to have_content('Opened less than a minute ago') + end + end +end diff --git a/qa/spec/factory/dependency_spec.rb b/qa/spec/factory/dependency_spec.rb index 32405415126..8aaa6665a18 100644 --- a/qa/spec/factory/dependency_spec.rb +++ b/qa/spec/factory/dependency_spec.rb @@ -54,6 +54,19 @@ describe QA::Factory::Dependency do expect(factory).to have_received(:mydep=).with(dependency) end + + context 'when receives a caller factory as block argument' do + let(:dependency) { QA::Factory::Base } + + it 'calls given block with dependency factory and caller factory' do + allow_any_instance_of(QA::Factory::Base).to receive(:fabricate!).and_return(factory) + allow(QA::Factory::Product).to receive(:populate!).and_return(spy('any')) + + subject.build! + + expect(block).to have_received(:call).with(an_instance_of(QA::Factory::Base), factory) + end + end end end end |