diff options
Diffstat (limited to 'spec/frontend/code_navigation/components')
3 files changed, 41 insertions, 12 deletions
diff --git a/spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap b/spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap index c1534022242..c9fdd388585 100644 --- a/spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap +++ b/spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap @@ -23,17 +23,20 @@ exports[`Code navigation popover component renders popover 1`] = ` <div class="popover-body" > - <gl-deprecated-button-stub + <gl-button-stub + category="tertiary" class="w-100" - href="http://test.com" - size="md" + data-testid="go-to-definition-btn" + href="http://gitlab.com/test.js#L20" + icon="" + size="medium" target="_blank" variant="default" > Go to definition - </gl-deprecated-button-stub> + </gl-button-stub> </div> </div> `; diff --git a/spec/frontend/code_navigation/components/app_spec.js b/spec/frontend/code_navigation/components/app_spec.js index d5693cc4173..6dfc81dcc40 100644 --- a/spec/frontend/code_navigation/components/app_spec.js +++ b/spec/frontend/code_navigation/components/app_spec.js @@ -48,6 +48,7 @@ describe('Code navigation app component', () => { factory({ currentDefinition: { hover: 'console' }, currentDefinitionPosition: { x: 0 }, + currentBlobPath: 'index.js', }); expect(wrapper.find(Popover).exists()).toBe(true); 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); |