summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/code_navigation/store/actions_spec.js64
-rw-r--r--spec/frontend/code_navigation/store/mutations_spec.js8
-rw-r--r--spec/frontend/code_navigation/utils/index_spec.js4
3 files changed, 46 insertions, 30 deletions
diff --git a/spec/frontend/code_navigation/store/actions_spec.js b/spec/frontend/code_navigation/store/actions_spec.js
index f58dc283ada..6d2ede6dda7 100644
--- a/spec/frontend/code_navigation/store/actions_spec.js
+++ b/spec/frontend/code_navigation/store/actions_spec.js
@@ -28,9 +28,9 @@ describe('Code navigation actions', () => {
describe('fetchData', () => {
let mock;
- const codeNavUrl =
+ const codeNavigationPath =
'gitlab-org/gitlab-shell/-/jobs/1114/artifacts/raw/lsif/cmd/check/main.go.json';
- const state = { codeNavUrl };
+ const state = { blobs: [{ path: 'index.js', codeNavigationPath }] };
beforeEach(() => {
window.gon = { api_version: '1' };
@@ -43,7 +43,7 @@ describe('Code navigation actions', () => {
describe('success', () => {
beforeEach(() => {
- mock.onGet(codeNavUrl).replyOnce(200, [
+ mock.onGet(codeNavigationPath).replyOnce(200, [
{
start_line: 0,
start_char: 0,
@@ -66,7 +66,12 @@ describe('Code navigation actions', () => {
{ type: 'REQUEST_DATA' },
{
type: 'REQUEST_DATA_SUCCESS',
- payload: { '0:0': { start_line: 0, start_char: 0, hover: { value: '123' } } },
+ payload: {
+ path: 'index.js',
+ normalizedData: {
+ '0:0': { start_line: 0, start_char: 0, hover: { value: '123' } },
+ },
+ },
},
],
[],
@@ -83,13 +88,18 @@ describe('Code navigation actions', () => {
{ type: 'REQUEST_DATA' },
{
type: 'REQUEST_DATA_SUCCESS',
- payload: { '0:0': { start_line: 0, start_char: 0, hover: { value: '123' } } },
+ payload: {
+ path: 'index.js',
+ normalizedData: {
+ '0:0': { start_line: 0, start_char: 0, hover: { value: '123' } },
+ },
+ },
},
],
[],
)
.then(() => {
- expect(addInteractionClass).toHaveBeenCalledWith({
+ expect(addInteractionClass).toHaveBeenCalledWith('index.js', {
start_line: 0,
start_char: 0,
hover: { value: '123' },
@@ -102,7 +112,7 @@ describe('Code navigation actions', () => {
describe('error', () => {
beforeEach(() => {
- mock.onGet(codeNavUrl).replyOnce(500);
+ mock.onGet(codeNavigationPath).replyOnce(500);
});
it('dispatches requestDataError', done => {
@@ -118,11 +128,29 @@ describe('Code navigation actions', () => {
});
});
+ describe('showBlobInteractionZones', () => {
+ it('calls addInteractionClass with data for a path', () => {
+ const state = {
+ data: {
+ 'index.js': { '0:0': 'test', '1:1': 'console.log' },
+ },
+ };
+
+ 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']);
+ });
+ });
+
describe('showDefinition', () => {
let target;
beforeEach(() => {
- target = document.createElement('div');
+ setFixtures('<div data-path="index.js"><div class="js-test"></div></div>');
+ target = document.querySelector('.js-test');
});
it('returns early when no data exists', done => {
@@ -130,19 +158,7 @@ describe('Code navigation actions', () => {
});
it('commits SET_CURRENT_DEFINITION when target is not code navitation element', done => {
- testAction(
- actions.showDefinition,
- { target },
- { data: {} },
- [
- {
- type: 'SET_CURRENT_DEFINITION',
- payload: { definition: undefined, position: undefined },
- },
- ],
- [],
- done,
- );
+ testAction(actions.showDefinition, { target }, { data: {} }, [], [], done);
});
it('commits SET_CURRENT_DEFINITION with LSIF data', done => {
@@ -153,7 +169,7 @@ describe('Code navigation actions', () => {
testAction(
actions.showDefinition,
{ target },
- { data: { '0:0': { hover: 'test' } } },
+ { data: { 'index.js': { '0:0': { hover: 'test' } } } },
[
{
type: 'SET_CURRENT_DEFINITION',
@@ -173,7 +189,7 @@ describe('Code navigation actions', () => {
return testAction(
actions.showDefinition,
{ target },
- { data: { '0:0': { hover: 'test' } } },
+ { data: { 'index.js': { '0:0': { hover: 'test' } } } },
[
{
type: 'SET_CURRENT_DEFINITION',
@@ -194,7 +210,7 @@ describe('Code navigation actions', () => {
return testAction(
actions.showDefinition,
{ target },
- { data: { '0:0': { hover: 'test' } } },
+ { data: { 'index.js': { '0:0': { hover: 'test' } } } },
[
{
type: 'SET_CURRENT_DEFINITION',
diff --git a/spec/frontend/code_navigation/store/mutations_spec.js b/spec/frontend/code_navigation/store/mutations_spec.js
index 305386f4d0b..d4a75da429e 100644
--- a/spec/frontend/code_navigation/store/mutations_spec.js
+++ b/spec/frontend/code_navigation/store/mutations_spec.js
@@ -11,11 +11,11 @@ describe('Code navigation mutations', () => {
describe('SET_INITIAL_DATA', () => {
it('sets initial data', () => {
mutations.SET_INITIAL_DATA(state, {
- codeNavUrl: 'https://test.com/builds/1005',
+ blobs: ['test'],
definitionPathPrefix: 'https://test.com/blob/master',
});
- expect(state.codeNavUrl).toBe('https://test.com/builds/1005');
+ expect(state.blobs).toEqual(['test']);
expect(state.definitionPathPrefix).toBe('https://test.com/blob/master');
});
});
@@ -36,9 +36,9 @@ describe('Code navigation mutations', () => {
});
it('sets data', () => {
- mutations.REQUEST_DATA_SUCCESS(state, ['test']);
+ mutations.REQUEST_DATA_SUCCESS(state, { path: 'index.js', normalizedData: ['test'] });
- expect(state.data).toEqual(['test']);
+ expect(state.data).toEqual({ 'index.js': ['test'] });
});
});
diff --git a/spec/frontend/code_navigation/utils/index_spec.js b/spec/frontend/code_navigation/utils/index_spec.js
index 458cc536635..58c48a90075 100644
--- a/spec/frontend/code_navigation/utils/index_spec.js
+++ b/spec/frontend/code_navigation/utils/index_spec.js
@@ -36,7 +36,7 @@ describe('setCurrentHoverElement', () => {
describe('addInteractionClass', () => {
beforeEach(() => {
setFixtures(
- '<div id="LC1"><span>console</span><span>.</span><span>log</span></div><div id="LC2"><span>function</span></div>',
+ '<div data-path="index.js"><div class="blob-content"><div id="LC1"><span>console</span><span>.</span><span>log</span></div><div id="LC2"><span>function</span></div></div></div>',
);
});
@@ -48,7 +48,7 @@ describe('addInteractionClass', () => {
`(
'it sets code navigation attributes for line $line and character $char',
({ line, char, index }) => {
- addInteractionClass({ start_line: line, start_char: char });
+ addInteractionClass('index.js', { start_line: line, start_char: char });
expect(document.querySelectorAll(`#LC${line + 1} span`)[index].classList).toContain(
'js-code-navigation',