2020-08-17 17:09:56 -04:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import { Blob, BinaryBlob } from 'jest/blob/components/mock_data';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-03-24 11:08:44 -04:00
|
|
|
import SnippetApp from '~/snippets/components/show.vue';
|
2020-08-25 17:10:30 -04:00
|
|
|
import EmbedDropdown from '~/snippets/components/embed_dropdown.vue';
|
2019-12-17 13:07:48 -05:00
|
|
|
import SnippetHeader from '~/snippets/components/snippet_header.vue';
|
2020-01-31 10:08:42 -05:00
|
|
|
import SnippetTitle from '~/snippets/components/snippet_title.vue';
|
|
|
|
import SnippetBlob from '~/snippets/components/snippet_blob_view.vue';
|
2020-07-24 08:09:34 -04:00
|
|
|
import CloneDropdownButton from '~/vue_shared/components/clone_dropdown.vue';
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2020-07-24 08:09:34 -04:00
|
|
|
import {
|
|
|
|
SNIPPET_VISIBILITY_INTERNAL,
|
|
|
|
SNIPPET_VISIBILITY_PRIVATE,
|
|
|
|
SNIPPET_VISIBILITY_PUBLIC,
|
|
|
|
} from '~/snippets/constants';
|
2019-12-13 13:08:06 -05:00
|
|
|
|
|
|
|
describe('Snippet view app', () => {
|
|
|
|
let wrapper;
|
|
|
|
const defaultProps = {
|
2019-12-17 13:07:48 -05:00
|
|
|
snippetGid: 'gid://gitlab/PersonalSnippet/42',
|
2019-12-13 13:08:06 -05:00
|
|
|
};
|
2020-07-24 08:09:34 -04:00
|
|
|
const webUrl = 'http://foo.bar';
|
|
|
|
const dummyHTTPUrl = webUrl;
|
|
|
|
const dummySSHUrl = 'ssh://foo.bar';
|
2019-12-13 13:08:06 -05:00
|
|
|
|
2020-06-30 20:09:02 -04:00
|
|
|
function createComponent({ props = defaultProps, data = {}, loading = false } = {}) {
|
2019-12-13 13:08:06 -05:00
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
2019-12-17 13:07:48 -05:00
|
|
|
snippet: {
|
|
|
|
loading,
|
|
|
|
},
|
2019-12-13 13:08:06 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper = shallowMount(SnippetApp, {
|
|
|
|
mocks: { $apollo },
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
2020-06-30 20:09:02 -04:00
|
|
|
data() {
|
|
|
|
return data;
|
|
|
|
},
|
2019-12-13 13:08:06 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2019-12-17 13:07:48 -05:00
|
|
|
it('renders loader while the query is in flight', () => {
|
|
|
|
createComponent({ loading: true });
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-06-30 20:09:02 -04:00
|
|
|
it('renders all simple components after the query is finished', () => {
|
2019-12-13 13:08:06 -05:00
|
|
|
createComponent();
|
2019-12-17 13:07:48 -05:00
|
|
|
expect(wrapper.find(SnippetHeader).exists()).toBe(true);
|
2020-01-31 10:08:42 -05:00
|
|
|
expect(wrapper.find(SnippetTitle).exists()).toBe(true);
|
2020-06-30 20:09:02 -04:00
|
|
|
});
|
|
|
|
|
2020-08-25 17:10:30 -04:00
|
|
|
it('renders embed dropdown component if visibility allows', () => {
|
2020-06-30 20:09:02 -04:00
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
visibilityLevel: SNIPPET_VISIBILITY_PUBLIC,
|
|
|
|
webUrl: 'http://foo.bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-08-25 17:10:30 -04:00
|
|
|
expect(wrapper.contains(EmbedDropdown)).toBe(true);
|
2020-06-30 20:09:02 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correct snippet-blob components', () => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
blobs: [Blob, BinaryBlob],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const blobs = wrapper.findAll(SnippetBlob);
|
|
|
|
expect(blobs.length).toBe(2);
|
|
|
|
expect(blobs.at(0).props('blob')).toEqual(Blob);
|
|
|
|
expect(blobs.at(1).props('blob')).toEqual(BinaryBlob);
|
2019-12-13 13:08:06 -05:00
|
|
|
});
|
2020-07-24 08:09:34 -04:00
|
|
|
|
|
|
|
describe('Embed dropdown rendering', () => {
|
|
|
|
it.each`
|
|
|
|
visibilityLevel | condition | isRendered
|
|
|
|
${SNIPPET_VISIBILITY_INTERNAL} | ${'not render'} | ${false}
|
|
|
|
${SNIPPET_VISIBILITY_PRIVATE} | ${'not render'} | ${false}
|
|
|
|
${'foo'} | ${'not render'} | ${false}
|
|
|
|
${SNIPPET_VISIBILITY_PUBLIC} | ${'render'} | ${true}
|
2020-08-25 17:10:30 -04:00
|
|
|
`('does $condition embed-dropdown by default', ({ visibilityLevel, isRendered }) => {
|
2020-07-24 08:09:34 -04:00
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
visibilityLevel,
|
|
|
|
webUrl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-08-25 17:10:30 -04:00
|
|
|
expect(wrapper.contains(EmbedDropdown)).toBe(isRendered);
|
2020-07-24 08:09:34 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Clone button rendering', () => {
|
|
|
|
it.each`
|
|
|
|
httpUrlToRepo | sshUrlToRepo | shouldRender | isRendered
|
|
|
|
${null} | ${null} | ${'Should not'} | ${false}
|
|
|
|
${null} | ${dummySSHUrl} | ${'Should'} | ${true}
|
|
|
|
${dummyHTTPUrl} | ${null} | ${'Should'} | ${true}
|
|
|
|
${dummyHTTPUrl} | ${dummySSHUrl} | ${'Should'} | ${true}
|
|
|
|
`(
|
|
|
|
'$shouldRender render "Clone" button when `httpUrlToRepo` is $httpUrlToRepo and `sshUrlToRepo` is $sshUrlToRepo',
|
|
|
|
({ httpUrlToRepo, sshUrlToRepo, isRendered }) => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
sshUrlToRepo,
|
|
|
|
httpUrlToRepo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.contains(CloneDropdownButton)).toBe(isRendered);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2019-12-13 13:08:06 -05:00
|
|
|
});
|