diff options
Diffstat (limited to 'spec/frontend/snippets/components/show_spec.js')
-rw-r--r-- | spec/frontend/snippets/components/show_spec.js | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/spec/frontend/snippets/components/show_spec.js b/spec/frontend/snippets/components/show_spec.js index b5446e70028..8cccbb83d54 100644 --- a/spec/frontend/snippets/components/show_spec.js +++ b/spec/frontend/snippets/components/show_spec.js @@ -1,19 +1,27 @@ +import { GlLoadingIcon } from '@gitlab/ui'; +import { Blob, BinaryBlob } from 'jest/blob/components/mock_data'; +import { shallowMount } from '@vue/test-utils'; import SnippetApp from '~/snippets/components/show.vue'; import BlobEmbeddable from '~/blob/components/blob_embeddable.vue'; import SnippetHeader from '~/snippets/components/snippet_header.vue'; import SnippetTitle from '~/snippets/components/snippet_title.vue'; import SnippetBlob from '~/snippets/components/snippet_blob_view.vue'; -import { GlLoadingIcon } from '@gitlab/ui'; -import { Blob, BinaryBlob } from 'jest/blob/components/mock_data'; +import CloneDropdownButton from '~/vue_shared/components/clone_dropdown.vue'; -import { shallowMount } from '@vue/test-utils'; -import { SNIPPET_VISIBILITY_PUBLIC } from '~/snippets/constants'; +import { + SNIPPET_VISIBILITY_INTERNAL, + SNIPPET_VISIBILITY_PRIVATE, + SNIPPET_VISIBILITY_PUBLIC, +} from '~/snippets/constants'; describe('Snippet view app', () => { let wrapper; const defaultProps = { snippetGid: 'gid://gitlab/PersonalSnippet/42', }; + const webUrl = 'http://foo.bar'; + const dummyHTTPUrl = webUrl; + const dummySSHUrl = 'ssh://foo.bar'; function createComponent({ props = defaultProps, data = {}, loading = false } = {}) { const $apollo = { @@ -72,4 +80,47 @@ describe('Snippet view app', () => { expect(blobs.at(0).props('blob')).toEqual(Blob); expect(blobs.at(1).props('blob')).toEqual(BinaryBlob); }); + + 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} + `('does $condition blob-embeddable by default', ({ visibilityLevel, isRendered }) => { + createComponent({ + data: { + snippet: { + visibilityLevel, + webUrl, + }, + }, + }); + expect(wrapper.contains(BlobEmbeddable)).toBe(isRendered); + }); + }); + + 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); + }, + ); + }); }); |