Commit c57c78f4 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Natalia Tepluhina

Fix error messages and adjust tests

- source
- test
parent fe32171c
...@@ -72,7 +72,7 @@ export default { ...@@ -72,7 +72,7 @@ export default {
<template #left-primary> <template #left-primary>
<router-link <router-link
class="gl-text-body gl-font-weight-bold" class="gl-text-body gl-font-weight-bold"
data-testid="detailsLink" data-testid="details-link"
:to="{ name: 'details', params: { id: item.id } }" :to="{ name: 'details', params: { id: item.id } }"
> >
{{ item.path }} {{ item.path }}
......
...@@ -56,7 +56,7 @@ export const requestTagsList = ({ commit, dispatch, state: { imageDetails } }, p ...@@ -56,7 +56,7 @@ export const requestTagsList = ({ commit, dispatch, state: { imageDetails } }, p
dispatch('receiveTagsListSuccess', { data, headers }); dispatch('receiveTagsListSuccess', { data, headers });
}) })
.catch(() => { .catch(() => {
createFlash(FETCH_TAGS_LIST_ERROR_MESSAGE); createFlash({ message: FETCH_TAGS_LIST_ERROR_MESSAGE });
}) })
.finally(() => { .finally(() => {
commit(types.SET_MAIN_LOADING, false); commit(types.SET_MAIN_LOADING, false);
...@@ -71,7 +71,7 @@ export const requestImageDetailsAndTagsList = ({ dispatch, commit }, id) => { ...@@ -71,7 +71,7 @@ export const requestImageDetailsAndTagsList = ({ dispatch, commit }, id) => {
dispatch('requestTagsList'); dispatch('requestTagsList');
}) })
.catch(() => { .catch(() => {
createFlash(FETCH_IMAGE_DETAILS_ERROR_MESSAGE); createFlash({ message: FETCH_IMAGE_DETAILS_ERROR_MESSAGE });
commit(types.SET_MAIN_LOADING, false); commit(types.SET_MAIN_LOADING, false);
}); });
}; };
......
export const pathGenerator = (imageDetails, ending = '?format=json') => { export const pathGenerator = (imageDetails, ending = '?format=json') => {
// this method is a temporary workaround, to be removed with graphql implementation // this method is a temporary workaround, to be removed with graphql implementation
// https://gitlab.com/gitlab-org/gitlab/-/issues/276432 // https://gitlab.com/gitlab-org/gitlab/-/issues/276432
const basePath = imageDetails.name
? imageDetails.path.replace(`/${imageDetails.name}`, '') const splitPath = imageDetails.path.split('/').reverse();
: imageDetails.path; const splitName = imageDetails.name ? imageDetails.name.split('/').reverse() : [];
const basePath = splitPath
.reduce((acc, curr, index) => {
if (splitPath[index] !== splitName[index]) {
acc.unshift(curr);
}
return acc;
}, [])
.join('/');
return `/${basePath}/registry/repository/${imageDetails.id}/tags${ending}`; return `/${basePath}/registry/repository/${imageDetails.id}/tags${ending}`;
}; };
...@@ -89,6 +89,20 @@ RSpec.describe 'Container Registry', :js do ...@@ -89,6 +89,20 @@ RSpec.describe 'Container Registry', :js do
end end
end end
context 'when an image has the same name as the subgroup' do
before do
stub_container_registry_tags(tags: %w[latest], with_manifest: true)
project.container_repositories << create(:container_repository, name: group.name)
visit_container_registry
end
it 'details page loads properly' do
find('a[data-testid="details-link"]').click
expect(page).to have_content 'latest'
end
end
def visit_container_registry def visit_container_registry
visit group_container_registries_path(group) visit group_container_registries_path(group)
end end
......
...@@ -10,6 +10,10 @@ RSpec.describe 'Container Registry', :js do ...@@ -10,6 +10,10 @@ RSpec.describe 'Container Registry', :js do
create(:container_repository, name: 'my/image') create(:container_repository, name: 'my/image')
end end
let(:nameless_container_repository) do
create(:container_repository, name: '')
end
before do before do
sign_in(user) sign_in(user)
project.add_developer(user) project.add_developer(user)
...@@ -96,6 +100,20 @@ RSpec.describe 'Container Registry', :js do ...@@ -96,6 +100,20 @@ RSpec.describe 'Container Registry', :js do
end end
end end
describe 'image repo details when image has no name' do
before do
stub_container_registry_tags(tags: %w[latest], with_manifest: true)
project.container_repositories << nameless_container_repository
visit_container_registry
end
it 'renders correctly' do
find('a[data-testid="details-link"]').click
expect(page).to have_content 'latest'
end
end
context 'when there are more than 10 images' do context 'when there are more than 10 images' do
before do before do
create_list(:container_repository, 12, project: project) create_list(:container_repository, 12, project: project)
......
...@@ -19,7 +19,7 @@ describe('Image List Row', () => { ...@@ -19,7 +19,7 @@ describe('Image List Row', () => {
let wrapper; let wrapper;
const item = imagesListResponse.data[0]; const item = imagesListResponse.data[0];
const findDetailsLink = () => wrapper.find('[data-testid="detailsLink"]'); const findDetailsLink = () => wrapper.find('[data-testid="details-link"]');
const findTagsCount = () => wrapper.find('[data-testid="tagsCount"]'); const findTagsCount = () => wrapper.find('[data-testid="tagsCount"]');
const findDeleteBtn = () => wrapper.find(DeleteButton); const findDeleteBtn = () => wrapper.find(DeleteButton);
const findClipboardButton = () => wrapper.find(ClipboardButton); const findClipboardButton = () => wrapper.find(ClipboardButton);
......
...@@ -8,6 +8,11 @@ import * as actions from '~/registry/explorer/stores/actions'; ...@@ -8,6 +8,11 @@ import * as actions from '~/registry/explorer/stores/actions';
import * as types from '~/registry/explorer/stores/mutation_types'; import * as types from '~/registry/explorer/stores/mutation_types';
import { reposServerResponse, registryServerResponse } from '../mock_data'; import { reposServerResponse, registryServerResponse } from '../mock_data';
import * as utils from '~/registry/explorer/utils'; import * as utils from '~/registry/explorer/utils';
import {
FETCH_IMAGES_LIST_ERROR_MESSAGE,
FETCH_TAGS_LIST_ERROR_MESSAGE,
FETCH_IMAGE_DETAILS_ERROR_MESSAGE,
} from '~/registry/explorer/constants/index';
jest.mock('~/flash.js'); jest.mock('~/flash.js');
jest.mock('~/registry/explorer/utils'); jest.mock('~/registry/explorer/utils');
...@@ -129,7 +134,7 @@ describe('Actions RegistryExplorer Store', () => { ...@@ -129,7 +134,7 @@ describe('Actions RegistryExplorer Store', () => {
], ],
[], [],
() => { () => {
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalledWith({ message: FETCH_IMAGES_LIST_ERROR_MESSAGE });
done(); done();
}, },
); );
...@@ -169,7 +174,7 @@ describe('Actions RegistryExplorer Store', () => { ...@@ -169,7 +174,7 @@ describe('Actions RegistryExplorer Store', () => {
], ],
[], [],
() => { () => {
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalledWith({ message: FETCH_TAGS_LIST_ERROR_MESSAGE });
done(); done();
}, },
); );
...@@ -261,7 +266,7 @@ describe('Actions RegistryExplorer Store', () => { ...@@ -261,7 +266,7 @@ describe('Actions RegistryExplorer Store', () => {
], ],
[], [],
() => { () => {
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalledWith({ message: FETCH_IMAGE_DETAILS_ERROR_MESSAGE });
done(); done();
}, },
); );
......
...@@ -16,6 +16,20 @@ describe('Utils', () => { ...@@ -16,6 +16,20 @@ describe('Utils', () => {
expect(pathGenerator(imageDetails, '/foo')).toBe('/foo/bar/registry/repository/1/tags/foo'); expect(pathGenerator(imageDetails, '/foo')).toBe('/foo/bar/registry/repository/1/tags/foo');
}); });
it.each`
path | name | result
${'foo/foo'} | ${''} | ${'/foo/foo/registry/repository/1/tags?format=json'}
${'foo/foo/foo'} | ${'foo'} | ${'/foo/foo/registry/repository/1/tags?format=json'}
${'baz/foo/foo/foo'} | ${'foo'} | ${'/baz/foo/foo/registry/repository/1/tags?format=json'}
${'baz/foo/foo/foo'} | ${'foo'} | ${'/baz/foo/foo/registry/repository/1/tags?format=json'}
${'foo/foo/baz/foo/foo'} | ${'foo/foo'} | ${'/foo/foo/baz/registry/repository/1/tags?format=json'}
${'foo/foo/baz/foo/bar'} | ${'foo/bar'} | ${'/foo/foo/baz/registry/repository/1/tags?format=json'}
${'baz/foo/foo'} | ${'foo'} | ${'/baz/foo/registry/repository/1/tags?format=json'}
${'baz/foo/bar'} | ${'foo'} | ${'/baz/foo/bar/registry/repository/1/tags?format=json'}
`('returns the correct path when path is $path and name is $name', ({ name, path, result }) => {
expect(pathGenerator({ id: 1, name, path })).toBe(result);
});
it('returns the url unchanged when imageDetails have no name', () => { it('returns the url unchanged when imageDetails have no name', () => {
const imageDetailsWithoutName = { const imageDetailsWithoutName = {
path: 'foo/bar/baz', path: 'foo/bar/baz',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment