Commit b98f4a76 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Martin Wortschack

Trigger load of images only on first navigation

- update router
- add feature test to ensure coverage of the functionality
parent 99b3ee82
...@@ -24,10 +24,10 @@ export default { ...@@ -24,10 +24,10 @@ export default {
}, },
lastCrumb() { lastCrumb() {
const { children } = last(this.crumbs); const { children } = last(this.crumbs);
const { tagName, classList } = first(children); const { tagName, className } = first(children);
return { return {
tagName, tagName,
classList: [...classList], className,
text: this.$route.meta.nameGenerator(this.$route), text: this.$route.meta.nameGenerator(this.$route),
path: { to: this.$route.name }, path: { to: this.$route.name },
}; };
...@@ -41,7 +41,7 @@ export default { ...@@ -41,7 +41,7 @@ export default {
<li <li
v-for="(crumb, index) in rootCrumbs" v-for="(crumb, index) in rootCrumbs"
:key="index" :key="index"
:class="crumb.classList" :class="crumb.className"
v-html="crumb.innerHTML" v-html="crumb.innerHTML"
></li> ></li>
<li v-if="!isRootRoute"> <li v-if="!isRootRoute">
...@@ -51,7 +51,7 @@ export default { ...@@ -51,7 +51,7 @@ export default {
<component :is="divider.tagName" :class="divider.classList" v-html="divider.innerHTML" /> <component :is="divider.tagName" :class="divider.classList" v-html="divider.innerHTML" />
</li> </li>
<li> <li>
<component :is="lastCrumb.tagName" ref="lastCrumb" :class="lastCrumb.classList"> <component :is="lastCrumb.tagName" ref="lastCrumb" :class="lastCrumb.className">
<router-link ref="childRouteLink" :to="lastCrumb.path">{{ lastCrumb.text }}</router-link> <router-link ref="childRouteLink" :to="lastCrumb.path">{{ lastCrumb.text }}</router-link>
</component> </component>
</li> </li>
......
...@@ -21,7 +21,9 @@ export default function createRouter(base, store) { ...@@ -21,7 +21,9 @@ export default function createRouter(base, store) {
root: true, root: true,
}, },
beforeEnter: (to, from, next) => { beforeEnter: (to, from, next) => {
if (!from.name || !store.state.images?.length) {
store.dispatch('requestImagesList'); store.dispatch('requestImagesList');
}
next(); next();
}, },
}, },
......
...@@ -149,12 +149,36 @@ describe 'Container Registry', :js do ...@@ -149,12 +149,36 @@ describe 'Container Registry', :js do
end end
it('pagination navigate to the second page') do it('pagination navigate to the second page') do
pagination = find('.gl-pagination') visit_second_page
pagination.click_link('2')
expect(page).to have_content '20' expect(page).to have_content '20'
end end
end end
end end
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
it 'shows pagination' do
expect(page).to have_css '.gl-pagination'
end
it 'pagination goes to second page' do
visit_second_page
expect(page).to have_content 'my/image'
end
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'
end
end
end end
def visit_container_registry def visit_container_registry
...@@ -163,6 +187,11 @@ describe 'Container Registry', :js do ...@@ -163,6 +187,11 @@ describe 'Container Registry', :js do
def visit_container_registry_details(name) def visit_container_registry_details(name)
visit_container_registry visit_container_registry
click_link(name) click_link name
end
def visit_second_page
pagination = find '.gl-pagination'
pagination.click_link '2'
end end
end end
...@@ -7,14 +7,14 @@ describe('Registry Breadcrumb', () => { ...@@ -7,14 +7,14 @@ describe('Registry Breadcrumb', () => {
const nameGenerator = jest.fn(); const nameGenerator = jest.fn();
const crumb = { const crumb = {
classList: ['foo', 'bar'], className: 'foo bar',
tagName: 'div', tagName: 'div',
innerHTML: 'baz', innerHTML: 'baz',
querySelector: jest.fn(), querySelector: jest.fn(),
children: [ children: [
{ {
tagName: 'a', tagName: 'a',
classList: ['foo'], className: 'foo',
}, },
], ],
}; };
...@@ -25,7 +25,7 @@ describe('Registry Breadcrumb', () => { ...@@ -25,7 +25,7 @@ describe('Registry Breadcrumb', () => {
innerHTML: 'foo', innerHTML: 'foo',
}; };
const crumbs = [crumb, { ...crumb, innerHTML: 'foo' }, { ...crumb, classList: ['baz'] }]; const crumbs = [crumb, { ...crumb, innerHTML: 'foo' }, { ...crumb, className: 'baz' }];
const routes = [ const routes = [
{ name: 'foo', meta: { nameGenerator, root: true } }, { name: 'foo', meta: { nameGenerator, root: true } },
...@@ -121,7 +121,11 @@ describe('Registry Breadcrumb', () => { ...@@ -121,7 +121,11 @@ describe('Registry Breadcrumb', () => {
}); });
it('has the same classes as the last children of the crumbs', () => { it('has the same classes as the last children of the crumbs', () => {
expect(findLastCrumb().classes()).toEqual(lastChildren.classList); expect(
findLastCrumb()
.classes()
.join(' '),
).toEqual(lastChildren.className);
}); });
it('has a link to the current route', () => { it('has a link to the current route', () => {
......
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