Commit f1e3aa0a authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-e2e-add-file-to-snippet' into 'master'

E2E test to add files to an existing snippet

See merge request gitlab-org/gitlab!45735
parents 675750b9 c32fafac
......@@ -9,6 +9,11 @@ module QA
element :submit_button, required: true
end
view 'app/assets/javascripts/snippets/components/snippet_blob_edit.vue' do
element :file_name_field
element :file_holder_container
end
def add_to_file_content(content)
text_area.set content
text_area.has_text?(content) # wait for changes to take effect
......@@ -18,7 +23,32 @@ module QA
choose(visibility_type)
end
def click_add_file
click_element(:add_file_button)
end
def fill_file_name(name, file_number = nil)
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
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)
end
end
def save_changes
wait_until(reload: false) { !find_element(:submit_button).disabled? }
click_element(:submit_button, Page::Dashboard::Snippet::Show)
end
......
......@@ -31,6 +31,14 @@ module QA
new_snippet.click_create_snippet_button
end
end
def api_get_path
"/projects/#{project.id}/snippets/#{snippet_id}"
end
def api_post_path
"/projects/#{project.id}/snippets"
end
end
end
end
......@@ -3,7 +3,7 @@
module QA
module Resource
class Snippet < Base
attr_accessor :title, :description, :file_content, :visibility, :file_name
attr_accessor :title, :description, :file_content, :visibility, :file_name, :snippet_id
def initialize
@title = 'New snippet title'
......@@ -36,6 +36,34 @@ module QA
new_page.click_create_snippet_button
end
end
def fabricate_via_api!
resource_web_url(api_post)
rescue ResourceNotFoundError
super
end
def api_get_path
"/snippets/#{snippet_id}"
end
def api_post_path
'/snippets'
end
def api_post_body
{
title: title,
description: description,
visibility: visibility.downcase,
files: [
{
content: file_content,
file_path: file_name
}
]
}
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'Multiple file snippet' do
let(:personal_snippet) do
Resource::Snippet.fabricate_via_api! do |snippet|
snippet.title = 'Personal snippet to add file to'
snippet.file_name = 'Original file name'
snippet.file_content = 'Original file content'
end
end
let(:project_snippet) do
Resource::ProjectSnippet.fabricate_via_api! do |snippet|
snippet.title = 'Project snippet to add file to'
snippet.file_name = 'Original file name'
snippet.file_content = 'Original file content'
end
end
before do
Flow::Login.sign_in
end
shared_examples 'adding file to snippet' do |snippet_type|
it "adds second file to an existing #{snippet_type} to make it multi-file" do
send(snippet_type).visit!
Page::Dashboard::Snippet::Show.perform(&:click_edit_button)
Page::Dashboard::Snippet::Edit.perform do |snippet|
snippet.click_add_file
snippet.fill_file_name('Second file name', 2)
snippet.fill_file_content('Second file content', 2)
snippet.save_changes
end
Page::Dashboard::Snippet::Show.perform do |snippet|
aggregate_failures 'file names and contents' do
expect(snippet).to have_file_name('Original file name', 1)
expect(snippet).to have_file_content('Original file content', 1)
expect(snippet).to have_file_name('Second file name', 2)
expect(snippet).to have_file_content('Second file content', 2)
end
end
end
end
it_behaves_like 'adding file to snippet', :personal_snippet
it_behaves_like 'adding file to snippet', :project_snippet
end
end
end
......@@ -22,13 +22,13 @@ module QA
end
let(:repository_uri_http) do
snippet
snippet.visit!
Page::Dashboard::Snippet::Show.perform(&:get_repository_uri_http)
end
let(:repository_uri_ssh) do
ssh_key
snippet
snippet.visit!
Page::Dashboard::Snippet::Show.perform(&:get_repository_uri_ssh)
end
......
......@@ -22,13 +22,13 @@ module QA
end
let(:repository_uri_http) do
snippet
snippet.visit!
Page::Dashboard::Snippet::Show.perform(&:get_repository_uri_http)
end
let(:repository_uri_ssh) do
ssh_key
snippet
snippet.visit!
Page::Dashboard::Snippet::Show.perform(&:get_repository_uri_ssh)
end
......
......@@ -18,7 +18,7 @@ module QA
context 'when the snippet is public' do
it 'can be shared with not signed-in users', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1016' do
snippet
snippet.visit!
sharing_link = Page::Dashboard::Snippet::Show.perform do |snippet|
expect(snippet).to have_embed_dropdown
......@@ -40,7 +40,7 @@ module QA
context 'when the snippet is changed to private' do
it 'does not display Embed/Share dropdown', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1015' do
snippet
snippet.visit!
Page::Dashboard::Snippet::Show.perform do |snippet|
expect(snippet).to have_embed_dropdown
......
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