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/app_spec.js7
-rw-r--r--spec/frontend/code_navigation/store/actions_spec.js64
-rw-r--r--spec/frontend/code_navigation/store/mutations_spec.js2
-rw-r--r--spec/frontend/code_navigation/utils/index_spec.js30
4 files changed, 71 insertions, 32 deletions
diff --git a/spec/frontend/code_navigation/components/app_spec.js b/spec/frontend/code_navigation/components/app_spec.js
index 0d7c0360e9b..f2f97092c5a 100644
--- a/spec/frontend/code_navigation/components/app_spec.js
+++ b/spec/frontend/code_navigation/components/app_spec.js
@@ -38,12 +38,17 @@ describe('Code navigation app component', () => {
const codeNavigationPath = 'code/nav/path.js';
const path = 'blob/path.js';
const definitionPathPrefix = 'path/prefix';
+ const wrapTextNodes = true;
- factory({}, { codeNavigationPath, blobPath: path, pathPrefix: definitionPathPrefix });
+ factory(
+ {},
+ { codeNavigationPath, blobPath: path, pathPrefix: definitionPathPrefix, wrapTextNodes },
+ );
expect(setInitialData).toHaveBeenCalledWith(expect.anything(), {
blobs: [{ codeNavigationPath, path }],
definitionPathPrefix,
+ wrapTextNodes,
});
});
diff --git a/spec/frontend/code_navigation/store/actions_spec.js b/spec/frontend/code_navigation/store/actions_spec.js
index 73f935deeca..c26416aca94 100644
--- a/spec/frontend/code_navigation/store/actions_spec.js
+++ b/spec/frontend/code_navigation/store/actions_spec.js
@@ -7,15 +7,16 @@ import axios from '~/lib/utils/axios_utils';
jest.mock('~/code_navigation/utils');
describe('Code navigation actions', () => {
+ const wrapTextNodes = true;
+
describe('setInitialData', () => {
- it('commits SET_INITIAL_DATA', (done) => {
- testAction(
+ it('commits SET_INITIAL_DATA', () => {
+ return testAction(
actions.setInitialData,
- { projectPath: 'test' },
+ { projectPath: 'test', wrapTextNodes },
{},
- [{ type: 'SET_INITIAL_DATA', payload: { projectPath: 'test' } }],
+ [{ type: 'SET_INITIAL_DATA', payload: { projectPath: 'test', wrapTextNodes } }],
[],
- done,
);
});
});
@@ -30,7 +31,7 @@ describe('Code navigation actions', () => {
const codeNavigationPath =
'gitlab-org/gitlab-shell/-/jobs/1114/artifacts/raw/lsif/cmd/check/main.go.json';
- const state = { blobs: [{ path: 'index.js', codeNavigationPath }] };
+ const state = { blobs: [{ path: 'index.js', codeNavigationPath }], wrapTextNodes };
beforeEach(() => {
window.gon = { api_version: '1' };
@@ -57,8 +58,8 @@ describe('Code navigation actions', () => {
]);
});
- it('commits REQUEST_DATA_SUCCESS with normalized data', (done) => {
- testAction(
+ it('commits REQUEST_DATA_SUCCESS with normalized data', () => {
+ return testAction(
actions.fetchData,
null,
state,
@@ -80,12 +81,11 @@ describe('Code navigation actions', () => {
},
],
[],
- done,
);
});
- it('calls addInteractionClass with data', (done) => {
- testAction(
+ it('calls addInteractionClass with data', () => {
+ return testAction(
actions.fetchData,
null,
state,
@@ -107,16 +107,17 @@ describe('Code navigation actions', () => {
},
],
[],
- )
- .then(() => {
- expect(addInteractionClass).toHaveBeenCalledWith('index.js', {
+ ).then(() => {
+ expect(addInteractionClass).toHaveBeenCalledWith({
+ path: 'index.js',
+ d: {
start_line: 0,
start_char: 0,
hover: { value: '123' },
- });
- })
- .then(done)
- .catch(done.fail);
+ },
+ wrapTextNodes,
+ });
+ });
});
});
@@ -125,14 +126,13 @@ describe('Code navigation actions', () => {
mock.onGet(codeNavigationPath).replyOnce(500);
});
- it('dispatches requestDataError', (done) => {
- testAction(
+ it('dispatches requestDataError', () => {
+ return testAction(
actions.fetchData,
null,
state,
[{ type: 'REQUEST_DATA' }],
[{ type: 'requestDataError' }],
- done,
);
});
});
@@ -144,14 +144,19 @@ describe('Code navigation actions', () => {
data: {
'index.js': { '0:0': 'test', '1:1': 'console.log' },
},
+ wrapTextNodes,
};
actions.showBlobInteractionZones({ state }, 'index.js');
expect(addInteractionClass).toHaveBeenCalled();
expect(addInteractionClass.mock.calls.length).toBe(2);
- expect(addInteractionClass.mock.calls[0]).toEqual(['index.js', 'test']);
- expect(addInteractionClass.mock.calls[1]).toEqual(['index.js', 'console.log']);
+ expect(addInteractionClass.mock.calls[0]).toEqual([
+ { path: 'index.js', d: 'test', wrapTextNodes },
+ ]);
+ expect(addInteractionClass.mock.calls[1]).toEqual([
+ { path: 'index.js', d: 'console.log', wrapTextNodes },
+ ]);
});
it('does not call addInteractionClass when no data exists', () => {
@@ -175,20 +180,20 @@ describe('Code navigation actions', () => {
target = document.querySelector('.js-test');
});
- it('returns early when no data exists', (done) => {
- testAction(actions.showDefinition, { target }, {}, [], [], done);
+ it('returns early when no data exists', () => {
+ return testAction(actions.showDefinition, { target }, {}, [], []);
});
- it('commits SET_CURRENT_DEFINITION when target is not code navitation element', (done) => {
- testAction(actions.showDefinition, { target }, { data: {} }, [], [], done);
+ it('commits SET_CURRENT_DEFINITION when target is not code navitation element', () => {
+ return testAction(actions.showDefinition, { target }, { data: {} }, [], []);
});
- it('commits SET_CURRENT_DEFINITION with LSIF data', (done) => {
+ it('commits SET_CURRENT_DEFINITION with LSIF data', () => {
target.classList.add('js-code-navigation');
target.setAttribute('data-line-index', '0');
target.setAttribute('data-char-index', '0');
- testAction(
+ return testAction(
actions.showDefinition,
{ target },
{ data: { 'index.js': { '0:0': { hover: 'test' } } } },
@@ -203,7 +208,6 @@ describe('Code navigation actions', () => {
},
],
[],
- done,
);
});
diff --git a/spec/frontend/code_navigation/store/mutations_spec.js b/spec/frontend/code_navigation/store/mutations_spec.js
index cb10729f4b6..b2f1b3bddfd 100644
--- a/spec/frontend/code_navigation/store/mutations_spec.js
+++ b/spec/frontend/code_navigation/store/mutations_spec.js
@@ -13,10 +13,12 @@ describe('Code navigation mutations', () => {
mutations.SET_INITIAL_DATA(state, {
blobs: ['test'],
definitionPathPrefix: 'https://test.com/blob/main',
+ wrapTextNodes: true,
});
expect(state.blobs).toEqual(['test']);
expect(state.definitionPathPrefix).toBe('https://test.com/blob/main');
+ expect(state.wrapTextNodes).toBe(true);
});
});
diff --git a/spec/frontend/code_navigation/utils/index_spec.js b/spec/frontend/code_navigation/utils/index_spec.js
index 6a01249d2a3..682c8bce8c5 100644
--- a/spec/frontend/code_navigation/utils/index_spec.js
+++ b/spec/frontend/code_navigation/utils/index_spec.js
@@ -45,14 +45,42 @@ describe('addInteractionClass', () => {
${0} | ${0} | ${0}
${0} | ${8} | ${2}
${1} | ${0} | ${0}
+ ${1} | ${0} | ${0}
`(
'it sets code navigation attributes for line $line and character $char',
({ line, char, index }) => {
- addInteractionClass('index.js', { start_line: line, start_char: char });
+ addInteractionClass({ path: 'index.js', d: { start_line: line, start_char: char } });
expect(document.querySelectorAll(`#LC${line + 1} span`)[index].classList).toContain(
'js-code-navigation',
);
},
);
+
+ describe('wrapTextNodes', () => {
+ beforeEach(() => {
+ setFixtures(
+ '<div data-path="index.js"><div class="blob-content"><div id="LC1" class="line"> Text </div></div></div>',
+ );
+ });
+
+ const params = { path: 'index.js', d: { start_line: 0, start_char: 0 } };
+ const findAllSpans = () => document.querySelectorAll('#LC1 span');
+
+ it('does not wrap text nodes by default', () => {
+ addInteractionClass(params);
+ const spans = findAllSpans();
+ expect(spans.length).toBe(0);
+ });
+
+ it('wraps text nodes if wrapTextNodes is true', () => {
+ addInteractionClass({ ...params, wrapTextNodes: true });
+ const spans = findAllSpans();
+
+ expect(spans.length).toBe(3);
+ expect(spans[0].textContent).toBe(' ');
+ expect(spans[1].textContent).toBe('Text');
+ expect(spans[2].textContent).toBe(' ');
+ });
+ });
});