Commit ab1b5f8f authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-e2e-copy-snippet-file-contents' into 'master'

Add E2E to test copying snippet file contents

See merge request gitlab-org/gitlab!49542
parents 5ded4737 d258996a
...@@ -50,7 +50,7 @@ export default { ...@@ -50,7 +50,7 @@ export default {
}; };
</script> </script>
<template> <template>
<gl-button-group> <gl-button-group data-qa-selector="default_actions_container">
<gl-button <gl-button
v-if="!hasRenderError" v-if="!hasRenderError"
v-gl-tooltip.hover v-gl-tooltip.hover
...@@ -59,6 +59,7 @@ export default { ...@@ -59,6 +59,7 @@ export default {
:disabled="copyDisabled" :disabled="copyDisabled"
:data-clipboard-target="getBlobHashTarget" :data-clipboard-target="getBlobHashTarget"
data-testid="copyContentsButton" data-testid="copyContentsButton"
data-qa-selector="copy_contents_button"
icon="copy-to-clipboard" icon="copy-to-clipboard"
category="primary" category="primary"
variant="default" variant="default"
......
...@@ -78,6 +78,11 @@ module QA ...@@ -78,6 +78,11 @@ module QA
base.view 'app/assets/javascripts/snippets/components/embed_dropdown.vue' do base.view 'app/assets/javascripts/snippets/components/embed_dropdown.vue' do
element :copy_button element :copy_button
end end
base.view 'app/assets/javascripts/blob/components/blob_header_default_actions.vue' do
element :default_actions_container
element :copy_contents_button
end
end end
def has_snippet_title?(snippet_title) def has_snippet_title?(snippet_title)
...@@ -182,7 +187,10 @@ module QA ...@@ -182,7 +187,10 @@ module QA
def add_comment(comment) def add_comment(comment)
fill_element(:note_field, comment) fill_element(:note_field, comment)
click_element(:comment_button) click_element(:comment_button)
wait_until(reload: false) { has_element?(:note_author_content) }
unless has_element?(:note_author_content)
raise ElementNotFound, "Comment did not appear as expected"
end
end end
def has_comment_author?(author_username) def has_comment_author?(author_username)
...@@ -207,7 +215,10 @@ module QA ...@@ -207,7 +215,10 @@ module QA
click_element(:edit_comment_button) click_element(:edit_comment_button)
fill_element(:edit_note_field, comment) fill_element(:edit_note_field, comment)
click_element(:save_comment_button) click_element(:save_comment_button)
wait_until(reload: false) { has_element?(:note_author_content) }
unless has_element?(:note_author_content)
raise ElementNotFound, "Comment did not appear as expected"
end
end end
def delete_comment(comment) def delete_comment(comment)
...@@ -215,7 +226,32 @@ module QA ...@@ -215,7 +226,32 @@ module QA
accept_alert do accept_alert do
click_element(:delete_comment_button) click_element(:delete_comment_button)
end end
wait_until(reload: false) { has_no_text?(comment) }
unless has_no_element?(:note_content, text: comment)
raise ElementNotFound, "Comment was not removed as expected"
end
end
def click_copy_file_contents(file_number = nil)
if file_number
within_element_by_index(:default_actions_container, file_number - 1) do
click_element(:copy_contents_button)
end
else
within_element(:default_actions_container) do
click_element(:copy_contents_button)
end
end
end
def copy_file_contents_to_comment(file_number = nil)
click_copy_file_contents(file_number)
send_keys_to_element(:note_field, [:shift, :insert])
click_element(:comment_button)
unless has_element?(:note_author_content)
raise ElementNotFound, "Comment did not appear as expected"
end
end end
end end
end end
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'Multiple file snippet' do
let(:first_file_content) { 'First file content' }
let(:second_file_content) { 'Second file content' }
let(:third_file_content) { 'Third file content' }
let(:personal_snippet) do
Resource::Snippet.fabricate_via_api! do |snippet|
snippet.title = 'Personal snippet to copy file contents from'
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
end
let(:project_snippet) do
Resource::ProjectSnippet.fabricate_via_api! do |snippet|
snippet.title = 'Project snippet to copy file contents from'
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
end
let(:files) do
[
{
number: 1,
content: first_file_content
},
{
number: 2,
content: second_file_content
},
{
number: 3,
content: third_file_content
}
]
end
before do
Flow::Login.sign_in
end
shared_examples 'copying snippet file contents' do |snippet_type|
it "copies file contents of a multi-file #{snippet_type} to a comment and verifies them" do
send(snippet_type).visit!
files.each do |files|
Page::Dashboard::Snippet::Show.perform do |snippet|
snippet.copy_file_contents_to_comment(files[:number])
expect(snippet).to have_comment_content(files[:content])
snippet.delete_comment(files[:content])
end
end
end
end
it_behaves_like 'copying snippet file contents', :personal_snippet
it_behaves_like 'copying snippet file contents', :project_snippet
end
end
end
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
Resource::Snippet.fabricate! do |snippet| Resource::Snippet.fabricate! do |snippet|
snippet.title = 'Shared snippet' snippet.title = 'Shared snippet'
snippet.visibility = 'Public' snippet.visibility = 'Public'
snippet.file_content = 'code.py' snippet.file_name = 'code.py'
snippet.file_content = 'code to be shared' snippet.file_content = 'code to be shared'
end end
end end
......
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