Commit ac1662e6 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'qa-ml-fix-add-file-template-tests' into 'master'

[QA] Fix add file template tests

Closes gitlab-org/quality/staging#46 and gitlab-org/quality/nightly#97

See merge request gitlab-org/gitlab-ce!28915
parents 765917dc 5cccf313
...@@ -78,7 +78,7 @@ export default { ...@@ -78,7 +78,7 @@ export default {
data-container="body" data-container="body"
data-placement="right" data-placement="right"
type="button" type="button"
class="ide-sidebar-link js-ide-commit-mode" class="ide-sidebar-link js-ide-commit-mode qa-commit-mode-tab"
@click.prevent="changedActivityView($event, $options.activityBarViews.commit)" @click.prevent="changedActivityView($event, $options.activityBarViews.commit)"
> >
<icon name="commit" /> <icon name="commit" />
......
...@@ -134,6 +134,7 @@ export default { ...@@ -134,6 +134,7 @@ export default {
<template> <template>
<gl-modal <gl-modal
id="ide-new-entry" id="ide-new-entry"
class="qa-new-file-modal"
:header-title-text="modalTitle" :header-title-text="modalTitle"
:footer-primary-button-text="buttonLabel" :footer-primary-button-text="buttonLabel"
footer-primary-button-variant="success" footer-primary-button-variant="success"
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
.form-group.row.initialize-with-readme-setting .form-group.row.initialize-with-readme-setting
%div{ :class => "col-sm-12" } %div{ :class => "col-sm-12" }
.form-check .form-check
= check_box_tag 'project[initialize_with_readme]', '1', false, class: 'form-check-input', data: { track_label: "#{track_label}", track_event: "activate_form_input", track_property: "init_with_readme" } = check_box_tag 'project[initialize_with_readme]', '1', false, class: 'form-check-input qa-initialize-with-readme-checkbox', data: { track_label: "#{track_label}", track_event: "activate_form_input", track_property: "init_with_readme" }
= label_tag 'project[initialize_with_readme]', class: 'form-check-label' do = label_tag 'project[initialize_with_readme]', class: 'form-check-label' do
.option-title .option-title
%strong Initialize repository with a README %strong Initialize repository with a README
......
...@@ -78,8 +78,12 @@ module QA ...@@ -78,8 +78,12 @@ module QA
page.evaluate_script('xhr.status') == 200 page.evaluate_script('xhr.status') == 200
end end
def find_element(name, text: nil, wait: Capybara.default_max_wait_time) def find_element(name, **kwargs)
find(element_selector_css(name), wait: wait, text: text) find(element_selector_css(name), kwargs)
end
def active_element?(name)
find_element(name, class: 'active')
end end
def all_elements(name) def all_elements(name)
...@@ -132,6 +136,15 @@ module QA ...@@ -132,6 +136,15 @@ module QA
has_no_css?('.fa-spinner', wait: Capybara.default_max_wait_time) has_no_css?('.fa-spinner', wait: Capybara.default_max_wait_time)
end end
def wait_for_animated_element(name)
# It would be ideal if we could detect when the animation is complete
# but in some cases there's nothing we can easily access via capybara
# so instead we wait for the element, and then we wait a little longer
raise ElementNotFound, %Q(Couldn't find element named "#{name}") unless has_element?(name)
sleep 1
end
def within_element(name, text: nil) def within_element(name, text: nil)
page.within(element_selector_css(name), text: text) do page.within(element_selector_css(name), text: text) do
yield yield
......
...@@ -38,6 +38,8 @@ module QA ...@@ -38,6 +38,8 @@ module QA
def commit_changes def commit_changes
click_on 'Commit changes' click_on 'Commit changes'
finished_loading?
end end
def select_template(template_type, template) def select_template(template_type, template)
......
...@@ -12,6 +12,7 @@ module QA ...@@ -12,6 +12,7 @@ module QA
end end
view 'app/views/projects/_new_project_fields.html.haml' do view 'app/views/projects/_new_project_fields.html.haml' do
element :initialize_with_readme_checkbox
element :project_namespace_select element :project_namespace_select
element :project_namespace_field, 'namespaces_options' # rubocop:disable QA/ElementWithPattern element :project_namespace_field, 'namespaces_options' # rubocop:disable QA/ElementWithPattern
element :project_name, 'text_field :name' # rubocop:disable QA/ElementWithPattern element :project_name, 'text_field :name' # rubocop:disable QA/ElementWithPattern
...@@ -64,6 +65,10 @@ module QA ...@@ -64,6 +65,10 @@ module QA
def click_github_link def click_github_link
click_link 'GitHub' click_link 'GitHub'
end end
def enable_initialize_with_readme
check_element :initialize_with_readme_checkbox
end
end end
end end
end end
......
...@@ -7,6 +7,10 @@ module QA ...@@ -7,6 +7,10 @@ module QA
class Edit < Page::Base class Edit < Page::Base
include Page::Component::DropdownFilter include Page::Component::DropdownFilter
view 'app/assets/javascripts/ide/components/activity_bar.vue' do
element :commit_mode_tab
end
view 'app/assets/javascripts/ide/components/ide_tree.vue' do view 'app/assets/javascripts/ide/components/ide_tree.vue' do
element :new_file element :new_file
end end
...@@ -17,6 +21,7 @@ module QA ...@@ -17,6 +21,7 @@ module QA
view 'app/assets/javascripts/ide/components/new_dropdown/modal.vue' do view 'app/assets/javascripts/ide/components/new_dropdown/modal.vue' do
element :full_file_path element :full_file_path
element :new_file_modal
element :template_list element :template_list
end end
...@@ -42,12 +47,19 @@ module QA ...@@ -42,12 +47,19 @@ module QA
def create_new_file_from_template(file_name, template) def create_new_file_from_template(file_name, template)
click_element :new_file click_element :new_file
# Wait for the modal animation to complete before clicking on the file name
wait_for_animated_element(:new_file_modal)
within_element(:template_list) do within_element(:template_list) do
click_on file_name click_on file_name
rescue Capybara::ElementNotFound rescue Capybara::ElementNotFound
raise ElementNotFound, %Q(Couldn't find file template named "#{file_name}". Please confirm that it is a valid option.) raise ElementNotFound, %Q(Couldn't find file template named "#{file_name}". Please confirm that it is a valid option.)
end end
# Wait for the modal to fade out too
has_no_element?(:new_file_modal)
wait(reload: false) do wait(reload: false) do
within_element(:file_templates_bar) do within_element(:file_templates_bar) do
click_element :file_template_dropdown click_element :file_template_dropdown
...@@ -63,10 +75,16 @@ module QA ...@@ -63,10 +75,16 @@ module QA
end end
def commit_changes def commit_changes
# Clicking :begin_commit_button the first time switches from the
# edit to the commit view
click_element :begin_commit_button
active_element? :commit_mode_tab
# We need to click :begin_commit_button again
click_element :begin_commit_button click_element :begin_commit_button
# After clicking :begin_commit_button there is an animation that # After clicking :begin_commit_button the 2nd time there is an
# hides :begin_commit_button and shows :commit_button # animation that hides :begin_commit_button and shows :commit_button
# #
# Wait for the animation to complete before clicking :commit_button # Wait for the animation to complete before clicking :commit_button
# otherwise the click will quietly do nothing. # otherwise the click will quietly do nothing.
...@@ -75,7 +93,10 @@ module QA ...@@ -75,7 +93,10 @@ module QA
has_element?(:commit_button) has_element?(:commit_button)
end end
# Retry the attempt to click :commit_button just in case part of the # At this point we're ready to commit and the button should be
# labelled "Stage & Commit"
#
# Click :commit_button and keep retrying just in case part of the
# animation is still in process even when the buttons have the # animation is still in process even when the buttons have the
# expected visibility. # expected visibility.
commit_success_msg_shown = retry_until do commit_success_msg_shown = retry_until do
......
...@@ -7,6 +7,8 @@ module QA ...@@ -7,6 +7,8 @@ module QA
class Project < Base class Project < Base
include Events::Project include Events::Project
attr_writer :initialize_with_readme
attribute :id attribute :id
attribute :name attribute :name
attribute :description attribute :description
...@@ -33,6 +35,7 @@ module QA ...@@ -33,6 +35,7 @@ module QA
def initialize def initialize
@description = 'My awesome project' @description = 'My awesome project'
@initialize_with_readme = false
end end
def name=(raw_name) def name=(raw_name)
...@@ -49,6 +52,7 @@ module QA ...@@ -49,6 +52,7 @@ module QA
page.choose_name(@name) page.choose_name(@name)
page.add_description(@description) page.add_description(@description)
page.set_visibility('Public') page.set_visibility('Public')
page.enable_initialize_with_readme if @initialize_with_readme
page.create_new_project page.create_new_project
end end
end end
...@@ -73,7 +77,8 @@ module QA ...@@ -73,7 +77,8 @@ module QA
path: name, path: name,
name: name, name: name,
description: description, description: description,
visibility: 'public' visibility: 'public',
initialize_with_readme: @initialize_with_readme
} }
end end
......
...@@ -17,14 +17,7 @@ module QA ...@@ -17,14 +17,7 @@ module QA
@project = Resource::Project.fabricate! do |project| @project = Resource::Project.fabricate! do |project|
project.name = 'file-template-project' project.name = 'file-template-project'
project.description = 'Add file templates via the Files view' project.description = 'Add file templates via the Files view'
end project.initialize_with_readme = true
# There's no 'New File' dropdown when the project is blank, so we first
# add a dummy file so that the dropdown will appear
Resource::File.fabricate! do |file|
file.project = @project
file.name = 'README.md'
file.content = '# Readme'
end end
Page::Main::Menu.perform(&:sign_out) Page::Main::Menu.perform(&:sign_out)
......
...@@ -17,16 +17,7 @@ module QA ...@@ -17,16 +17,7 @@ module QA
@project = Resource::Project.fabricate! do |project| @project = Resource::Project.fabricate! do |project|
project.name = 'file-template-project' project.name = 'file-template-project'
project.description = 'Add file templates via the Web IDE' project.description = 'Add file templates via the Web IDE'
end project.initialize_with_readme = true
@project.visit!
# Add a file via the regular Files view because the Web IDE isn't
# available unless there is a file present
Page::Project::Show.perform(&:create_first_new_file!)
Page::File::Form.perform do |page|
page.add_name('dummy')
page.add_content('Enable the Web IDE')
page.commit_changes
end end
Page::Main::Menu.perform(&:sign_out) Page::Main::Menu.perform(&:sign_out)
......
...@@ -33,11 +33,8 @@ module QA ...@@ -33,11 +33,8 @@ module QA
exists exists
end end
def find_element(name, text: nil, wait: Capybara.default_max_wait_time) def find_element(name, **kwargs)
msg = ["finding :#{name}"] log("finding :#{name} with args #{kwargs}")
msg << %Q(with text "#{text}") if text
msg << "(wait: #{wait})"
log(msg.compact.join(' '))
element = super element = super
...@@ -122,6 +119,12 @@ module QA ...@@ -122,6 +119,12 @@ module QA
loaded loaded
end end
def wait_for_animated_element(name)
log("waiting for animated element: #{name}")
super
end
def within_element(name) def within_element(name)
log("within element :#{name}") log("within element :#{name}")
......
...@@ -64,11 +64,21 @@ describe QA::Support::Page::Logging do ...@@ -64,11 +64,21 @@ describe QA::Support::Page::Logging do
it 'logs find_element with text' do it 'logs find_element with text' do
expect { subject.find_element(:element, text: 'foo') } expect { subject.find_element(:element, text: 'foo') }
.to output(/finding :element with text "foo"/).to_stdout_from_any_process .to output(/finding :element with args {:text=>"foo"}/).to_stdout_from_any_process
expect { subject.find_element(:element, text: 'foo') } expect { subject.find_element(:element, text: 'foo') }
.to output(/found :element/).to_stdout_from_any_process .to output(/found :element/).to_stdout_from_any_process
end end
it 'logs find_element with wait' do
expect { subject.find_element(:element, wait: 0) }
.to output(/finding :element with args {:wait=>0}/).to_stdout_from_any_process
end
it 'logs find_element with class' do
expect { subject.find_element(:element, class: 'active') }
.to output(/finding :element with args {:class=>\"active\"}/).to_stdout_from_any_process
end
it 'logs click_element' do it 'logs click_element' do
expect { subject.click_element(:element) } expect { subject.click_element(:element) }
.to output(/clicking :element/).to_stdout_from_any_process .to output(/clicking :element/).to_stdout_from_any_process
......
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