diff options
Diffstat (limited to 'spec/frontend/snippets/components/snippet_blob_edit_spec.js')
-rw-r--r-- | spec/frontend/snippets/components/snippet_blob_edit_spec.js | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/spec/frontend/snippets/components/snippet_blob_edit_spec.js b/spec/frontend/snippets/components/snippet_blob_edit_spec.js index 334fe7196a4..75688e61892 100644 --- a/spec/frontend/snippets/components/snippet_blob_edit_spec.js +++ b/spec/frontend/snippets/components/snippet_blob_edit_spec.js @@ -1,6 +1,7 @@ import SnippetBlobEdit from '~/snippets/components/snippet_blob_edit.vue'; import BlobHeaderEdit from '~/blob/components/blob_edit_header.vue'; import BlobContentEdit from '~/blob/components/blob_edit_content.vue'; +import { GlLoadingIcon } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue'; @@ -13,11 +14,13 @@ describe('Snippet Blob Edit component', () => { const findHeader = () => wrapper.find(BlobHeaderEdit); const findContent = () => wrapper.find(BlobContentEdit); - function createComponent() { + function createComponent(props = {}) { wrapper = shallowMount(SnippetBlobEdit, { propsData: { value, fileName, + isLoading: false, + ...props, }, }); } @@ -39,9 +42,23 @@ describe('Snippet Blob Edit component', () => { expect(findHeader().exists()).toBe(true); expect(findContent().exists()).toBe(true); }); + + it('renders loader if isLoading equals true', () => { + createComponent({ isLoading: true }); + expect(wrapper.contains(GlLoadingIcon)).toBe(true); + expect(findContent().exists()).toBe(false); + }); }); describe('functionality', () => { + it('does not fail without content', () => { + const spy = jest.spyOn(global.console, 'error'); + createComponent({ value: undefined }); + + expect(spy).not.toHaveBeenCalled(); + expect(findContent().exists()).toBe(true); + }); + it('emits "name-change" event when the file name gets changed', () => { expect(wrapper.emitted('name-change')).toBeUndefined(); const newFilename = 'foo.bar'; @@ -51,5 +68,15 @@ describe('Snippet Blob Edit component', () => { expect(wrapper.emitted('name-change')[0]).toEqual([newFilename]); }); }); + + it('emits "input" event when the file content gets changed', () => { + expect(wrapper.emitted('input')).toBeUndefined(); + const newValue = 'foo.bar'; + findContent().vm.$emit('input', newValue); + + return nextTick().then(() => { + expect(wrapper.emitted('input')[0]).toEqual([newValue]); + }); + }); }); }); |