diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 18:09:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 18:09:52 +0300 |
commit | e43077ab4742ba5083a01a1e5341db1a1b7a1701 (patch) | |
tree | c33a00fb176caff735243c484bbd594a3b08bb6e /spec/frontend | |
parent | 211a8c3361ccf4eb92f36edbdcf15c98fcdcc8b7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/blob/components/blob_header_default_actions_spec.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/frontend/blob/components/blob_header_default_actions_spec.js b/spec/frontend/blob/components/blob_header_default_actions_spec.js new file mode 100644 index 00000000000..348d68514a3 --- /dev/null +++ b/spec/frontend/blob/components/blob_header_default_actions_spec.js @@ -0,0 +1,64 @@ +import { mount } from '@vue/test-utils'; +import BlobHeaderActions from '~/blob/components/blob_header_default_actions.vue'; +import { + BTN_COPY_CONTENTS_TITLE, + BTN_DOWNLOAD_TITLE, + BTN_RAW_TITLE, +} from '~/blob/components/constants'; +import { GlButtonGroup, GlButton } from '@gitlab/ui'; +import { Blob } from './mock_data'; + +describe('Blob Header Default Actions', () => { + let wrapper; + let btnGroup; + let buttons; + const hrefPrefix = 'http://localhost'; + + function createComponent(props = {}) { + wrapper = mount(BlobHeaderActions, { + propsData: { + blob: Object.assign({}, Blob, props), + }, + }); + } + + beforeEach(() => { + createComponent(); + btnGroup = wrapper.find(GlButtonGroup); + buttons = wrapper.findAll(GlButton); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + describe('renders', () => { + it('gl-button-group component', () => { + expect(btnGroup.exists()).toBe(true); + }); + + it('exactly 3 buttons with predefined actions', () => { + expect(buttons.length).toBe(3); + [BTN_COPY_CONTENTS_TITLE, BTN_RAW_TITLE, BTN_DOWNLOAD_TITLE].forEach((title, i) => { + expect(buttons.at(i).vm.$el.title).toBe(title); + }); + }); + + it('correct href attribute on RAW button', () => { + expect(buttons.at(1).vm.$el.href).toBe(`${hrefPrefix}${Blob.rawPath}`); + }); + + it('correct href attribute on Download button', () => { + expect(buttons.at(2).vm.$el.href).toBe(`${hrefPrefix}${Blob.rawPath}?inline=false`); + }); + }); + + describe('functionally', () => { + it('emits an event when a Copy Contents button is clicked', () => { + jest.spyOn(wrapper.vm, '$emit'); + buttons.at(0).vm.$emit('click'); + + expect(wrapper.vm.$emit).toHaveBeenCalledWith('copy'); + }); + }); +}); |