1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
require 'spec_helper'
feature 'Template type dropdown selector', js: true do
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
project.team << [user, :master]
login_as user
end
context 'editing a non-matching file' do
before do
create_and_edit_file('.random-file.js')
end
scenario 'not displayed' do
check_type_selector_display(false)
end
scenario 'selects every template type correctly' do
fill_in 'file_path', with: '.gitignore'
try_selecting_all_types
end
scenario 'updates toggle value when input matches' do
fill_in 'file_path', with: '.gitignore'
check_type_selector_toggle_text('.gitignore')
end
end
context 'editing a matching file' do
before do
visit namespace_project_edit_blob_path(project.namespace, project, File.join(project.default_branch, 'LICENSE'))
end
scenario 'displayed' do
check_type_selector_display(true)
end
scenario 'is displayed when input matches' do
check_type_selector_display(true)
end
scenario 'selects every template type correctly' do
try_selecting_all_types
end
context 'user previews changes' do
before do
click_link 'Preview changes'
end
scenario 'type selector is hidden and shown correctly' do
check_type_selector_display(false)
click_link 'Write'
check_type_selector_display(true)
end
end
end
context 'creating a matching file' do
before do
visit namespace_project_new_blob_path(project.namespace, project, 'master', file_name: '.gitignore')
end
scenario 'is displayed' do
check_type_selector_display(true)
end
scenario 'toggle is set to the correct value' do
check_type_selector_toggle_text('.gitignore')
end
scenario 'selects every template type correctly' do
try_selecting_all_types
end
end
context 'creating a file' do
before do
visit namespace_project_new_blob_path(project.namespace, project, project.default_branch)
end
scenario 'type selector is shown' do
check_type_selector_display(true)
end
scenario 'toggle is set to the proper value' do
check_type_selector_toggle_text('Choose type')
end
scenario 'selects every template type correctly' do
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
try_selecting_template_type('LICENSE', 'Apply a license template')
try_selecting_template_type('Dockerfile', 'Apply a Dockerfile template')
try_selecting_template_type('.gitlab-ci.yml', 'Apply a GitLab CI Yaml template')
try_selecting_template_type('.gitignore', 'Apply a .gitignore template')
end
def try_selecting_template_type(template_type, selector_label)
select_template_type(template_type)
check_template_selector_display(selector_label)
check_type_selector_toggle_text(template_type)
end
def select_template_type(template_type)
find('.js-template-type-selector').click
find('.dropdown-content li', text: template_type).click
end
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)
visit namespace_project_new_blob_path(project.namespace, project, 'master', file_name: file_name)
click_button "Commit changes"
visit namespace_project_edit_blob_path(project.namespace, project, File.join(project.default_branch, file_name))
end
|