diff options
Diffstat (limited to 'spec/frontend/repository')
14 files changed, 109 insertions, 42 deletions
diff --git a/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap b/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap index cb56f392ec9..01494cb6a24 100644 --- a/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap +++ b/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap @@ -20,7 +20,8 @@ exports[`Repository last commit component renders commit widget 1`] = ` class="commit-detail flex-list gl-display-flex gl-justify-content-space-between gl-align-items-flex-start gl-flex-grow-1 gl-min-w-0" > <div - class="commit-content qa-commit-content" + class="commit-content" + data-qa-selector="commit_content" > <gl-link-stub class="commit-row-message item-title" diff --git a/spec/frontend/repository/components/blob_button_group_spec.js b/spec/frontend/repository/components/blob_button_group_spec.js index d5b882bd715..33a85c04fcf 100644 --- a/spec/frontend/repository/components/blob_button_group_spec.js +++ b/spec/frontend/repository/components/blob_button_group_spec.js @@ -66,12 +66,12 @@ describe('BlobButtonGroup component', () => { }); it('renders both the replace and delete button', () => { - expect(wrapper.findAll(GlButton)).toHaveLength(2); + expect(wrapper.findAllComponents(GlButton)).toHaveLength(2); }); it('renders the buttons in the correct order', () => { - expect(wrapper.findAll(GlButton).at(0).text()).toBe('Replace'); - expect(wrapper.findAll(GlButton).at(1).text()).toBe('Delete'); + expect(wrapper.findAllComponents(GlButton).at(0).text()).toBe('Replace'); + expect(wrapper.findAllComponents(GlButton).at(1).text()).toBe('Delete'); }); it('triggers the UploadBlobModal from the replace button', () => { @@ -97,14 +97,14 @@ describe('BlobButtonGroup component', () => { findReplaceButton().trigger('click'); expect(findUploadBlobModal().vm.show).not.toHaveBeenCalled(); - expect(wrapper.emitted().fork).toBeTruthy(); + expect(wrapper.emitted().fork).toHaveLength(1); }); it('does not trigger the DeleteBlobModal from the delete button', () => { findDeleteButton().trigger('click'); expect(findDeleteBlobModal().vm.show).not.toHaveBeenCalled(); - expect(wrapper.emitted().fork).toBeTruthy(); + expect(wrapper.emitted().fork).toHaveLength(1); }); }); }); diff --git a/spec/frontend/repository/components/blob_content_viewer_spec.js b/spec/frontend/repository/components/blob_content_viewer_spec.js index 0f7cf4e61b2..6ece72c41bb 100644 --- a/spec/frontend/repository/components/blob_content_viewer_spec.js +++ b/spec/frontend/repository/components/blob_content_viewer_spec.js @@ -17,7 +17,8 @@ import { loadViewer } from '~/repository/components/blob_viewers'; import DownloadViewer from '~/repository/components/blob_viewers/download_viewer.vue'; import EmptyViewer from '~/repository/components/blob_viewers/empty_viewer.vue'; import SourceViewer from '~/vue_shared/components/source_viewer/source_viewer.vue'; -import blobInfoQuery from '~/repository/queries/blob_info.query.graphql'; +import blobInfoQuery from 'shared_queries/repository/blob_info.query.graphql'; +import projectInfoQuery from '~/repository/queries/project_info.query.graphql'; import userInfoQuery from '~/repository/queries/user_info.query.graphql'; import applicationInfoQuery from '~/repository/queries/application_info.query.graphql'; import CodeIntelligence from '~/code_navigation/components/app.vue'; @@ -45,8 +46,9 @@ jest.mock('~/lib/utils/common_utils'); jest.mock('~/blob/line_highlighter'); let wrapper; -let mockResolver; +let blobInfoMockResolver; let userInfoMockResolver; +let projectInfoMockResolver; let applicationInfoMockResolver; const mockAxios = new MockAdapter(axios); @@ -74,22 +76,40 @@ const createComponent = async (mockData = {}, mountFn = shallowMount, mockRoute highlightJs = true, } = mockData; - const project = { + const blobInfo = { ...projectMock, + repository: { + empty, + blobs: { nodes: [blob] }, + }, + }; + + const projectInfo = { + __typename: 'Project', + id: '123', userPermissions: { pushCode, forkProject, downloadCode, createMergeRequestIn, }, - repository: { - empty, - blobs: { nodes: [blob] }, + pathLocks: { + nodes: [ + { + id: 'test', + path: 'locked_file.js', + user: { id: '123', username: 'root' }, + }, + ], }, }; - mockResolver = jest.fn().mockResolvedValue({ - data: { isBinary, project }, + projectInfoMockResolver = jest.fn().mockResolvedValue({ + data: { project: projectInfo }, + }); + + blobInfoMockResolver = jest.fn().mockResolvedValue({ + data: { isBinary, project: blobInfo }, }); userInfoMockResolver = jest.fn().mockResolvedValue({ @@ -101,8 +121,9 @@ const createComponent = async (mockData = {}, mountFn = shallowMount, mockRoute }); const fakeApollo = createMockApollo([ - [blobInfoQuery, mockResolver], + [blobInfoQuery, blobInfoMockResolver], [userInfoQuery, userInfoMockResolver], + [projectInfoQuery, projectInfoMockResolver], [applicationInfoQuery, applicationInfoMockResolver], ]); @@ -129,7 +150,7 @@ const createComponent = async (mockData = {}, mountFn = shallowMount, mockRoute // setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details // eslint-disable-next-line no-restricted-syntax - wrapper.setData({ project, isBinary }); + wrapper.setData({ project: blobInfo, isBinary }); await waitForPromises(); }; @@ -504,14 +525,16 @@ describe('Blob content viewer component', () => { async ({ highlightJs, shouldFetchRawText }) => { await createComponent({ highlightJs }); - expect(mockResolver).toHaveBeenCalledWith(expect.objectContaining({ shouldFetchRawText })); + expect(blobInfoMockResolver).toHaveBeenCalledWith( + expect.objectContaining({ shouldFetchRawText }), + ); }, ); it('is called with originalBranch value if the prop has a value', async () => { await createComponent({ inject: { originalBranch: 'some-branch' } }); - expect(mockResolver).toHaveBeenCalledWith( + expect(blobInfoMockResolver).toHaveBeenCalledWith( expect.objectContaining({ ref: 'some-branch', }), @@ -521,7 +544,7 @@ describe('Blob content viewer component', () => { it('is called with ref value if the originalBranch prop has no value', async () => { await createComponent(); - expect(mockResolver).toHaveBeenCalledWith( + expect(blobInfoMockResolver).toHaveBeenCalledWith( expect.objectContaining({ ref: 'default-ref', }), diff --git a/spec/frontend/repository/components/blob_viewers/csv_viewer_spec.js b/spec/frontend/repository/components/blob_viewers/csv_viewer_spec.js index 7d43e4e660b..c6b9737dde2 100644 --- a/spec/frontend/repository/components/blob_viewers/csv_viewer_spec.js +++ b/spec/frontend/repository/components/blob_viewers/csv_viewer_spec.js @@ -21,7 +21,7 @@ describe('CSV Viewer', () => { it('renders a Source Editor component', () => { createComponent(); expect(findCsvViewerComp().exists()).toBe(true); - expect(findCsvViewerComp().props('remoteFile')).toBeTruthy(); + expect(findCsvViewerComp().props('remoteFile')).toBe(true); expect(findCsvViewerComp().props('csv')).toBe(DEFAULT_BLOB_DATA.rawPath); }); }); diff --git a/spec/frontend/repository/components/breadcrumbs_spec.js b/spec/frontend/repository/components/breadcrumbs_spec.js index 40b32904589..c2f34f79f89 100644 --- a/spec/frontend/repository/components/breadcrumbs_spec.js +++ b/spec/frontend/repository/components/breadcrumbs_spec.js @@ -39,8 +39,8 @@ describe('Repository breadcrumbs component', () => { }); }; - const findUploadBlobModal = () => wrapper.find(UploadBlobModal); - const findNewDirectoryModal = () => wrapper.find(NewDirectoryModal); + const findUploadBlobModal = () => wrapper.findComponent(UploadBlobModal); + const findNewDirectoryModal = () => wrapper.findComponent(NewDirectoryModal); afterEach(() => { wrapper.destroy(); @@ -55,7 +55,7 @@ describe('Repository breadcrumbs component', () => { `('renders $linkCount links for path $path', ({ path, linkCount }) => { factory(path); - expect(wrapper.findAll(RouterLinkStub).length).toEqual(linkCount); + expect(wrapper.findAllComponents(RouterLinkStub).length).toEqual(linkCount); }); it.each` @@ -68,14 +68,14 @@ describe('Repository breadcrumbs component', () => { 'links to the correct router path when routeName is $routeName', ({ routeName, path, linkTo }) => { factory(path, {}, { name: routeName }); - expect(wrapper.findAll(RouterLinkStub).at(3).props('to')).toEqual(linkTo); + expect(wrapper.findAllComponents(RouterLinkStub).at(3).props('to')).toEqual(linkTo); }, ); it('escapes hash in directory path', () => { factory('app/assets/javascripts#'); - expect(wrapper.findAll(RouterLinkStub).at(3).props('to')).toEqual( + expect(wrapper.findAllComponents(RouterLinkStub).at(3).props('to')).toEqual( '/-/tree/app/assets/javascripts%23', ); }); @@ -83,7 +83,9 @@ describe('Repository breadcrumbs component', () => { it('renders last link as active', () => { factory('app/assets'); - expect(wrapper.findAll(RouterLinkStub).at(2).attributes('aria-current')).toEqual('page'); + expect(wrapper.findAllComponents(RouterLinkStub).at(2).attributes('aria-current')).toEqual( + 'page', + ); }); it('does not render add to tree dropdown when permissions are false', async () => { @@ -95,7 +97,7 @@ describe('Repository breadcrumbs component', () => { await nextTick(); - expect(wrapper.find(GlDropdown).exists()).toBe(false); + expect(wrapper.findComponent(GlDropdown).exists()).toBe(false); }); it.each` @@ -109,7 +111,7 @@ describe('Repository breadcrumbs component', () => { 'does render add to tree dropdown $isRendered when route is $routeName', ({ routeName, isRendered }) => { factory('app/assets/javascripts.js', { canCollaborate: true }, { name: routeName }); - expect(wrapper.find(GlDropdown).exists()).toBe(isRendered); + expect(wrapper.findComponent(GlDropdown).exists()).toBe(isRendered); }, ); @@ -122,7 +124,7 @@ describe('Repository breadcrumbs component', () => { await nextTick(); - expect(wrapper.find(GlDropdown).exists()).toBe(true); + expect(wrapper.findComponent(GlDropdown).exists()).toBe(true); }); describe('renders the upload blob modal', () => { diff --git a/spec/frontend/repository/components/delete_blob_modal_spec.js b/spec/frontend/repository/components/delete_blob_modal_spec.js index 785783b2e75..b5996816ad8 100644 --- a/spec/frontend/repository/components/delete_blob_modal_spec.js +++ b/spec/frontend/repository/components/delete_blob_modal_spec.js @@ -84,7 +84,7 @@ describe('DeleteBlobModal', () => { ${GlToggle} | ${'true'} | ${true} | ${initialProps.targetBranch} | ${initialProps.originalBranch} | ${true} ${GlToggle} | ${undefined} | ${true} | ${'same-branch'} | ${'same-branch'} | ${false} `( - 'has the correct form fields ', + 'has the correct form fields', ({ component, defaultValue, canPushCode, targetBranch, originalBranch, exist }) => { createComponent({ canPushCode, diff --git a/spec/frontend/repository/components/last_commit_spec.js b/spec/frontend/repository/components/last_commit_spec.js index 3783b34e33a..bf9528953b6 100644 --- a/spec/frontend/repository/components/last_commit_spec.js +++ b/spec/frontend/repository/components/last_commit_spec.js @@ -190,11 +190,16 @@ describe('Repository last commit component', () => { }); it('expands commit description when clicking expander', async () => { + expect(findCommitRowDescription().classes('d-block')).toBe(false); + expect(findTextExpander().classes('open')).toBe(false); + expect(findTextExpander().props('selected')).toBe(false); + findTextExpander().vm.$emit('click'); await nextTick(); - expect(findCommitRowDescription().isVisible()).toBe(true); - expect(findTextExpander().classes()).toContain('open'); + expect(findCommitRowDescription().classes('d-block')).toBe(true); + expect(findTextExpander().classes('open')).toBe(true); + expect(findTextExpander().props('selected')).toBe(true); }); }); diff --git a/spec/frontend/repository/components/new_directory_modal_spec.js b/spec/frontend/repository/components/new_directory_modal_spec.js index e1c50d63851..aaf751a9a8d 100644 --- a/spec/frontend/repository/components/new_directory_modal_spec.js +++ b/spec/frontend/repository/components/new_directory_modal_spec.js @@ -107,7 +107,7 @@ describe('NewDirectoryModal', () => { ${findMrToggle} | ${'true'} | ${true} | ${'new-target-branch'} | ${'master'} | ${true} ${findMrToggle} | ${'true'} | ${true} | ${'master'} | ${'master'} | ${true} `( - 'has the correct form fields ', + 'has the correct form fields', ({ component, defaultValue, canPushCode, targetBranch, originalBranch, exist }) => { createComponent({ canPushCode, diff --git a/spec/frontend/repository/components/preview/index_spec.js b/spec/frontend/repository/components/preview/index_spec.js index 0d9bfc62ed5..e4eba65795e 100644 --- a/spec/frontend/repository/components/preview/index_spec.js +++ b/spec/frontend/repository/components/preview/index_spec.js @@ -68,6 +68,6 @@ describe('Repository file preview component', () => { vm.setData({ loading: 1 }); await nextTick(); - expect(vm.find(GlLoadingIcon).exists()).toBe(true); + expect(vm.findComponent(GlLoadingIcon).exists()).toBe(true); }); }); diff --git a/spec/frontend/repository/components/table/index_spec.js b/spec/frontend/repository/components/table/index_spec.js index ff0371b5c07..697d2dcc7f5 100644 --- a/spec/frontend/repository/components/table/index_spec.js +++ b/spec/frontend/repository/components/table/index_spec.js @@ -38,6 +38,7 @@ const MOCK_BLOBS = [ const MOCK_COMMITS = [ { fileName: 'blob.md', + filePath: 'test_dir/blob.md', type: 'blob', commit: { message: 'Updated blob.md', @@ -45,6 +46,7 @@ const MOCK_COMMITS = [ }, { fileName: 'blob2.md', + filePath: 'test_dir/blob2.md', type: 'blob', commit: { message: 'Updated blob2.md', @@ -52,11 +54,20 @@ const MOCK_COMMITS = [ }, { fileName: 'blob3.md', + filePath: 'test_dir/blob3.md', type: 'blob', commit: { message: 'Updated blob3.md', }, }, + { + fileName: 'root_blob.md', + filePath: '/root_blob.md', + type: 'blob', + commit: { + message: 'Updated root_blob.md', + }, + }, ]; function factory({ path, isLoading = false, hasMore = true, entries = {}, commits = [] }) { @@ -77,6 +88,8 @@ function factory({ path, isLoading = false, hasMore = true, entries = {}, commit }); } +const findTableRows = () => vm.findAllComponents(TableRow); + describe('Repository table component', () => { afterEach(() => { vm.destroy(); @@ -108,14 +121,14 @@ describe('Repository table component', () => { it('renders table rows', () => { factory({ - path: '/', + path: 'test_dir', entries: { blobs: MOCK_BLOBS, }, commits: MOCK_COMMITS, }); - const rows = vm.findAll(TableRow); + const rows = findTableRows(); expect(rows.length).toEqual(3); expect(rows.at(2).attributes().mode).toEqual('120000'); @@ -123,6 +136,28 @@ describe('Repository table component', () => { expect(rows.at(2).props().commitInfo).toEqual(MOCK_COMMITS[2]); }); + it('renders correct commit info for blobs in the root', () => { + factory({ + path: '/', + entries: { + blobs: [ + { + id: '126abc', + sha: '126abc', + flatPath: 'root_blob.md', + name: 'root_blob.md', + type: 'blob', + webUrl: 'http://test.com', + mode: '120000', + }, + ], + }, + commits: MOCK_COMMITS, + }); + + expect(findTableRows().at(0).props().commitInfo).toEqual(MOCK_COMMITS[3]); + }); + describe('Show more button', () => { const showMoreButton = () => vm.find(GlButton); diff --git a/spec/frontend/repository/components/upload_blob_modal_spec.js b/spec/frontend/repository/components/upload_blob_modal_spec.js index bf024baa627..505ff7f3dd6 100644 --- a/spec/frontend/repository/components/upload_blob_modal_spec.js +++ b/spec/frontend/repository/components/upload_blob_modal_spec.js @@ -217,7 +217,7 @@ describe('UploadBlobModal', () => { createComponent(); }); - it('displays the default "Upload new file" modal title ', () => { + it('displays the default "Upload new file" modal title', () => { expect(findModal().props('title')).toBe('Upload new file'); }); diff --git a/spec/frontend/repository/log_tree_spec.js b/spec/frontend/repository/log_tree_spec.js index e3b4dcb8acc..c1309539b6d 100644 --- a/spec/frontend/repository/log_tree_spec.js +++ b/spec/frontend/repository/log_tree_spec.js @@ -30,7 +30,7 @@ describe('resolveCommit', () => { { fileName: 'index.js', filePath: '/app/assets/index.js' }, ]; - resolveCommit(commits, '', resolver); + resolveCommit(commits, '/', resolver); expect(resolver.resolve).toHaveBeenCalledWith({ fileName: 'index.js', @@ -107,14 +107,14 @@ describe('fetchLogsTree', () => { })); it('calls entry resolver', () => - fetchLogsTree(client, '', '0', resolver).then(() => { + fetchLogsTree(client, 'test', '0', resolver).then(() => { expect(resolver.resolve).toHaveBeenCalledWith( expect.objectContaining({ __typename: 'LogTreeCommit', commitPath: 'https://test.com', committedDate: '2019-01-01', fileName: 'index.js', - filePath: '/index.js', + filePath: 'test/index.js', message: 'testing message', sha: '123', }), @@ -122,7 +122,7 @@ describe('fetchLogsTree', () => { })); it('writes query to client', async () => { - await fetchLogsTree(client, '', '0', resolver); + await fetchLogsTree(client, '/', '0', resolver); expect(client.readQuery({ query: commitsQuery })).toEqual({ commits: [ expect.objectContaining({ diff --git a/spec/frontend/repository/mock_data.js b/spec/frontend/repository/mock_data.js index 4db295fe0b7..cda47a5b0a5 100644 --- a/spec/frontend/repository/mock_data.js +++ b/spec/frontend/repository/mock_data.js @@ -1,4 +1,5 @@ export const simpleViewerMock = { + __typename: 'RepositoryBlob', id: '1', name: 'some_file.js', size: 123, diff --git a/spec/frontend/repository/utils/commit_spec.js b/spec/frontend/repository/utils/commit_spec.js index b3dd5118308..65728e9cb24 100644 --- a/spec/frontend/repository/utils/commit_spec.js +++ b/spec/frontend/repository/utils/commit_spec.js @@ -15,7 +15,7 @@ const mockData = [ describe('normalizeData', () => { it('normalizes data into LogTreeCommit object', () => { - expect(normalizeData(mockData, '')).toEqual([ + expect(normalizeData(mockData, '/')).toEqual([ { sha: '123', message: 'testing message', |