debian-mirror-gitlab/spec/frontend/snippets/components/show_spec.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-22 19:07:51 +05:30
import SnippetApp from '~/snippets/components/show.vue';
2020-07-28 23:09:34 +05:30
import BlobEmbeddable from '~/blob/components/blob_embeddable.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';
import SnippetBlob from '~/snippets/components/snippet_blob_view.vue';
2020-01-01 13:55:28 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-07-28 23:09:34 +05:30
import { Blob, BinaryBlob } from 'jest/blob/components/mock_data';
2020-01-01 13:55:28 +05:30
2020-03-13 15:44:24 +05:30
import { shallowMount } from '@vue/test-utils';
2020-07-28 23:09:34 +05:30
import { SNIPPET_VISIBILITY_PUBLIC } from '~/snippets/constants';
2020-01-01 13:55:28 +05:30
describe('Snippet view app', () => {
let wrapper;
const defaultProps = {
snippetGid: 'gid://gitlab/PersonalSnippet/42',
};
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
});
}
afterEach(() => {
wrapper.destroy();
});
it('renders loader while the query is in flight', () => {
createComponent({ loading: true });
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
});
2020-07-28 23:09:34 +05:30
it('renders all simple components after the query is finished', () => {
2020-01-01 13:55:28 +05:30
createComponent();
expect(wrapper.find(SnippetHeader).exists()).toBe(true);
2020-03-13 15:44:24 +05:30
expect(wrapper.find(SnippetTitle).exists()).toBe(true);
2020-07-28 23:09:34 +05:30
});
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);
2020-01-01 13:55:28 +05:30
});
});