Commit 7bcbd59f authored by Erick Banks's avatar Erick Banks Committed by Mark Lapierre

Refactor file tests

Break up the previous file create, edit, delete tests into
individual tests.
parent 79f7a27c
...@@ -5,10 +5,10 @@ module QA ...@@ -5,10 +5,10 @@ module QA
class File < Base class File < Base
attr_accessor :author_email, attr_accessor :author_email,
:author_name, :author_name,
:branch,
:content, :content,
:commit_message, :commit_message,
:name :name
attr_writer :branch
attribute :project do attribute :project do
Project.fabricate! do |resource| Project.fabricate! do |resource|
...@@ -29,6 +29,10 @@ module QA ...@@ -29,6 +29,10 @@ module QA
@commit_message = 'QA Test - Commit message' @commit_message = 'QA Test - Commit message'
end end
def branch
@branch ||= "master"
end
def fabricate! def fabricate!
project.visit! project.visit!
...@@ -42,12 +46,6 @@ module QA ...@@ -42,12 +46,6 @@ module QA
end end
end end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# this particular resource does not expose a web_url property
end
def api_get_path def api_get_path
"/projects/#{CGI.escape(project.path_with_namespace)}/repository/files/#{CGI.escape(@name)}" "/projects/#{CGI.escape(project.path_with_namespace)}/repository/files/#{CGI.escape(@name)}"
end end
...@@ -58,13 +56,20 @@ module QA ...@@ -58,13 +56,20 @@ module QA
def api_post_body def api_post_body
{ {
branch: @branch || "master", branch: branch,
author_email: @author_email || Runtime::User.default_email, author_email: @author_email || Runtime::User.default_email,
author_name: @author_name || Runtime::User.username, author_name: @author_name || Runtime::User.username,
content: content, content: content,
commit_message: commit_message commit_message: commit_message
} }
end end
private
def transform_api_resource(api_resource)
api_resource[:web_url] = "#{Runtime::Scenario.gitlab_address}/#{project.full_path}/-/tree/#{branch}/#{api_resource[:file_path]}"
api_resource
end
end end
end end
end end
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
context 'File management' do
file_name = 'QA Test - File name'
file_content = 'QA Test - File content'
commit_message_for_create = 'QA Test - Create new file'
before do
Flow::Login.sign_in
end
it 'user creates a file via the Web', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1093' do
Resource::File.fabricate_via_browser_ui! do |file|
file.name = file_name
file.content = file_content
file.commit_message = commit_message_for_create
end
Page::File::Show.perform do |file|
aggregate_failures 'file details' do
expect(file).to have_file(file_name)
expect(file).to have_file_content(file_content)
expect(file).to have_commit_message(commit_message_for_create)
end
end
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
context 'File management' do
let(:file) { Resource::File.fabricate_via_api! }
commit_message_for_delete = 'QA Test - Delete file'
before do
Flow::Login.sign_in
file.visit!
end
it 'user deletes a file via the Web', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1095' do
Page::File::Show.perform do |file|
file.click_delete
file.add_commit_message(commit_message_for_delete)
file.click_delete_file
end
Page::Project::Show.perform do |project|
aggregate_failures 'file details' do
expect(project).to have_notice('The file has been successfully deleted.')
expect(project).to have_commit_message(commit_message_for_delete)
expect(project).not_to have_file(file.name)
end
end
end
end
end
end
...@@ -2,33 +2,18 @@ ...@@ -2,33 +2,18 @@
module QA module QA
RSpec.describe 'Create' do RSpec.describe 'Create' do
describe 'Files management' do context 'File management' do
it 'user creates, edits and deletes a file via the Web', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/451' do let(:file) { Resource::File.fabricate_via_api! }
Flow::Login.sign_in
# Create
file_name = 'QA Test - File name'
file_content = 'QA Test - File content'
commit_message_for_create = 'QA Test - Create new file'
Resource::File.fabricate_via_browser_ui! do |file| updated_file_content = 'QA Test - Updated file content'
file.name = file_name commit_message_for_update = 'QA Test - Update file'
file.content = file_content
file.commit_message = commit_message_for_create
end
Page::File::Show.perform do |file| before do
aggregate_failures 'file details' do Flow::Login.sign_in
expect(file).to have_file(file_name) file.visit!
expect(file).to have_file_content(file_content) end
expect(file).to have_commit_message(commit_message_for_create)
end
end
# Edit
updated_file_content = 'QA Test - Updated file content'
commit_message_for_update = 'QA Test - Update file'
it 'user edits a file via the Web', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1094' do
Page::File::Show.perform(&:click_edit) Page::File::Show.perform(&:click_edit)
Page::File::Form.perform do |file| Page::File::Form.perform do |file|
...@@ -45,23 +30,6 @@ module QA ...@@ -45,23 +30,6 @@ module QA
expect(file).to have_commit_message(commit_message_for_update) expect(file).to have_commit_message(commit_message_for_update)
end end
end end
# Delete
commit_message_for_delete = 'QA Test - Delete file'
Page::File::Show.perform do |file|
file.click_delete
file.add_commit_message(commit_message_for_delete)
file.click_delete_file
end
Page::Project::Show.perform do |project|
aggregate_failures 'file details' do
expect(project).to have_notice('The file has been successfully deleted.')
expect(project).to have_commit_message(commit_message_for_delete)
expect(project).not_to have_file(file_name)
end
end
end end
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