Commit 293a4416 authored by Ramya Authappan's avatar Ramya Authappan

Merge branch 'qa-e2e-delete-file-from-snippet' into 'master'

Add E2E to test deleting a file from snippet

See merge request gitlab-org/gitlab!46299
parents 033e05b6 44bd41fe
......@@ -50,6 +50,7 @@ export default {
variant="danger"
category="secondary"
:disabled="!canDelete"
data-qa-selector="delete_file_button"
@click="$emit('delete')"
>{{ s__('Snippets|Delete file') }}</gl-button
>
......
......@@ -110,6 +110,18 @@ module QA
end
end
def has_no_file_name?(file_name, file_number = nil)
if file_number
within_element_by_index(:file_title_content, file_number - 1) do
has_no_text?(file_name)
end
else
within_element(:file_title_content) do
has_no_text?(file_name)
end
end
end
def has_file_content?(file_content, file_number = nil)
if file_number
within_element_by_index(:file_content, file_number - 1) do
......
......@@ -14,6 +14,10 @@ module QA
element :file_holder_container
end
view 'app/assets/javascripts/blob/components/blob_edit_header.vue' do
element :delete_file_button
end
def add_to_file_content(content)
text_area.set content
text_area.has_text?(content) # wait for changes to take effect
......@@ -47,6 +51,12 @@ module QA
end
end
def click_delete_file(file_number)
within_element_by_index(:file_holder_container, file_number - 1) do
click_element(:delete_file_button)
end
end
def save_changes
wait_until(reload: false) { !find_element(:submit_button).disabled? }
click_element(:submit_button, Page::Dashboard::Snippet::Show)
......
......@@ -56,14 +56,16 @@ module QA
title: title,
description: description,
visibility: visibility.downcase,
files: [
{
content: file_content,
file_path: file_name
}
]
files: all_file_contents
}
end
def all_file_contents
@files.insert(0, { name: @file_name, content: @file_content })
@files.each do |file|
file[:file_path] = file.delete(:name)
end
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 delete file from'
snippet.file_name = 'Original file name'
snippet.file_content = 'Original file content'
snippet.add_files do |files|
files.append(name: 'Second file name', content: 'Second file content')
end
end
end
let(:project_snippet) do
Resource::ProjectSnippet.fabricate_via_api! do |snippet|
snippet.title = 'Project snippet to delete file from'
snippet.file_name = 'Original file name'
snippet.file_content = 'Original file content'
snippet.add_files do |files|
files.append(name: 'Second file name', content: 'Second file content')
end
end
end
before do
Flow::Login.sign_in
end
shared_examples 'deleting file from snippet' do |snippet_type|
it "deletes second file from an existing #{snippet_type} to make it single-file" do
send(snippet_type).visit!
Page::Dashboard::Snippet::Show.perform(&:click_edit_button)
Page::Dashboard::Snippet::Edit.perform do |snippet|
snippet.click_delete_file(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')
expect(snippet).to have_file_content('Original file content')
expect(snippet).to have_no_file_name('Second file name')
expect(snippet).to have_no_file_content('Second file content')
end
end
end
end
it_behaves_like 'deleting file from snippet', :personal_snippet
it_behaves_like 'deleting file from snippet', :project_snippet
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