2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-03 17:54:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Projects > Files > Template type dropdown selector', :js do
|
2017-07-24 22:51:14 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
2018-04-09 17:26:29 +00:00
|
|
|
let(:user) { project.owner }
|
2017-04-03 17:54:40 +00:00
|
|
|
|
|
|
|
before do
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in user
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'editing a non-matching file' do
|
|
|
|
before do
|
|
|
|
create_and_edit_file('.random-file.js')
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'not displayed' do
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_display(false)
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'selects every template type correctly' do
|
2017-04-03 17:54:40 +00:00
|
|
|
fill_in 'file_path', with: '.gitignore'
|
|
|
|
try_selecting_all_types
|
|
|
|
end
|
|
|
|
|
2019-10-10 09:06:08 +00:00
|
|
|
it 'updates template type toggle value when template is chosen' do
|
2017-04-03 17:54:40 +00:00
|
|
|
fill_in 'file_path', with: '.gitignore'
|
2019-10-10 09:06:08 +00:00
|
|
|
select_template('gitignore', 'Actionscript')
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_toggle_text('.gitignore')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'editing a matching file' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_edit_blob_path(project, File.join(project.default_branch, 'LICENSE'))
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'displayed' do
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_display(true)
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'selects every template type correctly' do
|
2017-04-03 17:54:40 +00:00
|
|
|
try_selecting_all_types
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user previews changes' do
|
|
|
|
before do
|
2017-04-06 13:55:11 +00:00
|
|
|
click_link 'Preview changes'
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'type selector is hidden and shown correctly' do
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_display(false)
|
|
|
|
click_link 'Write'
|
|
|
|
check_type_selector_display(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'creating a matching file' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_new_blob_path(project, 'master', file_name: '.gitignore')
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'is displayed' do
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_display(true)
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'toggle is set to the correct value' do
|
2019-10-10 09:06:08 +00:00
|
|
|
select_template('gitignore', 'Actionscript')
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_toggle_text('.gitignore')
|
|
|
|
end
|
|
|
|
|
2020-02-11 15:08:44 +00:00
|
|
|
it 'sets the toggle text when selecting the template type' do
|
|
|
|
select_template_type('.gitignore')
|
|
|
|
check_type_selector_toggle_text('.gitignore')
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'selects every template type correctly' do
|
2017-04-03 17:54:40 +00:00
|
|
|
try_selecting_all_types
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'creating a file' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_new_blob_path(project, project.default_branch)
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'type selector is shown' do
|
2017-04-03 17:54:40 +00:00
|
|
|
check_type_selector_display(true)
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'toggle is set to the proper value' do
|
2019-10-10 09:06:08 +00:00
|
|
|
check_type_selector_toggle_text('Select a template type')
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'selects every template type correctly' do
|
2017-04-03 17:54:40 +00:00
|
|
|
try_selecting_all_types
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_type_selector_display(is_visible)
|
|
|
|
count = is_visible ? 1 : 0
|
|
|
|
expect(page).to have_css('.js-template-type-selector', count: count)
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_selecting_all_types
|
2019-10-10 09:06:08 +00:00
|
|
|
try_selecting_template_type('LICENSE', 'Apply a template')
|
|
|
|
try_selecting_template_type('Dockerfile', 'Apply a template')
|
|
|
|
try_selecting_template_type('.gitlab-ci.yml', 'Apply a template')
|
|
|
|
try_selecting_template_type('.gitignore', 'Apply a template')
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def try_selecting_template_type(template_type, selector_label)
|
|
|
|
select_template_type(template_type)
|
|
|
|
check_template_selector_display(selector_label)
|
|
|
|
end
|
|
|
|
|
|
|
|
def select_template_type(template_type)
|
|
|
|
find('.js-template-type-selector').click
|
|
|
|
find('.dropdown-content li', text: template_type).click
|
|
|
|
end
|
|
|
|
|
2019-10-10 09:06:08 +00:00
|
|
|
def select_template(type, template)
|
|
|
|
find(".js-#{type}-selector-wrap").click
|
|
|
|
find('.dropdown-content li', text: template).click
|
|
|
|
end
|
|
|
|
|
2017-04-03 17:54:40 +00:00
|
|
|
def check_template_selector_display(content)
|
|
|
|
expect(page).to have_content(content)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_type_selector_toggle_text(template_type)
|
|
|
|
dropdown_toggle_button = find('.template-type-selector .dropdown-toggle-text')
|
|
|
|
expect(dropdown_toggle_button).to have_content(template_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_and_edit_file(file_name)
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_new_blob_path(project, 'master', file_name: file_name)
|
2017-04-04 18:06:32 +00:00
|
|
|
click_button "Commit changes"
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_edit_blob_path(project, File.join(project.default_branch, file_name))
|
2017-04-03 17:54:40 +00:00
|
|
|
end
|