diff options
Diffstat (limited to 'spec/frontend/code_navigation/components/popover_spec.js')
-rw-r--r-- | spec/frontend/code_navigation/components/popover_spec.js | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/spec/frontend/code_navigation/components/popover_spec.js b/spec/frontend/code_navigation/components/popover_spec.js index df3bbc7c1c6..858e94cf155 100644 --- a/spec/frontend/code_navigation/components/popover_spec.js +++ b/spec/frontend/code_navigation/components/popover_spec.js @@ -1,7 +1,7 @@ import { shallowMount } from '@vue/test-utils'; import Popover from '~/code_navigation/components/popover.vue'; -const DEFINITION_PATH_PREFIX = 'http:/'; +const DEFINITION_PATH_PREFIX = 'http://gitlab.com'; const MOCK_CODE_DATA = Object.freeze({ hover: [ @@ -10,7 +10,7 @@ const MOCK_CODE_DATA = Object.freeze({ value: 'console.log', }, ], - definition_path: 'test.com', + definition_path: 'test.js#L20', }); const MOCK_DOCS_DATA = Object.freeze({ @@ -20,13 +20,15 @@ const MOCK_DOCS_DATA = Object.freeze({ value: 'console.log', }, ], - definition_path: 'test.com', + definition_path: 'test.js#L20', }); let wrapper; -function factory(position, data, definitionPathPrefix) { - wrapper = shallowMount(Popover, { propsData: { position, data, definitionPathPrefix } }); +function factory({ position, data, definitionPathPrefix, blobPath = 'index.js' }) { + wrapper = shallowMount(Popover, { + propsData: { position, data, definitionPathPrefix, blobPath }, + }); } describe('Code navigation popover component', () => { @@ -35,14 +37,33 @@ describe('Code navigation popover component', () => { }); it('renders popover', () => { - factory({ x: 0, y: 0, height: 0 }, MOCK_CODE_DATA, DEFINITION_PATH_PREFIX); + factory({ + position: { x: 0, y: 0, height: 0 }, + data: MOCK_CODE_DATA, + definitionPathPrefix: DEFINITION_PATH_PREFIX, + }); expect(wrapper.element).toMatchSnapshot(); }); + it('renders link with hash to current file', () => { + factory({ + position: { x: 0, y: 0, height: 0 }, + data: MOCK_CODE_DATA, + definitionPathPrefix: DEFINITION_PATH_PREFIX, + blobPath: 'test.js', + }); + + expect(wrapper.find('[data-testid="go-to-definition-btn"]').attributes('href')).toBe('#L20'); + }); + describe('code output', () => { it('renders code output', () => { - factory({ x: 0, y: 0, height: 0 }, MOCK_CODE_DATA, DEFINITION_PATH_PREFIX); + factory({ + position: { x: 0, y: 0, height: 0 }, + data: MOCK_CODE_DATA, + definitionPathPrefix: DEFINITION_PATH_PREFIX, + }); expect(wrapper.find({ ref: 'code-output' }).exists()).toBe(true); expect(wrapper.find({ ref: 'doc-output' }).exists()).toBe(false); @@ -51,7 +72,11 @@ describe('Code navigation popover component', () => { describe('documentation output', () => { it('renders code output', () => { - factory({ x: 0, y: 0, height: 0 }, MOCK_DOCS_DATA, DEFINITION_PATH_PREFIX); + factory({ + position: { x: 0, y: 0, height: 0 }, + data: MOCK_DOCS_DATA, + definitionPathPrefix: DEFINITION_PATH_PREFIX, + }); expect(wrapper.find({ ref: 'code-output' }).exists()).toBe(false); expect(wrapper.find({ ref: 'doc-output' }).exists()).toBe(true); |