diff options
Diffstat (limited to 'spec/frontend/lib/utils')
-rw-r--r-- | spec/frontend/lib/utils/common_utils_spec.js | 23 | ||||
-rw-r--r-- | spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js | 59 | ||||
-rw-r--r-- | spec/frontend/lib/utils/datetime_utility_spec.js | 10 | ||||
-rw-r--r-- | spec/frontend/lib/utils/file_upload_spec.js | 28 | ||||
-rw-r--r-- | spec/frontend/lib/utils/text_markdown_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/lib/utils/url_utility_spec.js | 8 |
6 files changed, 116 insertions, 16 deletions
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js index f5a74ee7f09..de1be5bc337 100644 --- a/spec/frontend/lib/utils/common_utils_spec.js +++ b/spec/frontend/lib/utils/common_utils_spec.js @@ -279,6 +279,14 @@ describe('common_utils', () => { top: elementTopWithContext, }); }); + + it('passes through behaviour', () => { + commonUtils.scrollToElementWithContext(`#${id}`, { behavior: 'smooth' }); + expect(window.scrollTo).toHaveBeenCalledWith({ + behavior: 'smooth', + top: elementTopWithContext, + }); + }); }); }); @@ -1000,6 +1008,21 @@ describe('common_utils', () => { }); }); + describe('scopedLabelKey', () => { + it.each` + label | expectedLabelKey + ${undefined} | ${''} + ${''} | ${''} + ${'title'} | ${'title'} + ${'scoped::value'} | ${'scoped'} + ${'scoped::label::value'} | ${'scoped::label'} + ${'scoped::label-some::value'} | ${'scoped::label-some'} + ${'scoped::label::some::value'} | ${'scoped::label::some'} + `('returns "$expectedLabelKey" when label is "$label"', ({ label, expectedLabelKey }) => { + expect(commonUtils.scopedLabelKey({ title: label })).toBe(expectedLabelKey); + }); + }); + describe('getDashPath', () => { it('returns the path following /-/', () => { expect(commonUtils.getDashPath('/some/-/url-with-dashes-/')).toEqual('url-with-dashes-/'); diff --git a/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js new file mode 100644 index 00000000000..d19f9352bbc --- /dev/null +++ b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js @@ -0,0 +1,59 @@ +import { GlModal } from '@gitlab/ui'; +import { mount } from '@vue/test-utils'; +import ConfirmModal from '~/lib/utils/confirm_via_gl_modal/confirm_modal.vue'; + +describe('Confirm Modal', () => { + let wrapper; + let modal; + + const createComponent = ({ primaryText, primaryVariant } = {}) => { + wrapper = mount(ConfirmModal, { + propsData: { + primaryText, + primaryVariant, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + const findGlModal = () => wrapper.findComponent(GlModal); + + describe('Modal events', () => { + beforeEach(() => { + createComponent(); + modal = findGlModal(); + }); + + it('should emit `confirmed` event on `primary` modal event', () => { + findGlModal().vm.$emit('primary'); + expect(wrapper.emitted('confirmed')).toBeTruthy(); + }); + + it('should emit closed` event on `hidden` modal event', () => { + modal.vm.$emit('hidden'); + expect(wrapper.emitted('closed')).toBeTruthy(); + }); + }); + + describe('Custom properties', () => { + it('should pass correct custom primary text & button variant to the modal when provided', () => { + const primaryText = "Let's do it!"; + const primaryVariant = 'danger'; + + createComponent({ primaryText, primaryVariant }); + const customProps = findGlModal().props('actionPrimary'); + expect(customProps.text).toBe(primaryText); + expect(customProps.attributes.variant).toBe(primaryVariant); + }); + + it('should pass default primary text & button variant to the modal if no custom values provided', () => { + createComponent(); + const customProps = findGlModal().props('actionPrimary'); + expect(customProps.text).toBe('OK'); + expect(customProps.attributes.variant).toBe('confirm'); + }); + }); +}); diff --git a/spec/frontend/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js index f6ad41d5478..7a64b654baa 100644 --- a/spec/frontend/lib/utils/datetime_utility_spec.js +++ b/spec/frontend/lib/utils/datetime_utility_spec.js @@ -185,15 +185,15 @@ describe('dateInWords', () => { const date = new Date('07/01/2016'); it('should return date in words', () => { - expect(datetimeUtility.dateInWords(date)).toEqual(s__('July 1, 2016')); + expect(datetimeUtility.dateInWords(date)).toEqual(__('July 1, 2016')); }); it('should return abbreviated month name', () => { - expect(datetimeUtility.dateInWords(date, true)).toEqual(s__('Jul 1, 2016')); + expect(datetimeUtility.dateInWords(date, true)).toEqual(__('Jul 1, 2016')); }); it('should return date in words without year', () => { - expect(datetimeUtility.dateInWords(date, true, true)).toEqual(s__('Jul 1')); + expect(datetimeUtility.dateInWords(date, true, true)).toEqual(__('Jul 1')); }); }); @@ -201,11 +201,11 @@ describe('monthInWords', () => { const date = new Date('2017-01-20'); it('returns month name from provided date', () => { - expect(datetimeUtility.monthInWords(date)).toBe(s__('January')); + expect(datetimeUtility.monthInWords(date)).toBe(__('January')); }); it('returns abbreviated month name from provided date', () => { - expect(datetimeUtility.monthInWords(date, true)).toBe(s__('Jan')); + expect(datetimeUtility.monthInWords(date, true)).toBe(__('Jan')); }); }); diff --git a/spec/frontend/lib/utils/file_upload_spec.js b/spec/frontend/lib/utils/file_upload_spec.js index 1dff5d4f925..ff11107ea60 100644 --- a/spec/frontend/lib/utils/file_upload_spec.js +++ b/spec/frontend/lib/utils/file_upload_spec.js @@ -1,4 +1,4 @@ -import fileUpload, { getFilename } from '~/lib/utils/file_upload'; +import fileUpload, { getFilename, validateImageName } from '~/lib/utils/file_upload'; describe('File upload', () => { beforeEach(() => { @@ -64,13 +64,23 @@ describe('File upload', () => { }); describe('getFilename', () => { - it('returns first value correctly', () => { - const event = { - clipboardData: { - getData: () => 'test.png\rtest.txt', - }, - }; - - expect(getFilename(event)).toBe('test.png'); + it('returns file name', () => { + const file = new File([], 'test.jpg'); + + expect(getFilename(file)).toBe('test.jpg'); + }); +}); + +describe('file name validator', () => { + it('validate file name', () => { + const file = new File([], 'test.jpg'); + + expect(validateImageName(file)).toBe('test.jpg'); + }); + + it('illegal file name should be rename to image.png', () => { + const file = new File([], 'test<.png'); + + expect(validateImageName(file)).toBe('image.png'); }); }); diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js index acbf1a975b8..ab81ec47b64 100644 --- a/spec/frontend/lib/utils/text_markdown_spec.js +++ b/spec/frontend/lib/utils/text_markdown_spec.js @@ -100,11 +100,11 @@ describe('init markdown', () => { text: textArea.value, tag: '```suggestion:-0+0\n{text}\n```', blockTag: true, - selected: '# Does not parse the %br currently.', + selected: '# Does not %br parse the %br currently.', wrap: false, }); - expect(textArea.value).toContain('# Does not parse the \\n currently.'); + expect(textArea.value).toContain('# Does not \\n parse the \\n currently.'); }); it('inserts the tag on the same line if the current line only contains spaces', () => { diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js index 36e1a453ef4..c6edba19c56 100644 --- a/spec/frontend/lib/utils/url_utility_spec.js +++ b/spec/frontend/lib/utils/url_utility_spec.js @@ -1060,4 +1060,12 @@ describe('URL utility', () => { }, ); }); + + describe('defaultPromoUrl', () => { + it('Gitlab about page url', () => { + const url = 'https://about.gitlab.com'; + + expect(urlUtils.PROMO_URL).toBe(url); + }); + }); }); |