Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/snippets')
-rw-r--r--spec/frontend/snippets/components/__snapshots__/snippet_description_edit_spec.js.snap10
-rw-r--r--spec/frontend/snippets/components/edit_spec.js85
-rw-r--r--spec/frontend/snippets/components/snippet_visibility_edit_spec.js25
3 files changed, 75 insertions, 45 deletions
diff --git a/spec/frontend/snippets/components/__snapshots__/snippet_description_edit_spec.js.snap b/spec/frontend/snippets/components/__snapshots__/snippet_description_edit_spec.js.snap
index 93684ed48ee..cef5f8cc528 100644
--- a/spec/frontend/snippets/components/__snapshots__/snippet_description_edit_spec.js.snap
+++ b/spec/frontend/snippets/components/__snapshots__/snippet_description_edit_spec.js.snap
@@ -52,9 +52,13 @@ exports[`Snippet Description Edit component rendering matches the snapshot 1`] =
<div
class="div-dropzone-hover"
>
- <i
- class="fa fa-paperclip div-dropzone-icon"
- />
+ <svg
+ class="div-dropzone-icon s24"
+ >
+ <use
+ xlink:href="undefined#paperclip"
+ />
+ </svg>
</div>
</div>
diff --git a/spec/frontend/snippets/components/edit_spec.js b/spec/frontend/snippets/components/edit_spec.js
index c1fad8cebe6..3521733ee5e 100644
--- a/spec/frontend/snippets/components/edit_spec.js
+++ b/spec/frontend/snippets/components/edit_spec.js
@@ -1,7 +1,9 @@
-import { ApolloMutation } from 'vue-apollo';
+import VueApollo, { ApolloMutation } from 'vue-apollo';
import { GlLoadingIcon } from '@gitlab/ui';
-import { shallowMount } from '@vue/test-utils';
+import { shallowMount, createLocalVue } from '@vue/test-utils';
import waitForPromises from 'helpers/wait_for_promises';
+import createMockApollo from 'jest/helpers/mock_apollo_helper';
+import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql';
import { deprecatedCreateFlash as Flash } from '~/flash';
import * as urlUtils from '~/lib/utils/url_utility';
import SnippetEditApp from '~/snippets/components/edit.vue';
@@ -10,7 +12,11 @@ import SnippetVisibilityEdit from '~/snippets/components/snippet_visibility_edit
import SnippetBlobActionsEdit from '~/snippets/components/snippet_blob_actions_edit.vue';
import TitleField from '~/vue_shared/components/form/title.vue';
import FormFooterActions from '~/vue_shared/components/form/form_footer_actions.vue';
-import { SNIPPET_VISIBILITY_PRIVATE } from '~/snippets/constants';
+import {
+ SNIPPET_VISIBILITY_PRIVATE,
+ SNIPPET_VISIBILITY_INTERNAL,
+ SNIPPET_VISIBILITY_PUBLIC,
+} from '~/snippets/constants';
import UpdateSnippetMutation from '~/snippets/mutations/updateSnippet.mutation.graphql';
import CreateSnippetMutation from '~/snippets/mutations/createSnippet.mutation.graphql';
import { testEntries } from '../test_utils';
@@ -47,8 +53,12 @@ const createTestSnippet = () => ({
describe('Snippet Edit app', () => {
let wrapper;
+ let fakeApollo;
const relativeUrlRoot = '/foo/';
const originalRelativeUrlRoot = gon.relative_url_root;
+ const GetSnippetQuerySpy = jest.fn().mockResolvedValue({
+ data: { snippets: { nodes: [createTestSnippet()] } },
+ });
const mutationTypes = {
RESOLVE: jest.fn().mockResolvedValue({
@@ -78,12 +88,10 @@ describe('Snippet Edit app', () => {
props = {},
loading = false,
mutationRes = mutationTypes.RESOLVE,
+ selectedLevel = SNIPPET_VISIBILITY_PRIVATE,
+ withApollo = false,
} = {}) {
- if (wrapper) {
- throw new Error('wrapper already exists');
- }
-
- wrapper = shallowMount(SnippetEditApp, {
+ let componentData = {
mocks: {
$apollo: {
queries: {
@@ -92,23 +100,35 @@ describe('Snippet Edit app', () => {
mutate: mutationRes,
},
},
+ };
+
+ if (withApollo) {
+ const localVue = createLocalVue();
+ localVue.use(VueApollo);
+
+ const requestHandlers = [[GetSnippetQuery, GetSnippetQuerySpy]];
+ fakeApollo = createMockApollo(requestHandlers);
+ componentData = {
+ localVue,
+ apolloProvider: fakeApollo,
+ };
+ }
+
+ wrapper = shallowMount(SnippetEditApp, {
+ ...componentData,
stubs: {
ApolloMutation,
FormFooterActions,
},
+ provide: {
+ selectedLevel,
+ },
propsData: {
snippetGid: 'gid://gitlab/PersonalSnippet/42',
markdownPreviewPath: 'http://preview.foo.bar',
markdownDocsPath: 'http://docs.foo.bar',
...props,
},
- data() {
- return {
- snippet: {
- visibilityLevel: SNIPPET_VISIBILITY_PRIVATE,
- },
- };
- },
});
}
@@ -152,16 +172,13 @@ describe('Snippet Edit app', () => {
if (nodes.length) {
wrapper.setData({
snippet: nodes[0],
+ newSnippet: false,
+ });
+ } else {
+ wrapper.setData({
+ newSnippet: true,
});
}
-
- wrapper.vm.onSnippetFetch({
- data: {
- snippets: {
- nodes,
- },
- },
- });
};
describe('rendering', () => {
@@ -228,6 +245,28 @@ describe('Snippet Edit app', () => {
});
describe('functionality', () => {
+ it('does not fetch snippet when create a new snippet', async () => {
+ createComponent({ props: { snippetGid: '' }, withApollo: true });
+
+ jest.runOnlyPendingTimers();
+ await wrapper.vm.$nextTick();
+
+ expect(GetSnippetQuerySpy).not.toHaveBeenCalled();
+ });
+
+ describe('default visibility', () => {
+ it.each([SNIPPET_VISIBILITY_PRIVATE, SNIPPET_VISIBILITY_INTERNAL, SNIPPET_VISIBILITY_PUBLIC])(
+ 'marks %s visibility by default',
+ async visibility => {
+ createComponent({
+ props: { snippetGid: '' },
+ selectedLevel: visibility,
+ });
+ expect(wrapper.vm.snippet.visibilityLevel).toEqual(visibility);
+ },
+ );
+ });
+
describe('form submission handling', () => {
it.each`
snippetArg | projectPath | uploadedFiles | input | mutation
diff --git a/spec/frontend/snippets/components/snippet_visibility_edit_spec.js b/spec/frontend/snippets/components/snippet_visibility_edit_spec.js
index 3919e4d7993..3151090f388 100644
--- a/spec/frontend/snippets/components/snippet_visibility_edit_spec.js
+++ b/spec/frontend/snippets/components/snippet_visibility_edit_spec.js
@@ -1,7 +1,6 @@
import { GlFormRadio, GlIcon, GlFormRadioGroup, GlLink } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils';
import SnippetVisibilityEdit from '~/snippets/components/snippet_visibility_edit.vue';
-import { defaultSnippetVisibilityLevels } from '~/snippets/utils/blob';
import {
SNIPPET_VISIBILITY,
SNIPPET_VISIBILITY_PRIVATE,
@@ -15,36 +14,25 @@ describe('Snippet Visibility Edit component', () => {
let wrapper;
const defaultHelpLink = '/foo/bar';
const defaultVisibilityLevel = 'private';
- const defaultVisibility = defaultSnippetVisibilityLevels([0, 10, 20]);
function createComponent({
propsData = {},
- visibilityLevels = defaultVisibility,
+ visibilityLevels = [0, 10, 20],
multipleLevelsRestricted = false,
deep = false,
} = {}) {
const method = deep ? mount : shallowMount;
- const $apollo = {
- queries: {
- defaultVisibility: {
- loading: false,
- },
- },
- };
wrapper = method.call(this, SnippetVisibilityEdit, {
- mock: { $apollo },
propsData: {
helpLink: defaultHelpLink,
isProjectSnippet: false,
value: defaultVisibilityLevel,
...propsData,
},
- data() {
- return {
- visibilityLevels,
- multipleLevelsRestricted,
- };
+ provide: {
+ visibilityLevels,
+ multipleLevelsRestricted,
},
});
}
@@ -108,7 +96,6 @@ describe('Snippet Visibility Edit component', () => {
it.each`
levels | resultOptions
- ${undefined} | ${[]}
${''} | ${[]}
${[]} | ${[]}
${[0]} | ${[RESULTING_OPTIONS[0]]}
@@ -117,7 +104,7 @@ describe('Snippet Visibility Edit component', () => {
${[0, 20]} | ${[RESULTING_OPTIONS[0], RESULTING_OPTIONS[20]]}
${[10, 20]} | ${[RESULTING_OPTIONS[10], RESULTING_OPTIONS[20]]}
`('renders correct visibility options for $levels', ({ levels, resultOptions }) => {
- createComponent({ visibilityLevels: defaultSnippetVisibilityLevels(levels), deep: true });
+ createComponent({ visibilityLevels: levels, deep: true });
expect(findRadiosData()).toEqual(resultOptions);
});
@@ -132,7 +119,7 @@ describe('Snippet Visibility Edit component', () => {
'renders correct information about restricted visibility levels for $levels',
({ levels, levelsRestricted, resultText }) => {
createComponent({
- visibilityLevels: defaultSnippetVisibilityLevels(levels),
+ visibilityLevels: levels,
multipleLevelsRestricted: levelsRestricted,
});
expect(findRestrictedInfo().text()).toBe(resultText);