summaryrefslogtreecommitdiff
path: root/spec/frontend/repository/components
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-05-24 10:39:18 +0100
committerPhil Hughes <me@iamphill.com>2019-05-24 13:58:11 +0100
commitd8bb8d458c09146d70261026a5c90e97903b99c4 (patch)
tree5403eb594816cf2010aa213d1446d1fa871a6a4a /spec/frontend/repository/components
parentc509b35b489ff69121c4760faa52d81e7666e9ca (diff)
downloadgitlab-ce-d8bb8d458c09146d70261026a5c90e97903b99c4.tar.gz
Pull files for repository tree from GraphQL API
Diffstat (limited to 'spec/frontend/repository/components')
-rw-r--r--spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap2
-rw-r--r--spec/frontend/repository/components/table/index_spec.js51
-rw-r--r--spec/frontend/repository/components/table/row_spec.js18
3 files changed, 55 insertions, 16 deletions
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`] = `
<a
class="str-truncated"
>
+
test
+
</a>
<!---->
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');