2022-02-27 12:50:16 +05:30
|
|
|
import { GlLoadingIcon, GlAlert } from '@gitlab/ui';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { Blob, BinaryBlob } from 'jest/blob/components/mock_data';
|
2020-11-24 15:15:51 +05:30
|
|
|
import EmbedDropdown from '~/snippets/components/embed_dropdown.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import SnippetApp from '~/snippets/components/show.vue';
|
|
|
|
import SnippetBlob from '~/snippets/components/snippet_blob_view.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
import SnippetHeader from '~/snippets/components/snippet_header.vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
import SnippetTitle from '~/snippets/components/snippet_title.vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import {
|
|
|
|
SNIPPET_VISIBILITY_INTERNAL,
|
|
|
|
SNIPPET_VISIBILITY_PRIVATE,
|
|
|
|
SNIPPET_VISIBILITY_PUBLIC,
|
|
|
|
} from '~/snippets/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import CloneDropdownButton from '~/vue_shared/components/clone_dropdown.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe('Snippet view app', () => {
|
|
|
|
let wrapper;
|
|
|
|
const defaultProps = {
|
|
|
|
snippetGid: 'gid://gitlab/PersonalSnippet/42',
|
|
|
|
};
|
2020-10-24 23:57:45 +05:30
|
|
|
const webUrl = 'http://foo.bar';
|
|
|
|
const dummyHTTPUrl = webUrl;
|
|
|
|
const dummySSHUrl = 'ssh://foo.bar';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
function createComponent({ props = defaultProps, data = {}, loading = false } = {}) {
|
2020-01-01 13:55:28 +05:30
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
|
|
|
snippet: {
|
|
|
|
loading,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper = shallowMount(SnippetApp, {
|
|
|
|
mocks: { $apollo },
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
data() {
|
|
|
|
return data;
|
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
}
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
|
|
|
const findEmbedDropdown = () => wrapper.findComponent(EmbedDropdown);
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loader while the query is in flight', () => {
|
|
|
|
createComponent({ loading: true });
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it('renders all simple components required after the query is finished', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent();
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(wrapper.findComponent(SnippetHeader).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(SnippetTitle).exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('renders embed dropdown component if visibility allows', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
visibilityLevel: SNIPPET_VISIBILITY_PUBLIC,
|
|
|
|
webUrl: 'http://foo.bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(findEmbedDropdown().exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correct snippet-blob components', () => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
2021-10-27 15:23:28 +05:30
|
|
|
snippet: {
|
|
|
|
blobs: [Blob, BinaryBlob],
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
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);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
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-11-24 15:15:51 +05:30
|
|
|
`('does $condition embed-dropdown by default', ({ visibilityLevel, isRendered }) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
visibilityLevel,
|
|
|
|
webUrl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(findEmbedDropdown().exists()).toBe(isRendered);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-02-27 12:50:16 +05:30
|
|
|
describe('hasUnretrievableBlobs alert rendering', () => {
|
|
|
|
it.each`
|
|
|
|
hasUnretrievableBlobs | condition | isRendered
|
|
|
|
${false} | ${'not render'} | ${false}
|
|
|
|
${true} | ${'render'} | ${true}
|
|
|
|
`('does $condition gl-alert by default', ({ hasUnretrievableBlobs, isRendered }) => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
hasUnretrievableBlobs,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findComponent(GlAlert).exists()).toBe(isRendered);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(wrapper.findComponent(CloneDropdownButton).exists()).toBe(isRendered);
|
2020-10-24 23:57:45 +05:30
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|