Commit 03a57456 authored by Fernando Arias's avatar Fernando Arias Committed by Peter Hegman

Change corpus upload modal to use prop instead of graphQL

parent eea9ad53
...@@ -22,14 +22,13 @@ export default { ...@@ -22,14 +22,13 @@ export default {
newUpload: s__('CorpusManagement|New upload'), newUpload: s__('CorpusManagement|New upload'),
newCorpus: s__('CorpusMnagement|New corpus'), newCorpus: s__('CorpusMnagement|New corpus'),
}, },
inject: ['projectFullPath', 'corpusHelpPath'], inject: ['projectFullPath'],
apollo: { apollo: {
states: { states: {
query: getCorpusesQuery, query: getCorpusesQuery,
variables() { variables() {
return { return {
projectPath: this.projectFullPath, projectPath: this.projectFullPath,
...this.cursor,
}; };
}, },
update(data) { update(data) {
...@@ -99,7 +98,7 @@ export default { ...@@ -99,7 +98,7 @@ export default {
</div> </div>
<gl-button v-gl-modal-directive="$options.modal.modalId" class="gl-mr-5" variant="confirm"> <gl-button v-gl-modal-directive="$options.modal.modalId" class="gl-mr-5" variant="confirm">
{{ this.$options.i18n.newCorpus }} {{ $options.i18n.newCorpus }}
</gl-button> </gl-button>
<gl-modal <gl-modal
...@@ -111,7 +110,7 @@ export default { ...@@ -111,7 +110,7 @@ export default {
@primary="addCorpus" @primary="addCorpus"
@canceled="resetCorpus" @canceled="resetCorpus"
> >
<corpus-upload-form /> <corpus-upload-form :states="states" />
</gl-modal> </gl-modal>
</div> </div>
</template> </template>
...@@ -11,7 +11,6 @@ import { s__, __, sprintf } from '~/locale'; ...@@ -11,7 +11,6 @@ import { s__, __, sprintf } from '~/locale';
import { VALID_CORPUS_MIMETYPE } from '../constants'; import { VALID_CORPUS_MIMETYPE } from '../constants';
import resetCorpus from '../graphql/mutations/reset_corpus.mutation.graphql'; import resetCorpus from '../graphql/mutations/reset_corpus.mutation.graphql';
import uploadCorpus from '../graphql/mutations/upload_corpus.mutation.graphql'; import uploadCorpus from '../graphql/mutations/upload_corpus.mutation.graphql';
import getCorpusesQuery from '../graphql/queries/get_corpuses.query.graphql';
export default { export default {
components: { components: {
...@@ -23,6 +22,12 @@ export default { ...@@ -23,6 +22,12 @@ export default {
GlButton, GlButton,
}, },
inject: ['projectFullPath'], inject: ['projectFullPath'],
props: {
states: {
type: Object,
required: true,
},
},
i18n: { i18n: {
corpusName: s__('CorpusManagement|Corpus name'), corpusName: s__('CorpusManagement|Corpus name'),
uploadButtonText: __('Choose File...'), uploadButtonText: __('Choose File...'),
...@@ -30,22 +35,6 @@ export default { ...@@ -30,22 +35,6 @@ export default {
'CorpusManagement|New corpus needs to be a upload in *.zip format. Maximum 10GB', 'CorpusManagement|New corpus needs to be a upload in *.zip format. Maximum 10GB',
), ),
}, },
apollo: {
states: {
query: getCorpusesQuery,
variables() {
return {
projectPath: this.projectFullPath,
};
},
update(data) {
return data;
},
error() {
this.states = null;
},
},
},
data() { data() {
return { return {
attachmentName: '', attachmentName: '',
...@@ -68,7 +57,7 @@ export default { ...@@ -68,7 +57,7 @@ export default {
return this.states?.uploadState.isUploading; return this.states?.uploadState.isUploading;
}, },
isUploaded() { isUploaded() {
return this.states?.uploadState.progress === 100; return this.progress === 100;
}, },
showUploadButton() { showUploadButton() {
return this.hasAttachment && !this.isUploading && !this.isUploaded; return this.hasAttachment && !this.isUploading && !this.isUploaded;
...@@ -107,7 +96,6 @@ export default { ...@@ -107,7 +96,6 @@ export default {
this.$refs.fileUpload.click(); this.$refs.fileUpload.click();
}, },
beginFileUpload() { beginFileUpload() {
// const component = this;
// Simulate incrementing file upload progress // Simulate incrementing file upload progress
return this.$apollo return this.$apollo
.mutate({ .mutate({
...@@ -162,7 +150,7 @@ export default { ...@@ -162,7 +150,7 @@ export default {
:disabled="isUploading" :disabled="isUploading"
@click="openFileUpload" @click="openFileUpload"
> >
{{ this.$options.i18n.uploadButtonText }} {{ $options.i18n.uploadButtonText }}
</gl-button> </gl-button>
<span v-if="isShowingAttachmentName" class="gl-ml-3"> <span v-if="isShowingAttachmentName" class="gl-ml-3">
...@@ -186,7 +174,7 @@ export default { ...@@ -186,7 +174,7 @@ export default {
/> />
</gl-form-group> </gl-form-group>
<span>{{ this.$options.i18n.uploadMessage }}</span> <span>{{ $options.i18n.uploadMessage }}</span>
<gl-button <gl-button
v-if="showUploadButton" v-if="showUploadButton"
......
...@@ -37,7 +37,9 @@ exports[`Corpus Upload component renders header 1`] = ` ...@@ -37,7 +37,9 @@ exports[`Corpus Upload component renders header 1`] = `
title="New corpus" title="New corpus"
titletag="h4" titletag="h4"
> >
<corpus-upload-form-stub /> <corpus-upload-form-stub
states="[object Object]"
/>
</gl-modal-stub> </gl-modal-stub>
</div> </div>
`; `;
...@@ -2,39 +2,12 @@ import { createLocalVue, mount } from '@vue/test-utils'; ...@@ -2,39 +2,12 @@ import { createLocalVue, mount } from '@vue/test-utils';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import CorpusUploadForm from 'ee/security_configuration/corpus_management/components/corpus_upload_form.vue'; import CorpusUploadForm from 'ee/security_configuration/corpus_management/components/corpus_upload_form.vue';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
const TEST_PROJECT_FULL_PATH = '/namespace/project'; const TEST_PROJECT_FULL_PATH = '/namespace/project';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueApollo); localVue.use(VueApollo);
let mockTotalSize;
let mockData;
let mockIsUploading;
let mockProgress;
const mockResolver = {
Query: {
/* eslint-disable no-unused-vars */
mockedPackages(_, { projectPath }) {
return {
totalSize: mockTotalSize(),
data: mockData(),
__typename: 'MockedPackages',
};
},
/* eslint-disable no-unused-vars */
uploadState(_, { projectPath }) {
return {
isUploading: mockIsUploading(),
progress: mockProgress(),
__typename: 'UploadState',
};
},
},
};
describe('Corpus upload modal', () => { describe('Corpus upload modal', () => {
let wrapper; let wrapper;
...@@ -43,14 +16,11 @@ describe('Corpus upload modal', () => { ...@@ -43,14 +16,11 @@ describe('Corpus upload modal', () => {
const findUploadCorpus = () => wrapper.find('[data-testid="upload-corpus"]'); const findUploadCorpus = () => wrapper.find('[data-testid="upload-corpus"]');
const findUploadStatus = () => wrapper.find('[data-testid="upload-status"]'); const findUploadStatus = () => wrapper.find('[data-testid="upload-status"]');
const createMockApolloProvider = (resolverMock) => { const createComponent = (propsData, options = {}) => {
return createMockApollo([], resolverMock);
};
const createComponent = (resolverMock, options = {}) => {
wrapper = mount(CorpusUploadForm, { wrapper = mount(CorpusUploadForm, {
localVue, localVue,
apolloProvider: createMockApolloProvider(resolverMock), propsData,
apolloProvider: createMockApollo(),
provide: { provide: {
projectFullPath: TEST_PROJECT_FULL_PATH, projectFullPath: TEST_PROJECT_FULL_PATH,
}, },
...@@ -58,13 +28,6 @@ describe('Corpus upload modal', () => { ...@@ -58,13 +28,6 @@ describe('Corpus upload modal', () => {
}); });
}; };
beforeEach(() => {
mockTotalSize = jest.fn();
mockData = jest.fn();
mockIsUploading = jest.fn();
mockProgress = jest.fn();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -81,12 +44,20 @@ describe('Corpus upload modal', () => { ...@@ -81,12 +44,20 @@ describe('Corpus upload modal', () => {
}; };
}; };
mockTotalSize.mockResolvedValue(0); const props = {
mockData.mockResolvedValue([]); states: {
mockIsUploading.mockResolvedValue(false); mockedPackages: {
mockProgress.mockResolvedValue(0); totalSize: 0,
data: [],
},
uploadState: {
isUploading: false,
progress: 0,
},
},
};
createComponent(mockResolver, { data }); createComponent(props, { data });
}); });
it('shows empty name field', () => { it('shows empty name field', () => {
...@@ -120,12 +91,20 @@ describe('Corpus upload modal', () => { ...@@ -120,12 +91,20 @@ describe('Corpus upload modal', () => {
}; };
}; };
mockTotalSize.mockResolvedValue(0); const props = {
mockData.mockResolvedValue([]); states: {
mockIsUploading.mockResolvedValue(false); mockedPackages: {
mockProgress.mockResolvedValue(0); totalSize: 0,
data: [],
},
uploadState: {
isUploading: false,
progress: 0,
},
},
};
createComponent(mockResolver, { data }); createComponent(props, { data });
}); });
it('shows name field', () => { it('shows name field', () => {
...@@ -149,7 +128,7 @@ describe('Corpus upload modal', () => { ...@@ -149,7 +128,7 @@ describe('Corpus upload modal', () => {
const attachmentName = 'corpus.zip'; const attachmentName = 'corpus.zip';
const corpusName = 'User entered name'; const corpusName = 'User entered name';
beforeEach(async () => { beforeEach(() => {
const data = () => { const data = () => {
return { return {
attachmentName, attachmentName,
...@@ -159,14 +138,20 @@ describe('Corpus upload modal', () => { ...@@ -159,14 +138,20 @@ describe('Corpus upload modal', () => {
}; };
}; };
mockTotalSize.mockResolvedValue(0); const props = {
mockData.mockResolvedValue([]); states: {
mockIsUploading.mockResolvedValue(true); mockedPackages: {
mockProgress.mockResolvedValue(25); totalSize: 0,
data: [],
createComponent(mockResolver, { data }); },
uploadState: {
isUploading: true,
progress: 25,
},
},
};
await waitForPromises(); createComponent(props, { data });
}); });
it('shows name field', () => { it('shows name field', () => {
...@@ -192,7 +177,7 @@ describe('Corpus upload modal', () => { ...@@ -192,7 +177,7 @@ describe('Corpus upload modal', () => {
const attachmentName = 'corpus.zip'; const attachmentName = 'corpus.zip';
const corpusName = 'User entered name'; const corpusName = 'User entered name';
beforeEach(async () => { beforeEach(() => {
const data = () => { const data = () => {
return { return {
attachmentName, attachmentName,
...@@ -202,14 +187,20 @@ describe('Corpus upload modal', () => { ...@@ -202,14 +187,20 @@ describe('Corpus upload modal', () => {
}; };
}; };
mockTotalSize.mockResolvedValue(0); const props = {
mockData.mockResolvedValue([]); states: {
mockIsUploading.mockResolvedValue(false); mockedPackages: {
mockProgress.mockResolvedValue(100); totalSize: 0,
data: [],
createComponent(mockResolver, { data }); },
uploadState: {
isUploading: false,
progress: 100,
},
},
};
await waitForPromises(); createComponent(props, { data });
}); });
it('shows name field', () => { it('shows name field', () => {
......
...@@ -3,7 +3,6 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,7 +3,6 @@ import { shallowMount } from '@vue/test-utils';
import CorpusUpload from 'ee/security_configuration/corpus_management/components/corpus_upload.vue'; import CorpusUpload from 'ee/security_configuration/corpus_management/components/corpus_upload.vue';
const TEST_PROJECT_FULL_PATH = '/namespace/project'; const TEST_PROJECT_FULL_PATH = '/namespace/project';
const TEST_CORPUS_HELP_PATH = '/docs/corpus-management';
describe('Corpus Upload', () => { describe('Corpus Upload', () => {
let wrapper; let wrapper;
...@@ -12,9 +11,15 @@ describe('Corpus Upload', () => { ...@@ -12,9 +11,15 @@ describe('Corpus Upload', () => {
const defaultProps = { totalSize: 4e8 }; const defaultProps = { totalSize: 4e8 };
wrapper = mountFn(CorpusUpload, { wrapper = mountFn(CorpusUpload, {
propsData: defaultProps, propsData: defaultProps,
mocks: {
states: {
uploadState: {
progress: 0,
},
},
},
provide: { provide: {
projectFullPath: TEST_PROJECT_FULL_PATH, projectFullPath: TEST_PROJECT_FULL_PATH,
corpusHelpPath: TEST_CORPUS_HELP_PATH,
}, },
...options, ...options,
}); });
......
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