2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'Projects > Files > Template Undo Button', :js do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:user) { project.owner }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in user
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'editing a matching file and applying a template' do
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_edit_blob_path(project, File.join(project.default_branch, "LICENSE"))
|
2019-12-21 20:55:43 +05:30
|
|
|
select_file_template_type('LICENSE')
|
2017-08-17 22:00:37 +05:30
|
|
|
select_file_template('.js-license-selector', 'Apache License 2.0')
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'reverts template application' do
|
2019-12-21 20:55:43 +05:30
|
|
|
try_template_undo('http://www.apache.org/licenses/', 'Apply a template')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'creating a non-matching file' do
|
2017-08-17 22:00:37 +05:30
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_new_blob_path(project, 'master')
|
2017-08-17 22:00:37 +05:30
|
|
|
select_file_template_type('LICENSE')
|
|
|
|
select_file_template('.js-license-selector', 'Apache License 2.0')
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'reverts template application' do
|
2019-12-21 20:55:43 +05:30
|
|
|
try_template_undo('http://www.apache.org/licenses/', 'Apply a template')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_template_undo(template_content, toggle_text)
|
|
|
|
check_undo_button_display
|
|
|
|
check_content_reverted(template_content)
|
|
|
|
check_toggle_text_set(toggle_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_toggle_text_set(neutral_toggle_text)
|
|
|
|
expect(page).to have_content(neutral_toggle_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_undo_button_display
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(page).to have_content('template applied')
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(page).to have_css('.b-toaster')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def check_content_reverted(template_content)
|
2021-09-30 23:02:18 +05:30
|
|
|
find('.b-toaster a', text: 'Undo').click
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).not_to have_content(template_content)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(page).to have_css('.template-type-selector .dropdown-toggle-text')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def select_file_template(template_selector_selector, template_name)
|
|
|
|
find(template_selector_selector).click
|
|
|
|
find('.dropdown-content li', text: template_name).click
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def select_file_template_type(template_type)
|
|
|
|
find('.js-template-type-selector').click
|
|
|
|
find('.dropdown-content li', text: template_type).click
|
|
|
|
end
|