Commit 58f1cb7e authored by Jacques Erasmus's avatar Jacques Erasmus Committed by jerasmus

Add ability to view blobs accross forks

Added ref support to blin info query
parent f6995ca5
...@@ -8,6 +8,7 @@ import createFlash from '~/flash'; ...@@ -8,6 +8,7 @@ import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { isLoggedIn } from '~/lib/utils/common_utils'; import { isLoggedIn } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import getRefMixin from '../mixins/get_ref';
import blobInfoQuery from '../queries/blob_info.query.graphql'; import blobInfoQuery from '../queries/blob_info.query.graphql';
import BlobButtonGroup from './blob_button_group.vue'; import BlobButtonGroup from './blob_button_group.vue';
import BlobEdit from './blob_edit.vue'; import BlobEdit from './blob_edit.vue';
...@@ -21,6 +22,12 @@ export default { ...@@ -21,6 +22,12 @@ export default {
BlobContent, BlobContent,
GlLoadingIcon, GlLoadingIcon,
}, },
mixins: [getRefMixin],
inject: {
originalBranch: {
default: '',
},
},
apollo: { apollo: {
project: { project: {
query: blobInfoQuery, query: blobInfoQuery,
...@@ -28,6 +35,7 @@ export default { ...@@ -28,6 +35,7 @@ export default {
return { return {
projectPath: this.projectPath, projectPath: this.projectPath,
filePath: this.path, filePath: this.path,
ref: this.originalBranch || this.ref,
}; };
}, },
result() { result() {
......
query getBlobInfo($projectPath: ID!, $filePath: String!) { query getBlobInfo($projectPath: ID!, $filePath: String!, $ref: String!) {
project(fullPath: $projectPath) { project(fullPath: $projectPath) {
userPermissions { userPermissions {
pushCode pushCode
} }
repository { repository {
empty empty
blobs(paths: [$filePath]) { blobs(paths: [$filePath], ref: $ref) {
nodes { nodes {
webPath webPath
name name
......
...@@ -20,6 +20,8 @@ import blobInfoQuery from '~/repository/queries/blob_info.query.graphql'; ...@@ -20,6 +20,8 @@ import blobInfoQuery from '~/repository/queries/blob_info.query.graphql';
jest.mock('~/repository/components/blob_viewers'); jest.mock('~/repository/components/blob_viewers');
let wrapper; let wrapper;
let mockResolver;
const simpleMockData = { const simpleMockData = {
name: 'some_file.js', name: 'some_file.js',
size: 123, size: 123,
...@@ -71,14 +73,14 @@ const projectMockData = { ...@@ -71,14 +73,14 @@ const projectMockData = {
const localVue = createLocalVue(); const localVue = createLocalVue();
const mockAxios = new MockAdapter(axios); const mockAxios = new MockAdapter(axios);
const createComponentWithApollo = (mockData = {}) => { const createComponentWithApollo = (mockData = {}, inject = {}) => {
localVue.use(VueApollo); localVue.use(VueApollo);
const defaultPushCode = projectMockData.userPermissions.pushCode; const defaultPushCode = projectMockData.userPermissions.pushCode;
const defaultEmptyRepo = projectMockData.repository.empty; const defaultEmptyRepo = projectMockData.repository.empty;
const { blobs, emptyRepo = defaultEmptyRepo, canPushCode = defaultPushCode } = mockData; const { blobs, emptyRepo = defaultEmptyRepo, canPushCode = defaultPushCode } = mockData;
const mockResolver = jest.fn().mockResolvedValue({ mockResolver = jest.fn().mockResolvedValue({
data: { data: {
project: { project: {
userPermissions: { pushCode: canPushCode }, userPermissions: { pushCode: canPushCode },
...@@ -101,6 +103,14 @@ const createComponentWithApollo = (mockData = {}) => { ...@@ -101,6 +103,14 @@ const createComponentWithApollo = (mockData = {}) => {
path: 'some_file.js', path: 'some_file.js',
projectPath: 'some/path', projectPath: 'some/path',
}, },
mixins: [
{
data: () => ({ ref: 'default-ref' }),
},
],
provide: {
...inject,
},
}); });
}; };
...@@ -119,6 +129,7 @@ const createFactory = (mountFn) => ( ...@@ -119,6 +129,7 @@ const createFactory = (mountFn) => (
queries: { queries: {
project: { project: {
loading, loading,
refetch: jest.fn(),
}, },
}, },
}, },
...@@ -382,4 +393,32 @@ describe('Blob content viewer component', () => { ...@@ -382,4 +393,32 @@ describe('Blob content viewer component', () => {
}); });
}); });
}); });
describe('blob info query', () => {
it('is called with originalBranch value if the prop has a value', async () => {
const inject = { originalBranch: 'some-branch' };
createComponentWithApollo({ blobs: simpleMockData }, inject);
await waitForPromises();
expect(mockResolver).toHaveBeenCalledWith(
expect.objectContaining({
ref: 'some-branch',
}),
);
});
it('is called with ref value if the originalBranch prop has no value', async () => {
const inject = { originalBranch: null };
createComponentWithApollo({ blobs: simpleMockData }, inject);
await waitForPromises();
expect(mockResolver).toHaveBeenCalledWith(
expect.objectContaining({
ref: 'default-ref',
}),
);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment