Commit a1f735f3 authored by Nathan Friend's avatar Nathan Friend

Move visibility control to parent component

This commit updates releases_pagination_apollo_client.vue to not
control its own visibility and instead gives this responsibility to its
parent.
parent 8e10dcb8
...@@ -108,7 +108,11 @@ export default { ...@@ -108,7 +108,11 @@ export default {
return this.isLoading && !this.hasError; return this.isLoading && !this.hasError;
}, },
shouldRenderPagination() { shouldRenderPagination() {
return !this.isLoading && !this.hasError; return (
!this.isLoading &&
!this.hasError &&
(this.pageInfo.hasPreviousPage || this.pageInfo.hasNextPage)
);
}, },
}, },
created() { created() {
......
...@@ -13,11 +13,6 @@ export default { ...@@ -13,11 +13,6 @@ export default {
validator: (info) => isBoolean(info.hasPreviousPage) && isBoolean(info.hasNextPage), validator: (info) => isBoolean(info.hasPreviousPage) && isBoolean(info.hasNextPage),
}, },
}, },
computed: {
showPagination() {
return this.pageInfo.hasPreviousPage || this.pageInfo.hasNextPage;
},
},
methods: { methods: {
onPrev(before) { onPrev(before) {
historyPushState(buildUrlWithCurrentLocation(`?before=${before}`)); historyPushState(buildUrlWithCurrentLocation(`?before=${before}`));
...@@ -31,7 +26,6 @@ export default { ...@@ -31,7 +26,6 @@ export default {
<template> <template>
<div class="gl-display-flex gl-justify-content-center"> <div class="gl-display-flex gl-justify-content-center">
<gl-keyset-pagination <gl-keyset-pagination
v-if="showPagination"
v-bind="pageInfo" v-bind="pageInfo"
v-on="$listeners" v-on="$listeners"
@prev="onPrev($event)" @prev="onPrev($event)"
......
...@@ -160,7 +160,7 @@ describe('app_index_apollo_client.vue', () => { ...@@ -160,7 +160,7 @@ describe('app_index_apollo_client.vue', () => {
expectNoFlashMessage(); expectNoFlashMessage();
expectNewReleaseButton(); expectNewReleaseButton();
expectReleases(0); expectReleases(0);
expectPagination(); expectNoPagination();
}); });
describe('when an error occurs while loading data', () => { describe('when an error occurs while loading data', () => {
...@@ -176,11 +176,25 @@ describe('app_index_apollo_client.vue', () => { ...@@ -176,11 +176,25 @@ describe('app_index_apollo_client.vue', () => {
expectNoPagination(); expectNoPagination();
}); });
describe('when the data has successfully loaded', () => { describe('when the data has successfully loaded with a single page of results', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
}); });
expectNoLoadingIndicator();
expectNoEmptyState();
expectNoFlashMessage();
expectNewReleaseButton();
expectReleases(originalAllReleasesQueryResponse.data.project.releases.nodes.length);
expectNoPagination();
});
describe('when the data has successfully loaded with multiple pages of results', () => {
beforeEach(() => {
allReleasesQueryResponse.data.project.releases.pageInfo.hasNextPage = true;
createComponent(Promise.resolve(allReleasesQueryResponse));
});
expectNoLoadingIndicator(); expectNoLoadingIndicator();
expectNoEmptyState(); expectNoEmptyState();
expectNoFlashMessage(); expectNoFlashMessage();
...@@ -260,13 +274,16 @@ describe('app_index_apollo_client.vue', () => { ...@@ -260,13 +274,16 @@ describe('app_index_apollo_client.vue', () => {
}); });
describe('pagination', () => { describe('pagination', () => {
it('requeries the GraphQL endpoint when a pagination button is clicked', async () => { beforeEach(async () => {
mockQueryParams = { before }; mockQueryParams = { before };
createComponent(); allReleasesQueryResponse.data.project.releases.pageInfo.hasNextPage = true;
createComponent(Promise.resolve(allReleasesQueryResponse));
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
});
it('requeries the GraphQL endpoint when a pagination button is clicked', async () => {
expect(allReleasesQueryMock.mock.calls).toEqual([[expect.objectContaining({ before })]]); expect(allReleasesQueryMock.mock.calls).toEqual([[expect.objectContaining({ before })]]);
mockQueryParams = { after }; mockQueryParams = { after };
......
import { GlKeysetPagination } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended } from 'helpers/vue_test_utils_helper';
import { historyPushState } from '~/lib/utils/common_utils'; import { historyPushState } from '~/lib/utils/common_utils';
import ReleasesPaginationApolloClient from '~/releases/components/releases_pagination_apollo_client.vue'; import ReleasesPaginationApolloClient from '~/releases/components/releases_pagination_apollo_client.vue';
...@@ -62,43 +61,30 @@ describe('releases_pagination_apollo_client.vue', () => { ...@@ -62,43 +61,30 @@ describe('releases_pagination_apollo_client.vue', () => {
endCursor, endCursor,
}; };
const findGlKeysetPagination = () => wrapper.findComponent(GlKeysetPagination);
const findPrevButton = () => wrapper.findByTestId('prevButton'); const findPrevButton = () => wrapper.findByTestId('prevButton');
const findNextButton = () => wrapper.findByTestId('nextButton'); const findNextButton = () => wrapper.findByTestId('nextButton');
describe.each` describe.each`
description | pageInfo | paginationRendered | prevEnabled | nextEnabled description | pageInfo | prevEnabled | nextEnabled
${'when there is only one page of results'} | ${singlePageInfo} | ${false} | ${'N/A'} | ${'N/A'} ${'when there is only one page of results'} | ${singlePageInfo} | ${false} | ${false}
${'when there is a next page, but not a previous page'} | ${onlyNextPageInfo} | ${true} | ${false} | ${true} ${'when there is a next page, but not a previous page'} | ${onlyNextPageInfo} | ${false} | ${true}
${'when there is a previous page, but not a next page'} | ${onlyPrevPageInfo} | ${true} | ${true} | ${false} ${'when there is a previous page, but not a next page'} | ${onlyPrevPageInfo} | ${true} | ${false}
${'when there is both a previous and next page'} | ${prevAndNextPageInfo} | ${true} | ${true} | ${true} ${'when there is both a previous and next page'} | ${prevAndNextPageInfo} | ${true} | ${true}
`( `('component states', ({ description, pageInfo, prevEnabled, nextEnabled }) => {
'component states', describe(description, () => {
({ description, pageInfo, paginationRendered, prevEnabled, nextEnabled }) => { beforeEach(() => {
describe(description, () => { createComponent(pageInfo);
beforeEach(() => { });
createComponent(pageInfo);
}); it(`renders the "Prev" button as ${prevEnabled ? 'enabled' : 'disabled'}`, () => {
expect(findPrevButton().attributes().disabled).toBe(prevEnabled ? undefined : 'disabled');
it(`does ${paginationRendered ? '' : 'not '}render a GlKeysetPagination`, () => {
expect(findGlKeysetPagination().exists()).toBe(paginationRendered);
});
// The remaining tests don't apply if the GlKeysetPagination component is not rendered
if (!paginationRendered) {
return;
}
it(`renders the "Prev" button as ${prevEnabled ? 'enabled' : 'disabled'}`, () => {
expect(findPrevButton().attributes().disabled).toBe(prevEnabled ? undefined : 'disabled');
});
it(`renders the "Next" button as ${nextEnabled ? 'enabled' : 'disabled'}`, () => {
expect(findNextButton().attributes().disabled).toBe(nextEnabled ? undefined : 'disabled');
});
}); });
},
); it(`renders the "Next" button as ${nextEnabled ? 'enabled' : 'disabled'}`, () => {
expect(findNextButton().attributes().disabled).toBe(nextEnabled ? undefined : 'disabled');
});
});
});
describe('button behavior', () => { describe('button behavior', () => {
beforeEach(() => { beforeEach(() => {
......
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