diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-11 18:10:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-11 18:10:57 +0300 |
commit | e40f19ef830c5863089bc6a7a73e6695efa60a13 (patch) | |
tree | c540032381175c4e95e3b6378698f91acac5100f /spec/frontend | |
parent | 1c7411c597334e20d2e92cc948f0699d339d2710 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
4 files changed, 107 insertions, 19 deletions
diff --git a/spec/frontend/members/mock_data.js b/spec/frontend/members/mock_data.js index f42ee295511..218db0b587a 100644 --- a/spec/frontend/members/mock_data.js +++ b/spec/frontend/members/mock_data.js @@ -39,7 +39,7 @@ export const member = { Developer: 30, Maintainer: 40, Owner: 50, - 'Minimal Access': 5, + 'Minimal access': 5, }, }; diff --git a/spec/frontend/packages_and_registries/dependency_proxy/app_spec.js b/spec/frontend/packages_and_registries/dependency_proxy/app_spec.js index 1f0252965b0..625f00a8666 100644 --- a/spec/frontend/packages_and_registries/dependency_proxy/app_spec.js +++ b/spec/frontend/packages_and_registries/dependency_proxy/app_spec.js @@ -1,32 +1,40 @@ -import { GlFormInputGroup, GlFormGroup, GlSkeletonLoader, GlSprintf } from '@gitlab/ui'; +import { + GlFormInputGroup, + GlFormGroup, + GlSkeletonLoader, + GlSprintf, + GlEmptyState, +} from '@gitlab/ui'; import { createLocalVue } from '@vue/test-utils'; import VueApollo from 'vue-apollo'; import createMockApollo from 'helpers/mock_apollo_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import { stripTypenames } from 'helpers/graphql_helpers'; import waitForPromises from 'helpers/wait_for_promises'; +import { GRAPHQL_PAGE_SIZE } from '~/packages_and_registries/dependency_proxy/constants'; import DependencyProxyApp from '~/packages_and_registries/dependency_proxy/app.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; +import ManifestsList from '~/packages_and_registries/dependency_proxy/components/manifests_list.vue'; import getDependencyProxyDetailsQuery from '~/packages_and_registries/dependency_proxy/graphql/queries/get_dependency_proxy_details.query.graphql'; -import { proxyDetailsQuery, proxyData } from './mock_data'; +import { proxyDetailsQuery, proxyData, pagination, proxyManifests } from './mock_data'; const localVue = createLocalVue(); describe('DependencyProxyApp', () => { let wrapper; let apolloProvider; + let resolver; const provideDefaults = { groupPath: 'gitlab-org', dependencyProxyAvailable: true, + noManifestsIllustration: 'noManifestsIllustration', }; - function createComponent({ - provide = provideDefaults, - resolver = jest.fn().mockResolvedValue(proxyDetailsQuery()), - } = {}) { + function createComponent({ provide = provideDefaults } = {}) { localVue.use(VueApollo); const requestHandlers = [[getDependencyProxyDetailsQuery, resolver]]; @@ -53,6 +61,12 @@ describe('DependencyProxyApp', () => { const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader); const findMainArea = () => wrapper.findByTestId('main-area'); const findProxyCountText = () => wrapper.findByTestId('proxy-count'); + const findManifestList = () => wrapper.findComponent(ManifestsList); + const findEmptyState = () => wrapper.findComponent(GlEmptyState); + + beforeEach(() => { + resolver = jest.fn().mockResolvedValue(proxyDetailsQuery()); + }); afterEach(() => { wrapper.destroy(); @@ -78,8 +92,8 @@ describe('DependencyProxyApp', () => { }); it('does not call the graphql endpoint', async () => { - const resolver = jest.fn().mockResolvedValue(proxyDetailsQuery()); - createComponent({ ...createComponentArguments, resolver }); + resolver = jest.fn().mockResolvedValue(proxyDetailsQuery()); + createComponent({ ...createComponentArguments }); await waitForPromises(); @@ -145,14 +159,73 @@ describe('DependencyProxyApp', () => { it('from group has a description with proxy count', () => { expect(findProxyCountText().text()).toBe('Contains 2 blobs of images (1024 Bytes)'); }); + + describe('manifest lists', () => { + describe('when there are no manifests', () => { + beforeEach(() => { + resolver = jest.fn().mockResolvedValue( + proxyDetailsQuery({ + extend: { dependencyProxyManifests: { nodes: [], pageInfo: pagination() } }, + }), + ); + createComponent(); + return waitForPromises(); + }); + + it('shows the empty state message', () => { + expect(findEmptyState().props()).toMatchObject({ + svgPath: provideDefaults.noManifestsIllustration, + title: DependencyProxyApp.i18n.noManifestTitle, + }); + }); + + it('hides the list', () => { + expect(findManifestList().exists()).toBe(false); + }); + }); + + describe('when there are manifests', () => { + it('hides the empty state message', () => { + expect(findEmptyState().exists()).toBe(false); + }); + + it('shows list', () => { + expect(findManifestList().props()).toMatchObject({ + manifests: proxyManifests(), + pagination: stripTypenames(pagination()), + }); + }); + + it('prev-page event on list fetches the previous page', () => { + findManifestList().vm.$emit('prev-page'); + + expect(resolver).toHaveBeenCalledWith({ + before: pagination().startCursor, + first: null, + fullPath: provideDefaults.groupPath, + last: GRAPHQL_PAGE_SIZE, + }); + }); + + it('next-page event on list fetches the next page', () => { + findManifestList().vm.$emit('next-page'); + + expect(resolver).toHaveBeenCalledWith({ + after: pagination().endCursor, + first: GRAPHQL_PAGE_SIZE, + fullPath: provideDefaults.groupPath, + }); + }); + }); + }); }); + describe('when the dependency proxy is disabled', () => { beforeEach(() => { - createComponent({ - resolver: jest - .fn() - .mockResolvedValue(proxyDetailsQuery({ extendSettings: { enabled: false } })), - }); + resolver = jest + .fn() + .mockResolvedValue(proxyDetailsQuery({ extendSettings: { enabled: false } })); + createComponent(); return waitForPromises(); }); diff --git a/spec/frontend/packages_and_registries/dependency_proxy/components/manifest_list_spec.js b/spec/frontend/packages_and_registries/dependency_proxy/components/manifest_list_spec.js index 2c3b4e96098..9e4c747a1bd 100644 --- a/spec/frontend/packages_and_registries/dependency_proxy/components/manifest_list_spec.js +++ b/spec/frontend/packages_and_registries/dependency_proxy/components/manifest_list_spec.js @@ -26,42 +26,56 @@ describe('Manifests List', () => { const findRows = () => wrapper.findAllComponents(ManifestRow); const findPagination = () => wrapper.findComponent(GlKeysetPagination); - beforeEach(() => { - createComponent(); - }); - afterEach(() => { wrapper.destroy(); }); it('has the correct title', () => { + createComponent(); + expect(wrapper.text()).toContain(Component.i18n.listTitle); }); it('shows a row for every manifest', () => { + createComponent(); + expect(findRows().length).toBe(defaultProps.manifests.length); }); it('binds a manifest to each row', () => { + createComponent(); + expect(findRows().at(0).props()).toMatchObject({ manifest: defaultProps.manifests[0], }); }); describe('pagination', () => { + it('is hidden when there is no next or prev pages', () => { + createComponent({ ...defaultProps, pagination: {} }); + + expect(findPagination().exists()).toBe(false); + }); + it('has the correct props', () => { + createComponent(); + expect(findPagination().props()).toMatchObject({ ...defaultProps.pagination, }); }); it('emits the next-page event', () => { + createComponent(); + findPagination().vm.$emit('next'); expect(wrapper.emitted('next-page')).toEqual([[]]); }); it('emits the prev-page event', () => { + createComponent(); + findPagination().vm.$emit('prev'); expect(wrapper.emitted('prev-page')).toEqual([[]]); diff --git a/spec/frontend/packages_and_registries/dependency_proxy/mock_data.js b/spec/frontend/packages_and_registries/dependency_proxy/mock_data.js index 119ec995462..8bad22b5287 100644 --- a/spec/frontend/packages_and_registries/dependency_proxy/mock_data.js +++ b/spec/frontend/packages_and_registries/dependency_proxy/mock_data.js @@ -21,7 +21,7 @@ export const pagination = (extend) => ({ ...extend, }); -export const proxyDetailsQuery = ({ extendSettings = {} } = {}) => ({ +export const proxyDetailsQuery = ({ extendSettings = {}, extend } = {}) => ({ data: { group: { ...proxyData(), @@ -34,6 +34,7 @@ export const proxyDetailsQuery = ({ extendSettings = {} } = {}) => ({ nodes: proxyManifests(), pageInfo: pagination(), }, + ...extend, }, }, }); |