2020-03-24 15:08:44 +00:00
|
|
|
import SnippetApp from '~/snippets/components/show.vue';
|
2020-07-01 00:09:02 +00:00
|
|
|
import BlobEmbeddable from '~/blob/components/blob_embeddable.vue';
|
2019-12-17 18:07:48 +00:00
|
|
|
import SnippetHeader from '~/snippets/components/snippet_header.vue';
|
2020-01-31 15:08:42 +00:00
|
|
|
import SnippetTitle from '~/snippets/components/snippet_title.vue';
|
|
|
|
import SnippetBlob from '~/snippets/components/snippet_blob_view.vue';
|
2019-12-17 18:07:48 +00:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2020-07-01 00:09:02 +00:00
|
|
|
import { Blob, BinaryBlob } from 'jest/blob/components/mock_data';
|
2019-12-17 18:07:48 +00:00
|
|
|
|
2020-01-08 15:08:01 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-07-01 00:09:02 +00:00
|
|
|
import { SNIPPET_VISIBILITY_PUBLIC } from '~/snippets/constants';
|
2019-12-13 18:08:06 +00:00
|
|
|
|
|
|
|
describe('Snippet view app', () => {
|
|
|
|
let wrapper;
|
|
|
|
const defaultProps = {
|
2019-12-17 18:07:48 +00:00
|
|
|
snippetGid: 'gid://gitlab/PersonalSnippet/42',
|
2019-12-13 18:08:06 +00:00
|
|
|
};
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
function createComponent({ props = defaultProps, data = {}, loading = false } = {}) {
|
2019-12-13 18:08:06 +00:00
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
2019-12-17 18:07:48 +00:00
|
|
|
snippet: {
|
|
|
|
loading,
|
|
|
|
},
|
2019-12-13 18:08:06 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper = shallowMount(SnippetApp, {
|
|
|
|
mocks: { $apollo },
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
2020-07-01 00:09:02 +00:00
|
|
|
data() {
|
|
|
|
return data;
|
|
|
|
},
|
2019-12-13 18:08:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2019-12-17 18:07:48 +00:00
|
|
|
it('renders loader while the query is in flight', () => {
|
|
|
|
createComponent({ loading: true });
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-07-01 00:09:02 +00:00
|
|
|
it('renders all simple components after the query is finished', () => {
|
2019-12-13 18:08:06 +00:00
|
|
|
createComponent();
|
2019-12-17 18:07:48 +00:00
|
|
|
expect(wrapper.find(SnippetHeader).exists()).toBe(true);
|
2020-01-31 15:08:42 +00:00
|
|
|
expect(wrapper.find(SnippetTitle).exists()).toBe(true);
|
2020-07-01 00:09:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders embeddable component if visibility allows', () => {
|
|
|
|
createComponent({
|
|
|
|
data: {
|
|
|
|
snippet: {
|
|
|
|
visibilityLevel: SNIPPET_VISIBILITY_PUBLIC,
|
|
|
|
webUrl: 'http://foo.bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.contains(BlobEmbeddable)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
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 18:08:06 +00:00
|
|
|
});
|
|
|
|
});
|