summaryrefslogtreecommitdiff
path: root/spec/frontend/code_navigation
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/code_navigation')
-rw-r--r--spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap11
-rw-r--r--spec/frontend/code_navigation/components/app_spec.js1
-rw-r--r--spec/frontend/code_navigation/components/popover_spec.js41
-rw-r--r--spec/frontend/code_navigation/store/actions_spec.js28
4 files changed, 66 insertions, 15 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);
diff --git a/spec/frontend/code_navigation/store/actions_spec.js b/spec/frontend/code_navigation/store/actions_spec.js
index 6d2ede6dda7..4cf77ed1be5 100644
--- a/spec/frontend/code_navigation/store/actions_spec.js
+++ b/spec/frontend/code_navigation/store/actions_spec.js
@@ -143,6 +143,16 @@ describe('Code navigation actions', () => {
expect(addInteractionClass.mock.calls[0]).toEqual(['index.js', 'test']);
expect(addInteractionClass.mock.calls[1]).toEqual(['index.js', 'console.log']);
});
+
+ it('does not call addInteractionClass when no data exists', () => {
+ const state = {
+ data: null,
+ };
+
+ actions.showBlobInteractionZones({ state }, 'index.js');
+
+ expect(addInteractionClass).not.toHaveBeenCalled();
+ });
});
describe('showDefinition', () => {
@@ -173,7 +183,11 @@ describe('Code navigation actions', () => {
[
{
type: 'SET_CURRENT_DEFINITION',
- payload: { definition: { hover: 'test' }, position: { height: 0, x: 0, y: 0 } },
+ payload: {
+ blobPath: 'index.js',
+ definition: { hover: 'test' },
+ position: { height: 0, x: 0, y: 0 },
+ },
},
],
[],
@@ -193,7 +207,11 @@ describe('Code navigation actions', () => {
[
{
type: 'SET_CURRENT_DEFINITION',
- payload: { definition: { hover: 'test' }, position: { height: 0, x: 0, y: 0 } },
+ payload: {
+ blobPath: 'index.js',
+ definition: { hover: 'test' },
+ position: { height: 0, x: 0, y: 0 },
+ },
},
],
[],
@@ -214,7 +232,11 @@ describe('Code navigation actions', () => {
[
{
type: 'SET_CURRENT_DEFINITION',
- payload: { definition: { hover: 'test' }, position: { height: 0, x: 0, y: 0 } },
+ payload: {
+ blobPath: 'index.js',
+ definition: { hover: 'test' },
+ position: { height: 0, x: 0, y: 0 },
+ },
},
],
[],