diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
commit | 2c89e169769ead722394a79ed67fcd08e96863dd (patch) | |
tree | 0dadb576846c484475b895f75fab41f71cdb952e /spec/frontend/blob/components | |
parent | bd497e352ebd279536ae11855871162e82a3f88c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/blob/components')
4 files changed, 55 insertions, 59 deletions
diff --git a/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap b/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap index b77ca28b9d8..2878ad492a4 100644 --- a/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap +++ b/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap @@ -12,13 +12,12 @@ exports[`Blob Header Default Actions rendering matches the snapshot 1`] = ` class="file-actions d-none d-sm-block" > <viewer-switcher-stub - activeviewer="rich" - blob="[object Object]" + value="simple" /> <default-actions-stub - activeviewer="rich" - blob="[object Object]" + activeviewer="simple" + rawpath="/flightjs/flight/snippets/51/raw" /> </div> </div> diff --git a/spec/frontend/blob/components/blob_header_default_actions_spec.js b/spec/frontend/blob/components/blob_header_default_actions_spec.js index fe0edffd12d..5da0d40ab14 100644 --- a/spec/frontend/blob/components/blob_header_default_actions_spec.js +++ b/spec/frontend/blob/components/blob_header_default_actions_spec.js @@ -8,7 +8,6 @@ import { } from '~/blob/components/constants'; import { GlButtonGroup, GlButton } from '@gitlab/ui'; import { Blob } from './mock_data'; -import eventHub from '~/blob/event_hub'; describe('Blob Header Default Actions', () => { let wrapper; @@ -16,10 +15,10 @@ describe('Blob Header Default Actions', () => { let buttons; const hrefPrefix = 'http://localhost'; - function createComponent(blobProps = {}, propsData = {}) { + function createComponent(propsData = {}) { wrapper = mount(BlobHeaderActions, { propsData: { - blob: Object.assign({}, Blob, blobProps), + rawPath: Blob.rawPath, ...propsData, }, }); @@ -60,12 +59,9 @@ describe('Blob Header Default Actions', () => { }); it('renders "Copy file contents" button as disables if the viewer is Rich', () => { - createComponent( - {}, - { - activeViewer: RICH_BLOB_VIEWER, - }, - ); + createComponent({ + activeViewer: RICH_BLOB_VIEWER, + }); buttons = wrapper.findAll(GlButton); expect(buttons.at(0).attributes('disabled')).toBeTruthy(); @@ -74,10 +70,10 @@ describe('Blob Header Default Actions', () => { describe('functionally', () => { it('emits an event when a Copy Contents button is clicked', () => { - jest.spyOn(eventHub, '$emit'); + jest.spyOn(wrapper.vm, '$emit'); buttons.at(0).vm.$emit('click'); - expect(eventHub.$emit).toHaveBeenCalledWith('copy'); + expect(wrapper.vm.$emit).toHaveBeenCalledWith('copy'); }); }); }); diff --git a/spec/frontend/blob/components/blob_header_spec.js b/spec/frontend/blob/components/blob_header_spec.js index 7d1443fb069..d410ef10fc9 100644 --- a/spec/frontend/blob/components/blob_header_spec.js +++ b/spec/frontend/blob/components/blob_header_spec.js @@ -3,7 +3,6 @@ import BlobHeader from '~/blob/components/blob_header.vue'; import ViewerSwitcher from '~/blob/components/blob_header_viewer_switcher.vue'; import DefaultActions from '~/blob/components/blob_header_default_actions.vue'; import BlobFilepath from '~/blob/components/blob_header_filepath.vue'; -import eventHub from '~/blob/event_hub'; import { Blob } from './mock_data'; @@ -21,10 +20,6 @@ describe('Blob Header Default Actions', () => { }); } - beforeEach(() => { - createComponent(); - }); - afterEach(() => { wrapper.destroy(); }); @@ -96,37 +91,48 @@ describe('Blob Header Default Actions', () => { describe('functionality', () => { const newViewer = 'Foo Bar'; + const activeViewerType = 'Alpha Beta'; - it('listens to "switch-view" event when viewer switcher is shown and updates activeViewer', () => { - expect(wrapper.vm.showViewerSwitcher).toBe(true); - eventHub.$emit('switch-viewer', newViewer); - - return wrapper.vm.$nextTick().then(() => { - expect(wrapper.vm.activeViewer).toBe(newViewer); - }); - }); - - it('does not update active viewer if the switcher is not shown', () => { - const activeViewer = 'Alpha Beta'; + const factory = (hideViewerSwitcher = false) => { createComponent( {}, + {}, { - data() { - return { - activeViewer, - }; - }, - }, - { - hideViewerSwitcher: true, + activeViewerType, + hideViewerSwitcher, }, ); + }; + + it('by default sets viewer data based on activeViewerType', () => { + factory(); + expect(wrapper.vm.viewer).toBe(activeViewerType); + }); + + it('sets viewer to null if the viewer switcher should be hidden', () => { + factory(true); + expect(wrapper.vm.viewer).toBe(null); + }); + + it('watches the changes in viewer data and emits event when the change is registered', () => { + factory(); + jest.spyOn(wrapper.vm, '$emit'); + wrapper.vm.viewer = newViewer; + + return wrapper.vm.$nextTick().then(() => { + expect(wrapper.vm.$emit).toHaveBeenCalledWith('viewer-changed', newViewer); + }); + }); + + it('does not emit event if the switcher is not rendered', () => { + factory(true); expect(wrapper.vm.showViewerSwitcher).toBe(false); - eventHub.$emit('switch-viewer', newViewer); + jest.spyOn(wrapper.vm, '$emit'); + wrapper.vm.viewer = newViewer; return wrapper.vm.$nextTick().then(() => { - expect(wrapper.vm.activeViewer).toBe(activeViewer); + expect(wrapper.vm.$emit).not.toHaveBeenCalled(); }); }); }); diff --git a/spec/frontend/blob/components/blob_header_viewer_switcher_spec.js b/spec/frontend/blob/components/blob_header_viewer_switcher_spec.js index 88e9eeea994..f1a7ac8b21a 100644 --- a/spec/frontend/blob/components/blob_header_viewer_switcher_spec.js +++ b/spec/frontend/blob/components/blob_header_viewer_switcher_spec.js @@ -7,18 +7,13 @@ import { SIMPLE_BLOB_VIEWER_TITLE, } from '~/blob/components/constants'; import { GlButtonGroup, GlButton } from '@gitlab/ui'; -import { Blob } from './mock_data'; -import eventHub from '~/blob/event_hub'; describe('Blob Header Viewer Switcher', () => { let wrapper; - function createComponent(blobProps = {}, propsData = {}) { + function createComponent(propsData = {}) { wrapper = mount(BlobHeaderViewerSwitcher, { - propsData: { - blob: Object.assign({}, Blob, blobProps), - ...propsData, - }, + propsData, }); } @@ -29,7 +24,7 @@ describe('Blob Header Viewer Switcher', () => { describe('intiialization', () => { it('is initialized with simple viewer as active', () => { createComponent(); - expect(wrapper.vm.activeViewer).toBe(SIMPLE_BLOB_VIEWER); + expect(wrapper.vm.value).toBe(SIMPLE_BLOB_VIEWER); }); }); @@ -60,42 +55,42 @@ describe('Blob Header Viewer Switcher', () => { let simpleBtn; let richBtn; - function factory(propsOptions = {}) { - createComponent({}, propsOptions); + function factory(propsData = {}) { + createComponent(propsData); buttons = wrapper.findAll(GlButton); simpleBtn = buttons.at(0); richBtn = buttons.at(1); - jest.spyOn(eventHub, '$emit'); + jest.spyOn(wrapper.vm, '$emit'); } it('does not switch the viewer if the selected one is already active', () => { factory(); - expect(wrapper.vm.activeViewer).toBe(SIMPLE_BLOB_VIEWER); + expect(wrapper.vm.value).toBe(SIMPLE_BLOB_VIEWER); simpleBtn.vm.$emit('click'); - expect(wrapper.vm.activeViewer).toBe(SIMPLE_BLOB_VIEWER); - expect(eventHub.$emit).not.toHaveBeenCalled(); + expect(wrapper.vm.value).toBe(SIMPLE_BLOB_VIEWER); + expect(wrapper.vm.$emit).not.toHaveBeenCalled(); }); it('emits an event when a Rich Viewer button is clicked', () => { factory(); - expect(wrapper.vm.activeViewer).toBe(SIMPLE_BLOB_VIEWER); + expect(wrapper.vm.value).toBe(SIMPLE_BLOB_VIEWER); richBtn.vm.$emit('click'); return wrapper.vm.$nextTick().then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith('switch-viewer', RICH_BLOB_VIEWER); + expect(wrapper.vm.$emit).toHaveBeenCalledWith('input', RICH_BLOB_VIEWER); }); }); it('emits an event when a Simple Viewer button is clicked', () => { factory({ - activeViewer: RICH_BLOB_VIEWER, + value: RICH_BLOB_VIEWER, }); simpleBtn.vm.$emit('click'); return wrapper.vm.$nextTick().then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith('switch-viewer', SIMPLE_BLOB_VIEWER); + expect(wrapper.vm.$emit).toHaveBeenCalledWith('input', SIMPLE_BLOB_VIEWER); }); }); }); |