2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-03 13:54:40 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Projects > Files > Template Undo Button', :js do
|
2017-07-24 18:51:14 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2018-04-09 13:26:29 -04:00
|
|
|
let(:user) { project.owner }
|
2017-04-03 13:54:40 -04:00
|
|
|
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in user
|
2017-04-03 13:54:40 -04:00
|
|
|
end
|
2017-04-21 16:32:02 -04:00
|
|
|
|
|
|
|
context 'editing a matching file and applying a template' do
|
2017-04-03 13:54:40 -04:00
|
|
|
before do
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_edit_blob_path(project, File.join(project.default_branch, "LICENSE"))
|
2019-10-10 05:06:08 -04:00
|
|
|
select_file_template_type('LICENSE')
|
2017-04-03 13:54:40 -04:00
|
|
|
select_file_template('.js-license-selector', 'Apache License 2.0')
|
|
|
|
end
|
2017-04-21 16:32:02 -04:00
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'reverts template application' do
|
2019-10-10 05:06:08 -04:00
|
|
|
try_template_undo('http://www.apache.org/licenses/', 'Apply a template')
|
2017-04-03 13:54:40 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-21 16:32:02 -04:00
|
|
|
|
2017-08-15 13:44:37 -04:00
|
|
|
context 'creating a non-matching file' do
|
2017-04-03 13:54:40 -04:00
|
|
|
before do
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_new_blob_path(project, 'master')
|
2017-04-03 13:54:40 -04:00
|
|
|
select_file_template_type('LICENSE')
|
|
|
|
select_file_template('.js-license-selector', 'Apache License 2.0')
|
|
|
|
end
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'reverts template application' do
|
2019-10-10 05:06:08 -04:00
|
|
|
try_template_undo('http://www.apache.org/licenses/', 'Apply a template')
|
2017-04-03 13:54:40 -04:00
|
|
|
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-10-10 05:06:08 -04:00
|
|
|
expect(page).to have_content('template applied')
|
|
|
|
expect(page).to have_css('.toasted-container')
|
2017-04-03 13:54:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_content_reverted(template_content)
|
2019-10-10 05:06:08 -04:00
|
|
|
find('.toasted-container a', text: 'Undo').click
|
2017-04-03 13:54:40 -04:00
|
|
|
expect(page).not_to have_content(template_content)
|
2019-04-26 11:51:05 -04:00
|
|
|
expect(page).to have_css('.template-type-selector .dropdown-toggle-text')
|
2017-04-03 13:54:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def select_file_template(template_selector_selector, template_name)
|
|
|
|
find(template_selector_selector).click
|
|
|
|
find('.dropdown-content li', text: template_name).click
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-04-03 13:54:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def select_file_template_type(template_type)
|
|
|
|
find('.js-template-type-selector').click
|
|
|
|
find('.dropdown-content li', text: template_type).click
|
|
|
|
end
|