Commit 900de4d9 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch '345999-improve-pipeline-editor-test' into 'master'

Improving pipeline editor E2E test

See merge request gitlab-org/gitlab!75046
parents ed1837e7 cb8cc4ce
...@@ -98,6 +98,7 @@ export default { ...@@ -98,6 +98,7 @@ export default {
class="gl-w-full gl-h-9 gl-rounded-0! gl-border-none! gl-border-b-solid! gl-border-1! gl-border-gray-100 gl-text-decoration-none! gl-outline-0! gl-display-flex" class="gl-w-full gl-h-9 gl-rounded-0! gl-border-none! gl-border-b-solid! gl-border-1! gl-border-gray-100 gl-text-decoration-none! gl-outline-0! gl-display-flex"
:class="buttonClass" :class="buttonClass"
:title="__('Toggle sidebar')" :title="__('Toggle sidebar')"
data-qa-selector="toggle_sidebar_collapse_button"
@click="toggleDrawer" @click="toggleDrawer"
> >
<span v-if="isExpanded" class="gl-text-gray-500 gl-mr-3" data-testid="collapse-text"> <span v-if="isExpanded" class="gl-text-gray-500 gl-mr-3" data-testid="collapse-text">
...@@ -105,7 +106,12 @@ export default { ...@@ -105,7 +106,12 @@ export default {
</span> </span>
<gl-icon data-testid="toggle-icon" :name="buttonIconName" /> <gl-icon data-testid="toggle-icon" :name="buttonIconName" />
</gl-button> </gl-button>
<div v-if="isExpanded" class="gl-h-full gl-p-5" data-testid="drawer-content"> <div
v-if="isExpanded"
class="gl-h-full gl-p-5"
data-testid="drawer-content"
data-qa-selector="drawer_content"
>
<getting-started-card class="gl-mb-4" /> <getting-started-card class="gl-mb-4" />
<first-pipeline-card class="gl-mb-4" /> <first-pipeline-card class="gl-mb-4" />
<visualize-and-lint-card class="gl-mb-4" /> <visualize-and-lint-card class="gl-mb-4" />
......
...@@ -247,6 +247,7 @@ export default { ...@@ -247,6 +247,7 @@ export default {
<gl-infinite-scroll <gl-infinite-scroll
:fetched-items="branches.length" :fetched-items="branches.length"
:max-list-height="250" :max-list-height="250"
data-qa-selector="branch_menu_container"
@bottomReached="fetchNextBranches" @bottomReached="fetchNextBranches"
> >
<template #items> <template #items>
...@@ -255,7 +256,7 @@ export default { ...@@ -255,7 +256,7 @@ export default {
:key="branch" :key="branch"
:is-checked="currentBranch === branch" :is-checked="currentBranch === branch"
:is-check-item="true" :is-check-item="true"
data-qa-selector="menu_branch_button" data-qa-selector="branch_menu_item_button"
@click="selectBranch(branch)" @click="selectBranch(branch)"
> >
{{ branch }} {{ branch }}
......
...@@ -96,6 +96,7 @@ export default { ...@@ -96,6 +96,7 @@ export default {
:id="`source-editor-${fileGlobalId}`" :id="`source-editor-${fileGlobalId}`"
ref="editor" ref="editor"
data-editor-loading data-editor-loading
data-qa-selector="source_editor_container"
@[$options.readyEvent]="$emit($options.readyEvent)" @[$options.readyEvent]="$emit($options.readyEvent)"
> >
<pre class="editor-loading-content">{{ value }}</pre> <pre class="editor-loading-content">{{ value }}</pre>
......
...@@ -6,37 +6,59 @@ module QA ...@@ -6,37 +6,59 @@ module QA
module PipelineEditor module PipelineEditor
class Show < QA::Page::Base class Show < QA::Page::Base
view 'app/assets/javascripts/pipeline_editor/components/file_nav/branch_switcher.vue' do view 'app/assets/javascripts/pipeline_editor/components/file_nav/branch_switcher.vue' do
element :branch_selector_button element :branch_selector_button, require: true
element :menu_branch_button element :branch_menu_item_button
element :branch_menu_container
end end
view 'app/assets/javascripts/pipeline_editor/components/commit/commit_form.vue' do view 'app/assets/javascripts/pipeline_editor/components/commit/commit_form.vue' do
element :target_branch_field element :target_branch_field, require: true
end end
def has_branch_selector_button? view 'app/assets/javascripts/pipeline_editor/components/drawer/pipeline_editor_drawer.vue' do
has_element? :branch_selector_button element :toggle_sidebar_collapse_button
element :drawer_content
end end
def click_branch_selector_button view 'app/assets/javascripts/vue_shared/components/source_editor.vue' do
wait_until(reload: false) do element :source_editor_container, require: true
has_element?(:branch_selector_button)
end
click_element(:branch_selector_button, skip_finished_loading_check: true)
end end
def select_branch_from_dropdown(branch_to_switch_to) def initialize
wait_until(reload: false) do super
has_element?(:menu_branch_button)
end wait_for_requests
click_element(:menu_branch_button, text: branch_to_switch_to, skip_finished_loading_check: true) close_toggle_sidebar
end
def open_branch_selector_dropdown
click_element(:branch_selector_button)
end
def select_branch_from_dropdown(branch_name)
wait_for_animated_element(:branch_menu_container)
click_element(:branch_menu_item_button, text: branch_name)
wait_for_requests
end end
def target_branch_name def target_branch_name
wait_until(reload: false) do find_element(:target_branch_field).value
has_element?(:target_branch_field) end
end
find_element(:target_branch_field, skip_finished_loading_check: true).value def editing_content
find_element(:source_editor_container).text
end
private
# If the page thinks user has never opened pipeline editor before
# It will expand pipeline editor sidebar by default
# Collapse the sidebar if it is expanded
def close_toggle_sidebar
return unless has_element?(:drawer_content)
click_element(:toggle_sidebar_collapse_button)
end end
end end
end end
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
module QA module QA
RSpec.describe 'Verify' do RSpec.describe 'Verify' do
describe 'Pipeline editor', :requires_admin do describe 'Pipeline editor' do
let(:random_test_string) { SecureRandom.hex(10) }
let(:project) do let(:project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = 'pipeline-editor-project' project.name = 'pipeline-editor-project'
...@@ -17,70 +19,71 @@ module QA ...@@ -17,70 +19,71 @@ module QA
[ [
{ {
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: default_file_content content: <<~YAML
stages:
- test
initialize:
stage: test
script:
- echo "I am now on branch #{project.default_branch}"
YAML
} }
] ]
) )
end end
end end
let!(:production_push) do let!(:test_branch) do
Resource::Repository::Push.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |resource|
push.repository_http_uri = project.repository_http_location.uri resource.project = project
push.branch_name = 'production' resource.branch_name = random_test_string
push.file_name = '.gitlab-ci.yml' resource.file_name = '.gitlab-ci.yml'
push.file_content = production_file_content resource.file_content = <<~YAML
end stages:
end - test
let(:default_file_content) do
<<~YAML
stages:
- test
initialize:
stage: test
script:
- echo "initialized in #{project.default_branch}"
YAML
end
let(:production_file_content) do initialize:
<<~YAML stage: test
stages: script:
- test - echo "I am now on branch #{random_test_string}"
YAML
initialize: end
stage: test
script:
- echo "initialized in production"
YAML
end end
before do before do
Flow::Login.sign_in Flow::Login.sign_in
project.visit! project.visit!
Page::Project::Menu.perform(&:go_to_pipeline_editor)
# Project push sometimes takes a while to complete
# Making sure new branch is pushed successfully prior to interacting
Support::Retrier.retry_until(max_duration: 15, sleep_interval: 3, reload_page: false, message: 'Ensuring project has branch') do
project.has_branch?(random_test_string)
end
end end
after do after do
project.remove_via_api! project.remove_via_api!
Page::Main::Menu.perform(&:sign_out)
end end
it 'can switch branches and target branch field updates accordingly', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1891' do it 'can switch branches and target branch field updates accordingly', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/1891' do
Page::Project::Menu.perform(&:go_to_pipeline_editor)
Page::Project::PipelineEditor::Show.perform do |show| Page::Project::PipelineEditor::Show.perform do |show|
expect(show).to have_branch_selector_button show.open_branch_selector_dropdown
show.select_branch_from_dropdown(random_test_string)
show.click_branch_selector_button
show.select_branch_from_dropdown(production_push.branch_name)
expect(show.target_branch_name).to eq(production_push.branch_name) aggregate_failures do
expect(show.target_branch_name).to eq(random_test_string), 'Target branch field is not showing expected branch name.'
expect(show.editing_content).to have_content(random_test_string), 'Editor content does not include expected test string.'
end
show.click_branch_selector_button show.open_branch_selector_dropdown
show.select_branch_from_dropdown(project.default_branch) show.select_branch_from_dropdown(project.default_branch)
expect(show.target_branch_name).to eq(project.default_branch) aggregate_failures do
expect(show.target_branch_name).to eq(project.default_branch), 'Target branch field is not showing expected branch name.'
expect(show.editing_content).to have_content(project.default_branch), 'Editor content does not include expected test string.'
end
end end
end end
end end
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
exports[`Source Editor component rendering matches the snapshot 1`] = ` exports[`Source Editor component rendering matches the snapshot 1`] = `
<div <div
data-editor-loading="" data-editor-loading=""
data-qa-selector="source_editor_container"
id="source-editor-snippet_777" id="source-editor-snippet_777"
> >
<pre <pre
......
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