Revision 329cfcba
Added by Sebastian Gräßl about 5 years ago
test/integration/container_steps_test.rb | ||
---|---|---|
1 | 1 |
require 'integration_test_helper' |
2 | 2 |
|
3 |
class ContainerStepsTest < ActionDispatch::IntegrationTest |
|
4 |
test 'shows a link to a new compute resource if none is available' do |
|
5 |
visit new_container_path |
|
6 |
assert has_selector?("div.alert", :text => 'Please add a new one') |
|
3 |
class ContainerStepsTest < IntegrationTestWithJavascript |
|
4 |
let(:wizard_state) { DockerContainerWizardState.create! } |
|
5 |
let(:compute_resource) { FactoryGirl.create(:docker_cr) } |
|
6 |
let(:registry) { FactoryGirl.create(:docker_registry) } |
|
7 |
let(:image_search_service) { ForemanDocker::ImageSearch.new } |
|
8 |
let(:image_search_results) do |
|
9 |
[{ 'name' => 'my_fake_repository_result', |
|
10 |
'star_count' => 300, |
|
11 |
'description' => 'fake repository' }] |
|
7 | 12 |
end |
8 | 13 |
|
9 |
test 'shows taxonomies tabs' do |
|
10 |
visit new_container_path |
|
11 |
assert has_selector?("a", :text => 'Locations') if SETTINGS[:locations_enabled] |
|
12 |
assert has_selector?("a", :text => 'Organizations') if SETTINGS[:organizations_enabled] |
|
14 |
let(:preliminary) do |
|
15 |
DockerContainerWizardStates::Preliminary.create!( |
|
16 |
:wizard_state => wizard_state, |
|
17 |
:compute_resource => compute_resource |
|
18 |
) |
|
19 |
end |
|
20 |
|
|
21 |
setup do |
|
22 |
stub_image_existance |
|
23 |
stub_registry_api |
|
24 |
ImageSearchController.any_instance.stubs(:image_search_service) |
|
25 |
.returns(image_search_service) |
|
26 |
end |
|
27 |
|
|
28 |
describe 'on preliminary step' do |
|
29 |
test 'it shows docker compute resources' do |
|
30 |
compute_resource.save |
|
31 |
visit wizard_state_step_path(:wizard_state_id => wizard_state, :id => :preliminary) |
|
32 |
assert_text compute_resource.name |
|
33 |
end |
|
34 |
|
|
35 |
context 'when no compute resources are available' do |
|
36 |
setup do |
|
37 |
ForemanDocker::Docker.destroy_all |
|
38 |
end |
|
39 |
|
|
40 |
test 'shows a link to a new compute resource if none is available' do |
|
41 |
visit wizard_state_step_path(:wizard_state_id => wizard_state, :id => :preliminary) |
|
42 |
assert has_selector?("div.alert", :text => 'Please add a new one') |
|
43 |
end |
|
44 |
end |
|
45 |
|
|
46 |
test 'shows taxonomies tabs' do |
|
47 |
visit wizard_state_step_path(:wizard_state_id => wizard_state, :id => :preliminary) |
|
48 |
assert has_selector?("a", :text => 'Locations') if SETTINGS[:locations_enabled] |
|
49 |
assert has_selector?("a", :text => 'Organizations') if SETTINGS[:organizations_enabled] |
|
50 |
end |
|
51 |
end |
|
52 |
|
|
53 |
describe 'on image step' do |
|
54 |
['hub', 'registry'].each do |tab| |
|
55 |
describe "on #{tab} tab" do |
|
56 |
let(:image_field_id) { "#{tab}_docker_container_wizard_states_image_repository_name" } |
|
57 |
let(:tag_field_id) { "#{tab}_docker_container_wizard_states_image_tag" } |
|
58 |
|
|
59 |
setup do |
|
60 |
registry.save |
|
61 |
wizard_state.preliminary = preliminary |
|
62 |
visit wizard_state_step_path(:wizard_state_id => wizard_state, :id => :image) |
|
63 |
find("##{tab}_tab").click |
|
64 |
|
|
65 |
if tab == 'registry' |
|
66 |
find("#docker_container_wizard_states_image_registry_id option:last-child", :visible => false) |
|
67 |
.select_option |
|
68 |
end |
|
69 |
end |
|
70 |
|
|
71 |
test 'clicking on search loads repositories' do |
|
72 |
image_search_service.expects(:search).at_least(2) |
|
73 |
.returns(image_search_results) |
|
74 |
fill_in image_field_id, :with => "fake" |
|
75 |
wait_for_ajax |
|
76 |
find("#search_repository_button_#{tab}").click |
|
77 |
wait_for_ajax |
|
78 |
assert_text 'my_fake_repository_result' |
|
79 |
end |
|
80 |
|
|
81 |
describe 'autcomplete' do |
|
82 |
describe 'for image name' do |
|
83 |
test 'entering text triggers autocomplete' do |
|
84 |
image_search_service.expects(:search) |
|
85 |
.returns(image_search_results) |
|
86 |
fill_in image_field_id, :with => 'fa' |
|
87 |
wait_for_ajax |
|
88 |
has_selector?('.ui-autocomplete a', :text => 'my_fake_repository_result') |
|
89 |
end |
|
90 |
|
|
91 |
if tab == 'registry' |
|
92 |
context 'when no registry is selected' do |
|
93 |
test 'it does not trigger a autocomplete' do |
|
94 |
image_search_service.expects(:search).never |
|
95 |
find("#docker_container_wizard_states_image_registry_id option:first-child", :visible => false).select_option |
|
96 |
fill_in image_field_id, :with => 'fa' |
|
97 |
wait_for_ajax |
|
98 |
has_no_selector?('.ui-autocomplete a', :text => 'my_fake_repository_result') |
|
99 |
end |
|
100 |
end |
|
101 |
end |
|
102 |
end |
|
103 |
|
|
104 |
describe 'for tag' do |
|
105 |
let(:image_name) { 'fake' } |
|
106 |
let(:tag_snippet) { 'lat' } |
|
107 |
|
|
108 |
setup do |
|
109 |
fill_in image_field_id, :with => 'fake' |
|
110 |
end |
|
111 |
|
|
112 |
test 'it searches for tags' do |
|
113 |
image_search_service.expects(:search).at_least(2) |
|
114 |
.returns(['latest']) |
|
115 |
fill_in tag_field_id, :with => tag_snippet |
|
116 |
wait_for_ajax |
|
117 |
has_selector?('.ui-autocomplete a', :text => 'latest') |
|
118 |
end |
|
119 |
end |
|
120 |
end |
|
121 |
end |
|
122 |
end |
|
13 | 123 |
end |
14 |
# test 'clicking on search loads repositories' do |
|
15 |
# Capybara.javascript_driver = :webkit |
|
16 |
# container = FactoryGirl.create(:container) |
|
17 |
# visit container_step_path(:container_id => container.id, :id => :repository) |
|
18 |
# ComputeResource.any_instance.expects(:search).returns([{'name' => 'my_fake_repository_result', |
|
19 |
# 'star_count' => 300, |
|
20 |
# 'description' => 'fake repository'}]) |
|
21 |
# click_button 'search_repository' |
|
22 |
# assert has_link? 'my_fake_repository_result' |
|
23 |
# end |
|
24 | 124 |
end |
Also available in: Unified diff
Fixes #18902 - Enable autocomplete for container image search
This enables the autocomplete for the image name search and
improves the usability of searching for container images on
Docker Hub or an external Registry.