From 58abdbb5428d71f6ebb94869b957a22661e1230e Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Wed, 3 Oct 2018 10:31:32 -0400 Subject: Fetch templates from filesystem or API Fetch template content from the source files used by the app rather than hardcoding strings that will need to be updated if the templates change. Licenses are different - they're not stored as flat files so we retrieve them via the API. --- qa/qa.rb | 2 ++ qa/qa/runtime/fixtures.rb | 23 +++++++++++++++++++++ qa/qa/runtime/path.rb | 13 ++++++++++++ .../3_create/repository/add_file_template_spec.rb | 24 ++++++++++++++-------- .../3_create/web_ide/add_file_template_spec.rb | 24 ++++++++++++++-------- 5 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 qa/qa/runtime/fixtures.rb create mode 100644 qa/qa/runtime/path.rb (limited to 'qa') diff --git a/qa/qa.rb b/qa/qa.rb index 9392e26c840..4421f55ba62 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -16,6 +16,8 @@ module QA autoload :Browser, 'qa/runtime/browser' autoload :Env, 'qa/runtime/env' autoload :Address, 'qa/runtime/address' + autoload :Path, 'qa/runtime/path' + autoload :Fixtures, 'qa/runtime/fixtures' module API autoload :Client, 'qa/runtime/api/client' diff --git a/qa/qa/runtime/fixtures.rb b/qa/qa/runtime/fixtures.rb new file mode 100644 index 00000000000..427b1264202 --- /dev/null +++ b/qa/qa/runtime/fixtures.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module QA + module Runtime + module Fixtures + def fetch_from_file(path) + File.read(File.join(Runtime::Path.qa_root, '../', path)) + end + + def fetch_license_from_api(key) + request = Runtime::API::Request.new(api_client, "/templates/licenses/#{key}") + get request.url + json_body[:content] + end + + private + + def api_client + @api_client ||= Runtime::API::Client.new(:gitlab) + end + end + end +end diff --git a/qa/qa/runtime/path.rb b/qa/qa/runtime/path.rb new file mode 100644 index 00000000000..3169c5dd743 --- /dev/null +++ b/qa/qa/runtime/path.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module QA + module Runtime + module Path + extend self + + def qa_root + ::File.expand_path('../../', __dir__) + end + end + end +end diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb index 7832a1f8e23..16ab7d4f856 100644 --- a/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb +++ b/qa/qa/specs/features/browser_ui/3_create/repository/add_file_template_spec.rb @@ -3,6 +3,8 @@ module QA context :create do describe 'File templates' do + include Runtime::Fixtures + def login Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } @@ -20,14 +22,20 @@ module QA end templates = [ - ['.gitignore', 'Go', ['# Output of the go coverage tool']], - ['.gitlab-ci.yml', 'Ruby', ['# This file is a template', 'image: "ruby']], - ['Dockerfile', 'Python', ['FROM python:3.6']], - ['LICENSE', 'Mozilla Public License 2.0', ['Mozilla Public License Version 2.0']] + ['.gitignore', 'Go', 'vendor/gitignore/Go.gitignore'], + ['.gitlab-ci.yml', 'Ruby', 'lib/gitlab/ci/templates/Ruby.gitlab-ci.yml'], + ['Dockerfile', 'Python', 'vendor/Dockerfile/Python.Dockerfile'], + ['LICENSE', 'Mozilla Public License 2.0', 'mpl-2.0'] ] - templates.each do |(file_name, template, contents)| - it "user adds #{file_name} via a file template" do + templates.each do |(file_name, template, content_key)| + it "user adds #{file_name} via file template #{template}" do + content = if file_name == 'LICENSE' + fetch_license_from_api(content_key) + else + fetch_from_file(content_key) + end + login @project.visit! @@ -39,7 +47,7 @@ module QA expect(page).to have_content('Template applied') expect(page).to have_button('Undo') - contents.each { |content| expect(page).to have_content(content) } + expect(page).to have_content(content[0..100]) Page::File::Form.perform do |page| page.commit_changes @@ -48,7 +56,7 @@ module QA expect(page).to have_content('The file has been successfully created.') expect(page).to have_content(file_name) expect(page).to have_content('Add new file') - contents.each { |content| expect(page).to have_content(content) } + expect(page).to have_content(content[0..100]) end end end diff --git a/qa/qa/specs/features/browser_ui/3_create/web_ide/add_file_template_spec.rb b/qa/qa/specs/features/browser_ui/3_create/web_ide/add_file_template_spec.rb index 30f665230c4..da96bf4afc8 100644 --- a/qa/qa/specs/features/browser_ui/3_create/web_ide/add_file_template_spec.rb +++ b/qa/qa/specs/features/browser_ui/3_create/web_ide/add_file_template_spec.rb @@ -3,6 +3,8 @@ module QA context :create do describe 'Web IDE file templates' do + include Runtime::Fixtures + def login Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } @@ -29,14 +31,20 @@ module QA end templates = [ - ['.gitignore', 'Android', ['# Android Studio captures folder']], - ['.gitlab-ci.yml', 'Julia', ['# This file is a template', 'http://julialang.org/']], - ['Dockerfile', 'Python', ['FROM python:3.6']], - ['LICENSE', 'Mozilla Public License 2.0', ['Mozilla Public License Version 2.0']] + ['.gitignore', 'Android', 'vendor/gitignore/Android.gitignore'], + ['.gitlab-ci.yml', 'Julia', 'lib/gitlab/ci/templates/Julia.gitlab-ci.yml'], + ['Dockerfile', 'Python', 'vendor/Dockerfile/Python.Dockerfile'], + ['LICENSE', 'Mozilla Public License 2.0', 'mpl-2.0'] ] - templates.each do |(file_name, template, contents)| - it "user adds #{file_name} via a file template" do + templates.each do |(file_name, template, content_key)| + it "user adds #{file_name} via file template #{template}" do + content = if file_name == 'LICENSE' + fetch_license_from_api(content_key) + else + fetch_from_file(content_key) + end + login @project.visit! @@ -48,14 +56,14 @@ module QA end expect(page).to have_button('Undo') - contents.each { |content| expect(page).to have_content(content) } + expect(page).to have_content(content[0..100]) Page::Project::WebIDE::Edit.perform do |page| page.commit_changes end expect(page).to have_content(file_name) - contents.each { |content| expect(page).to have_content(content) } + expect(page).to have_content(content[0..100]) end end end -- cgit v1.2.1