diff options
Diffstat (limited to 'spec/frontend/repository')
6 files changed, 286 insertions, 0 deletions
diff --git a/spec/frontend/repository/components/breadcrumbs_spec.js b/spec/frontend/repository/components/breadcrumbs_spec.js new file mode 100644 index 00000000000..068fa317a87 --- /dev/null +++ b/spec/frontend/repository/components/breadcrumbs_spec.js @@ -0,0 +1,44 @@ +import { shallowMount, RouterLinkStub } from '@vue/test-utils'; +import Breadcrumbs from '~/repository/components/breadcrumbs.vue'; + +let vm; + +function factory(currentPath) { + vm = shallowMount(Breadcrumbs, { + propsData: { + currentPath, + }, + stubs: { + RouterLink: RouterLinkStub, + }, + }); +} + +describe('Repository breadcrumbs component', () => { + afterEach(() => { + vm.destroy(); + }); + + it.each` + path | linkCount + ${'/'} | ${1} + ${'app'} | ${2} + ${'app/assets'} | ${3} + ${'app/assets/javascripts'} | ${4} + `('renders $linkCount links for path $path', ({ path, linkCount }) => { + factory(path); + + expect(vm.findAll(RouterLinkStub).length).toEqual(linkCount); + }); + + it('renders last link as active', () => { + factory('app/assets'); + + expect( + vm + .findAll(RouterLinkStub) + .at(2) + .attributes('aria-current'), + ).toEqual('page'); + }); +}); diff --git a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap new file mode 100644 index 00000000000..1b4564303e4 --- /dev/null +++ b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Repository table row component renders table row 1`] = ` +<tr + class="tree-item file_1" +> + <td + class="tree-item-file-name" + > + <i + aria-label="file" + class="fa fa-fw fa-file-text-o" + role="img" + /> + + <a + class="str-truncated" + > + + test + + </a> + + <!----> + </td> + + <td + class="d-none d-sm-table-cell tree-commit" + /> + + <td + class="tree-time-ago text-right" + /> +</tr> +`; diff --git a/spec/frontend/repository/components/table/index_spec.js b/spec/frontend/repository/components/table/index_spec.js new file mode 100644 index 00000000000..827927e6d9a --- /dev/null +++ b/spec/frontend/repository/components/table/index_spec.js @@ -0,0 +1,80 @@ +import { shallowMount } from '@vue/test-utils'; +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() })), + }; + + vm = shallowMount(Table, { + propsData: { + path, + }, + mocks: { + $apollo, + }, + }); +} + +describe('Repository table component', () => { + afterEach(() => { + vm.destroy(); + }); + + it.each` + path | ref + ${'/'} | ${'master'} + ${'app/assets'} | ${'master'} + ${'/'} | ${'test'} + `('renders table caption for $ref in $path', ({ path, ref }) => { + factory(path); + + vm.setData({ ref }); + + expect(vm.find('caption').text()).toEqual( + `Files, directories, and submodules in the path ${path} for commit reference ${ref}`, + ); + }); + + 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(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 new file mode 100644 index 00000000000..6b4508c418e --- /dev/null +++ b/spec/frontend/repository/components/table/row_spec.js @@ -0,0 +1,89 @@ +import { shallowMount, RouterLinkStub } from '@vue/test-utils'; +import TableRow from '~/repository/components/table/row.vue'; + +let vm; +let $router; + +function factory(propsData = {}) { + $router = { + push: jest.fn(), + }; + + vm = shallowMount(TableRow, { + propsData, + mocks: { + $router, + }, + stubs: { + RouterLink: RouterLinkStub, + }, + }); + + vm.setData({ ref: 'master' }); +} + +describe('Repository table row component', () => { + afterEach(() => { + vm.destroy(); + }); + + it('renders table row', () => { + factory({ + id: '1', + path: 'test', + type: 'file', + currentPath: '/', + }); + + expect(vm.element).toMatchSnapshot(); + }); + + it.each` + type | component | componentName + ${'tree'} | ${RouterLinkStub} | ${'RouterLink'} + ${'file'} | ${'a'} | ${'hyperlink'} + ${'commit'} | ${'a'} | ${'hyperlink'} + `('renders a $componentName for type $type', ({ type, component }) => { + factory({ + id: '1', + path: 'test', + type, + currentPath: '/', + }); + + expect(vm.find(component).exists()).toBe(true); + }); + + it.each` + type | pushes + ${'tree'} | ${true} + ${'file'} | ${false} + ${'commit'} | ${false} + `('pushes new router if type $type is tree', ({ type, pushes }) => { + factory({ + id: '1', + path: 'test', + type, + currentPath: '/', + }); + + vm.trigger('click'); + + if (pushes) { + expect($router.push).toHaveBeenCalledWith({ path: '/tree/master/test' }); + } else { + expect($router.push).not.toHaveBeenCalled(); + } + }); + + it('renders commit ID for submodule', () => { + factory({ + id: '1', + path: 'test', + type: 'commit', + currentPath: '/', + }); + + expect(vm.find('.commit-sha').text()).toContain('1'); + }); +}); diff --git a/spec/frontend/repository/utils/icon_spec.js b/spec/frontend/repository/utils/icon_spec.js new file mode 100644 index 00000000000..3d84705f7ea --- /dev/null +++ b/spec/frontend/repository/utils/icon_spec.js @@ -0,0 +1,23 @@ +import { getIconName } from '~/repository/utils/icon'; + +describe('getIconName', () => { + // Tests the returning font awesome icon name + // We only test one for each file type to save testing a lot of different + // file types + it.each` + type | path | icon + ${'tree'} | ${''} | ${'folder'} + ${'commit'} | ${''} | ${'archive'} + ${'file'} | ${'test.pdf'} | ${'file-pdf-o'} + ${'file'} | ${'test.jpg'} | ${'file-image-o'} + ${'file'} | ${'test.zip'} | ${'file-archive-o'} + ${'file'} | ${'test.mp3'} | ${'file-audio-o'} + ${'file'} | ${'test.flv'} | ${'file-video-o'} + ${'file'} | ${'test.dotx'} | ${'file-word-o'} + ${'file'} | ${'test.xlsb'} | ${'file-excel-o'} + ${'file'} | ${'test.ppam'} | ${'file-powerpoint-o'} + ${'file'} | ${'test.js'} | ${'file-text-o'} + `('returns $icon for $type with path $path', ({ type, path, icon }) => { + expect(getIconName(type, path)).toEqual(icon); + }); +}); diff --git a/spec/frontend/repository/utils/title_spec.js b/spec/frontend/repository/utils/title_spec.js new file mode 100644 index 00000000000..c4879716fd7 --- /dev/null +++ b/spec/frontend/repository/utils/title_spec.js @@ -0,0 +1,15 @@ +import { setTitle } from '~/repository/utils/title'; + +describe('setTitle', () => { + it.each` + path | title + ${'/'} | ${'Files'} + ${'app'} | ${'app'} + ${'app/assets'} | ${'app/assets'} + ${'app/assets/javascripts'} | ${'app/assets/javascripts'} + `('sets document title as $title for $path', ({ path, title }) => { + setTitle(path, 'master', 'GitLab'); + + expect(document.title).toEqual(`${title} · master · GitLab`); + }); +}); |