Commit 0ca472c1 authored by Anastasia McDonald's avatar Anastasia McDonald Committed by Dan Davison

Add E2E for personal snippet with multiple files

See https://gitlab.com/gitlab-org/quality/testcases/-/issues/842
parent 2771d5e1
...@@ -149,6 +149,7 @@ export default { ...@@ -149,6 +149,7 @@ export default {
data-testid="add_button" data-testid="add_button"
class="gl-my-3" class="gl-my-3"
variant="dashed" variant="dashed"
data-qa-selector="add_file_button"
@click="addBlob" @click="addBlob"
>{{ addLabel }}</gl-button >{{ addLabel }}</gl-button
> >
......
...@@ -69,7 +69,7 @@ export default { ...@@ -69,7 +69,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="file-holder snippet"> <div class="file-holder snippet" data-qa-selector="file_holder_container">
<blob-header-edit <blob-header-edit
:id="inputId" :id="inputId"
:value="blob.path" :value="blob.path"
......
...@@ -21,6 +21,7 @@ module QA ...@@ -21,6 +21,7 @@ module QA
base.view 'app/assets/javascripts/snippets/components/snippet_blob_edit.vue' do base.view 'app/assets/javascripts/snippets/components/snippet_blob_edit.vue' do
element :file_name_field element :file_name_field
element :file_holder_container
end end
base.view 'app/views/shared/form_elements/_description.html.haml' do base.view 'app/views/shared/form_elements/_description.html.haml' do
...@@ -35,6 +36,10 @@ module QA ...@@ -35,6 +36,10 @@ module QA
element :submit_button element :submit_button
end end
base.view 'app/assets/javascripts/snippets/components/snippet_blob_actions_edit.vue' do
element :add_file_button
end
base.view 'app/views/shared/_zen.html.haml' do base.view 'app/views/shared/_zen.html.haml' do
# This 'element' is here only to ensure the changes in the view source aren't mistakenly changed # This 'element' is here only to ensure the changes in the view source aren't mistakenly changed
element :_, "qa_selector = local_assigns.fetch(:qa_selector, '')" # rubocop:disable QA/ElementWithPattern element :_, "qa_selector = local_assigns.fetch(:qa_selector, '')" # rubocop:disable QA/ElementWithPattern
...@@ -54,13 +59,29 @@ module QA ...@@ -54,13 +59,29 @@ module QA
choose visibility choose visibility
end end
def fill_file_name(name) def fill_file_name(name, file_number = nil)
fill_element :file_name_field, name if file_number
within_element_by_index(:file_holder_container, file_number - 1) do
fill_element(:file_name_field, name)
end
else
fill_element(:file_name_field, name)
end
end end
def fill_file_content(content) def fill_file_content(content, file_number = nil)
if file_number
within_element_by_index(:file_holder_container, file_number - 1) do
text_area.set(content)
end
else
text_area.set content text_area.set content
end end
end
def click_add_file
click_element(:add_file_button)
end
def click_create_snippet_button def click_create_snippet_button
wait_until(reload: false) { !find_element(:submit_button).disabled? } wait_until(reload: false) { !find_element(:submit_button).disabled? }
......
...@@ -98,17 +98,29 @@ module QA ...@@ -98,17 +98,29 @@ module QA
end end
end end
def has_file_name?(file_name) def has_file_name?(file_name, file_number = nil)
if file_number
within_element_by_index(:file_title_content, file_number - 1) do
has_text?(file_name)
end
else
within_element(:file_title_content) do within_element(:file_title_content) do
has_text?(file_name) has_text?(file_name)
end end
end end
end
def has_file_content?(file_content) def has_file_content?(file_content, file_number = nil)
if file_number
within_element_by_index(:file_content, file_number - 1) do
has_text?(file_content)
end
else
within_element(:file_content) do within_element(:file_content) do
has_text?(file_content) has_text?(file_content)
end end
end end
end
def has_embed_dropdown? def has_embed_dropdown?
has_element?(:snippet_embed_dropdown) has_element?(:snippet_embed_dropdown)
......
...@@ -11,6 +11,11 @@ module QA ...@@ -11,6 +11,11 @@ module QA
@visibility = 'Public' @visibility = 'Public'
@file_content = 'The snippet content' @file_content = 'The snippet content'
@file_name = 'New snippet file name' @file_name = 'New snippet file name'
@files = []
end
def add_files
yield @files
end end
def fabricate! def fabricate!
...@@ -22,6 +27,12 @@ module QA ...@@ -22,6 +27,12 @@ module QA
new_page.set_visibility(@visibility) new_page.set_visibility(@visibility)
new_page.fill_file_name(@file_name) new_page.fill_file_name(@file_name)
new_page.fill_file_content(@file_content) new_page.fill_file_content(@file_content)
@files.each.with_index(2) do |file, i|
new_page.click_add_file
new_page.fill_file_name(file[:name], i)
new_page.fill_file_content(file[:content], i)
end
new_page.click_create_snippet_button new_page.click_create_snippet_button
end end
end end
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create', :requires_admin do
describe 'Multiple file snippet' do
before do
Runtime::Feature.enable_and_verify('snippet_multiple_files')
end
after do
Runtime::Feature.disable_and_verify('snippet_multiple_files')
end
it 'creates a personal snippet with multiple files', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/842' do
Flow::Login.sign_in
Page::Main::Menu.perform do |menu|
menu.go_to_more_dropdown_option(:snippets_link)
end
Resource::Snippet.fabricate_via_browser_ui! do |snippet|
snippet.title = 'Personal snippet with multiple files'
snippet.description = 'Snippet description'
snippet.visibility = 'Public'
snippet.file_name = 'First file name'
snippet.file_content = 'First file content'
snippet.add_files do |files|
files.append(name: 'Second file name', content: 'Second file content')
files.append(name: 'Third file name', content: 'Third file content')
end
end
Page::Dashboard::Snippet::Show.perform do |snippet|
expect(snippet).to have_snippet_title('Personal snippet with multiple files')
expect(snippet).to have_snippet_description('Snippet description')
expect(snippet).to have_visibility_type(/public/i)
expect(snippet).to have_file_name('First file name', 1)
expect(snippet).to have_file_content('First file content', 1)
expect(snippet).to have_file_name('Second file name', 2)
expect(snippet).to have_file_content('Second file content', 2)
expect(snippet).to have_file_name('Third file name', 3)
expect(snippet).to have_file_content('Third file content', 3)
end
end
end
end
end
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
exports[`Snippet Blob Edit component with loaded blob matches snapshot 1`] = ` exports[`Snippet Blob Edit component with loaded blob matches snapshot 1`] = `
<div <div
class="file-holder snippet" class="file-holder snippet"
data-qa-selector="file_holder_container"
> >
<blob-header-edit-stub <blob-header-edit-stub
candelete="true" candelete="true"
......
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