From d8bb8d458c09146d70261026a5c90e97903b99c4 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 24 May 2019 10:39:18 +0100 Subject: Pull files for repository tree from GraphQL API --- .../table/__snapshots__/row_spec.js.snap | 2 + .../repository/components/table/index_spec.js | 51 ++++++++++++++++++---- .../repository/components/table/row_spec.js | 18 +++++--- 3 files changed, 55 insertions(+), 16 deletions(-) (limited to 'spec/frontend/repository/components') diff --git a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap index f0b72343b6e..1b4564303e4 100644 --- a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap +++ b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap @@ -16,7 +16,9 @@ exports[`Repository table row component renders table row 1`] = ` + test + diff --git a/spec/frontend/repository/components/table/index_spec.js b/spec/frontend/repository/components/table/index_spec.js index 6f52cffe077..827927e6d9a 100644 --- a/spec/frontend/repository/components/table/index_spec.js +++ b/spec/frontend/repository/components/table/index_spec.js @@ -3,18 +3,19 @@ import { GlLoadingIcon } from '@gitlab/ui'; import Table from '~/repository/components/table/index.vue'; let vm; +let $apollo; + +function factory(path, data = () => ({})) { + $apollo = { + query: jest.fn().mockReturnValue(Promise.resolve({ data: data() })), + }; -function factory(path, loading = false) { vm = shallowMount(Table, { propsData: { path, }, mocks: { - $apollo: { - queries: { - files: { loading }, - }, - }, + $apollo, }, }); } @@ -39,9 +40,41 @@ describe('Repository table component', () => { ); }); - it('renders loading icon', () => { - factory('/', true); + it('shows loading icon', () => { + factory('/'); + + vm.setData({ isLoadingFiles: true }); + + expect(vm.find(GlLoadingIcon).isVisible()).toBe(true); + }); + + describe('normalizeData', () => { + it('normalizes edge nodes', () => { + const output = vm.vm.normalizeData('blobs', [{ node: '1' }, { node: '2' }]); + + expect(output).toEqual(['1', '2']); + }); + }); + + describe('hasNextPage', () => { + it('returns undefined when hasNextPage is false', () => { + const output = vm.vm.hasNextPage({ + trees: { pageInfo: { hasNextPage: false } }, + submodules: { pageInfo: { hasNextPage: false } }, + blobs: { pageInfo: { hasNextPage: false } }, + }); + + expect(output).toBe(undefined); + }); + + it('returns pageInfo object when hasNextPage is true', () => { + const output = vm.vm.hasNextPage({ + trees: { pageInfo: { hasNextPage: false } }, + submodules: { pageInfo: { hasNextPage: false } }, + blobs: { pageInfo: { hasNextPage: true, nextCursor: 'test' } }, + }); - expect(vm.find(GlLoadingIcon).exists()).toBe(true); + expect(output).toEqual({ hasNextPage: true, nextCursor: 'test' }); + }); }); }); diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js index 216128dce25..6b4508c418e 100644 --- a/spec/frontend/repository/components/table/row_spec.js +++ b/spec/frontend/repository/components/table/row_spec.js @@ -29,9 +29,10 @@ describe('Repository table row component', () => { it('renders table row', () => { factory({ - id: 1, + id: '1', path: 'test', type: 'file', + currentPath: '/', }); expect(vm.element).toMatchSnapshot(); @@ -39,14 +40,15 @@ describe('Repository table row component', () => { it.each` type | component | componentName - ${'folder'} | ${RouterLinkStub} | ${'RouterLink'} + ${'tree'} | ${RouterLinkStub} | ${'RouterLink'} ${'file'} | ${'a'} | ${'hyperlink'} ${'commit'} | ${'a'} | ${'hyperlink'} `('renders a $componentName for type $type', ({ type, component }) => { factory({ - id: 1, + id: '1', path: 'test', type, + currentPath: '/', }); expect(vm.find(component).exists()).toBe(true); @@ -54,14 +56,15 @@ describe('Repository table row component', () => { it.each` type | pushes - ${'folder'} | ${true} + ${'tree'} | ${true} ${'file'} | ${false} ${'commit'} | ${false} - `('pushes new router if type $type is folder', ({ type, pushes }) => { + `('pushes new router if type $type is tree', ({ type, pushes }) => { factory({ - id: 1, + id: '1', path: 'test', type, + currentPath: '/', }); vm.trigger('click'); @@ -75,9 +78,10 @@ describe('Repository table row component', () => { it('renders commit ID for submodule', () => { factory({ - id: 1, + id: '1', path: 'test', type: 'commit', + currentPath: '/', }); expect(vm.find('.commit-sha').text()).toContain('1'); -- cgit v1.2.1