This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
/
registries_spec.rb
157 lines (110 loc) · 4.71 KB
/
registries_spec.rb
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# frozen_string_literal: true
require "rails_helper"
describe "Admin - Registries panel" do
let!(:admin) { create(:admin) }
before do
login_as admin
end
describe "#force_registry_config!" do
it "redirects to new_admin_registry_path if no registry has been configured" do
visit authenticated_root_path
expect(page).to have_current_path(new_admin_registry_path)
end
end
describe "#create", js: true do
it "shows an error if name is blank" do
visit new_admin_registry_path
fill_in "registry_name", with: "registry"
clear_field("#registry_name")
expect(page).to have_content("Name can't be blank")
expect(page).to have_button("Create", disabled: true)
end
it "shows an error if hostname is blank" do
visit new_admin_registry_path
fill_in "registry_hostname", with: "registry"
clear_field("#registry_hostname")
expect(page).to have_content("Hostname can't be blank")
expect(page).to have_button("Create", disabled: true)
end
it "shows an error if hostname is not reachable" do
allow_any_instance_of(Registry).to receive(:reachable?).and_return("connection refused")
visit new_admin_registry_path
expect(page).not_to have_content("Skip remote checks")
fill_in "registry_name", with: "registry"
fill_in "registry_hostname", with: "url_not_known:1234"
expect(page).to have_content("Skip remote checks")
expect(page).to have_content("connection refused")
expect(page).to have_button("Create", disabled: true)
end
it "shows an error (hostname), but you can force it afterwards" do
allow_any_instance_of(Registry).to receive(:reachable?).and_return("Error")
visit new_admin_registry_path
fill_in "registry_name", with: "registry"
# for each field we do an ajax request to validate
# the sleep below is to delay the hostname change
# and guarantee the ajax responses order
# and avoid flaky and unrealistic state
sleep 1
fill_in "registry_hostname", with: "url_not_known:1234"
expect(page).to have_content("Skip remote checks")
expect(page).to have_css("#force")
# Use the force, Luke.
check "force"
expect(page).to have_button("Create")
click_button "Create"
expect(page).to have_current_path(admin_registries_path)
expect(page).to have_content("Registry was successfully created.")
expect(Registry).to be_any
end
it "shows advanced options when clicking on Show Advanced", js: true do
visit new_admin_registry_path
expect(page).not_to have_css("#advanced.collapse.in")
click_button "Show Advanced"
expect(page).to have_content("External Registry Name")
expect(page).to have_css("#advanced.collapse.in")
end
it "hides advanced options when clicking on Hide Advanced", js: true do
visit new_admin_registry_path
click_button "Show Advanced"
expect(page).to have_content("External Registry Name")
expect(page).to have_css("#advanced.collapse.in")
click_button "Hide Advanced"
expect(page).not_to have_css("#advanced.collapse.in")
expect(page).not_to have_content("External Registry Name")
end
end
describe "update", js: true do
let!(:registry) { create(:registry) }
before do
visit edit_admin_registry_path(registry.id)
end
it "does not show the hostname if there are repositories" do
expect(page).to have_css("#registry_hostname")
create(:repository)
visit edit_admin_registry_path(registry.id)
expect(page).not_to have_css("#registry_hostname")
end
it "shows an error if hostname is not reachable" do
allow_any_instance_of(Registry).to receive(:reachable?).and_return("connection refused")
fill_in "registry_name", with: "registry"
fill_in "registry_hostname", with: "url_not_known:1234"
expect(page).to have_content("Skip remote checks")
expect(page).to have_content("connection refused")
expect(page).to have_button("Update", disabled: true)
end
it "shows advanced options when clicking on Show Advanced" do
expect(page).not_to have_css("#advanced")
click_button "Show Advanced"
expect(page).to have_content("External Registry Name")
expect(page).to have_css("#advanced.collapse.in")
end
it "hides advanced options when clicking on Hide Advanced" do
click_button "Show Advanced"
expect(page).to have_content("External Registry Name")
expect(page).to have_css("#advanced.collapse.in")
click_button "Hide Advanced"
expect(page).not_to have_css("#advanced.collapse.in")
expect(page).not_to have_content("External Registry Name")
end
end
end