2020-02-25 10:08:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Container Registry', :js do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
let(:container_repository) do
|
|
|
|
create(:container_repository, name: 'my/image')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.add_developer(user)
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
stub_container_registry_tags(repository: :any, tags: [])
|
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'has a page title set' do
|
|
|
|
visit_container_registry
|
|
|
|
|
|
|
|
expect(page).to have_title _('Container Registry')
|
|
|
|
end
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
context 'when there are no image repositories' do
|
|
|
|
it 'list page has no container title' do
|
2020-02-25 10:08:50 -05:00
|
|
|
visit_container_registry
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
expect(page).to have_content _('There are no container images stored for this project')
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-05-27 08:08:19 -04:00
|
|
|
it 'list page has cli commands' do
|
2020-03-31 14:07:42 -04:00
|
|
|
visit_container_registry
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-05-27 08:08:19 -04:00
|
|
|
expect(page).to have_content _('CLI Commands')
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
2020-03-31 14:07:42 -04:00
|
|
|
end
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
context 'when there are image repositories' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_tags(repository: %r{my/image}, tags: %w[latest], with_manifest: true)
|
|
|
|
project.container_repositories << container_repository
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'list page has a list of images' do
|
2020-02-25 10:08:50 -05:00
|
|
|
visit_container_registry
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
expect(page).to have_content 'my/image'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'user removes entire container repository', :sidekiq_might_not_need_inline do
|
|
|
|
visit_container_registry
|
|
|
|
|
|
|
|
expect_any_instance_of(ContainerRepository).to receive(:delete_tags!).and_return(true)
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
find('[title="Remove repository"]').click
|
|
|
|
expect(find('.modal .modal-title')).to have_content _('Remove repository')
|
|
|
|
find('.modal .modal-footer .btn-danger').click
|
|
|
|
end
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'navigates to repo details' do
|
|
|
|
visit_container_registry_details('my/image')
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
expect(page).to have_content 'latest'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
describe 'image repo details' do
|
2020-02-25 10:08:50 -05:00
|
|
|
before do
|
2020-03-31 14:07:42 -04:00
|
|
|
stub_container_registry_tags(repository: %r{my/image}, tags: ('1'..'20').to_a, with_manifest: true)
|
|
|
|
visit_container_registry_details 'my/image'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'shows the details breadcrumb' do
|
|
|
|
expect(find('.breadcrumbs')).to have_link 'my/image'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'shows the image title' do
|
|
|
|
expect(page).to have_content 'my/image tags'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'user removes a specific tag from container repository' do
|
|
|
|
service = double('service')
|
|
|
|
expect(service).to receive(:execute).with(container_repository) { { status: :success } }
|
|
|
|
expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(container_repository.project, user, tags: ['1']) { service }
|
2020-02-25 10:08:50 -05:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
first('.js-delete-registry').click
|
|
|
|
expect(find('.modal .modal-title')).to have_content _('Remove tag')
|
|
|
|
find('.modal .modal-footer .btn-danger').click
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it('pagination navigate to the second page') do
|
|
|
|
visit_second_page
|
|
|
|
expect(page).to have_content '20'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
end
|
2020-03-31 14:07:42 -04:00
|
|
|
end
|
2020-03-23 02:09:28 -04:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
context 'when there are more than 10 images' do
|
|
|
|
before do
|
|
|
|
create_list(:container_repository, 12, project: project)
|
|
|
|
project.container_repositories << container_repository
|
|
|
|
visit_container_registry
|
|
|
|
end
|
2020-03-23 02:09:28 -04:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'shows pagination' do
|
|
|
|
expect(page).to have_css '.gl-pagination'
|
|
|
|
end
|
2020-03-23 02:09:28 -04:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'pagination goes to second page' do
|
|
|
|
visit_second_page
|
|
|
|
expect(page).to have_content 'my/image'
|
|
|
|
end
|
2020-03-23 02:09:28 -04:00
|
|
|
|
2020-03-31 14:07:42 -04:00
|
|
|
it 'pagination is preserved after navigating back from details' do
|
|
|
|
visit_second_page
|
|
|
|
click_link 'my/image'
|
|
|
|
breadcrumb = find '.breadcrumbs'
|
|
|
|
breadcrumb.click_link 'Container Registry'
|
|
|
|
expect(page).to have_content 'my/image'
|
2020-03-23 02:09:28 -04:00
|
|
|
end
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def visit_container_registry
|
|
|
|
visit project_container_registry_index_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_container_registry_details(name)
|
|
|
|
visit_container_registry
|
2020-03-23 02:09:28 -04:00
|
|
|
click_link name
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_second_page
|
|
|
|
pagination = find '.gl-pagination'
|
|
|
|
pagination.click_link '2'
|
2020-02-25 10:08:50 -05:00
|
|
|
end
|
|
|
|
end
|