Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/blob')
-rw-r--r--spec/frontend/blob/blob_blame_link_spec.js12
-rw-r--r--spec/frontend/blob/components/__snapshots__/blob_edit_content_spec.js.snap18
-rw-r--r--spec/frontend/blob/components/blob_edit_content_spec.js105
-rw-r--r--spec/frontend/blob/utils_spec.js62
4 files changed, 35 insertions, 162 deletions
diff --git a/spec/frontend/blob/blob_blame_link_spec.js b/spec/frontend/blob/blob_blame_link_spec.js
index 060e8803520..18adeed1f02 100644
--- a/spec/frontend/blob/blob_blame_link_spec.js
+++ b/spec/frontend/blob/blob_blame_link_spec.js
@@ -1,5 +1,5 @@
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
-import addBlameLink from '~/blob/blob_blame_link';
+import { addBlameLink } from '~/blob/blob_blame_link';
describe('Blob links', () => {
const mouseoverEvent = new MouseEvent('mouseover', {
@@ -10,9 +10,10 @@ describe('Blob links', () => {
beforeEach(() => {
setHTMLFixture(`
- <div id="blob-content-holder">
+ <div id="blob-content-holder" class="js-per-page" data-blame-per-page="1000">
<div class="line-numbers" data-blame-path="/blamePath">
<a id="L5" href="#L5" data-line-number="5" class="file-line-num js-line-links">5</a>
+ <a id="L1005" href="#L1005" data-line-number="1005" class="file-line-num js-line-links">1005</a>
</div>
<pre id="LC5">Line 5 content</pre>
</div>
@@ -44,4 +45,11 @@ describe('Blob links', () => {
expect(lineLink).not.toBeNull();
expect(lineLink.getAttribute('href')).toBe('#L5');
});
+
+ it('adds page parameter when needed', () => {
+ document.querySelectorAll('.file-line-num')[1].dispatchEvent(mouseoverEvent);
+ const blameLink = document.querySelectorAll('.file-line-blame')[1];
+ expect(blameLink).not.toBeNull();
+ expect(blameLink.getAttribute('href')).toBe('/blamePath?page=2#L1005');
+ });
});
diff --git a/spec/frontend/blob/components/__snapshots__/blob_edit_content_spec.js.snap b/spec/frontend/blob/components/__snapshots__/blob_edit_content_spec.js.snap
deleted file mode 100644
index 72761c18b3d..00000000000
--- a/spec/frontend/blob/components/__snapshots__/blob_edit_content_spec.js.snap
+++ /dev/null
@@ -1,18 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Blob Header Editing rendering matches the snapshot 1`] = `
-<div
- class="file-content code"
->
- <div
- data-editor-loading=""
- id="editor"
- >
- <pre
- class="editor-loading-content"
- >
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- </pre>
- </div>
-</div>
-`;
diff --git a/spec/frontend/blob/components/blob_edit_content_spec.js b/spec/frontend/blob/components/blob_edit_content_spec.js
deleted file mode 100644
index 5017b624292..00000000000
--- a/spec/frontend/blob/components/blob_edit_content_spec.js
+++ /dev/null
@@ -1,105 +0,0 @@
-import { shallowMount } from '@vue/test-utils';
-import { nextTick } from 'vue';
-import BlobEditContent from '~/blob/components/blob_edit_content.vue';
-import * as utils from '~/blob/utils';
-
-jest.mock('~/editor/source_editor');
-
-describe('Blob Header Editing', () => {
- let wrapper;
- const onDidChangeModelContent = jest.fn();
- const updateModelLanguage = jest.fn();
- const getValue = jest.fn();
- const value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
- const fileName = 'lorem.txt';
- const fileGlobalId = 'snippet_777';
-
- function createComponent(props = {}) {
- wrapper = shallowMount(BlobEditContent, {
- propsData: {
- value,
- fileName,
- fileGlobalId,
- ...props,
- },
- });
- }
-
- beforeEach(() => {
- jest.spyOn(utils, 'initSourceEditor').mockImplementation(() => ({
- onDidChangeModelContent,
- updateModelLanguage,
- getValue,
- dispose: jest.fn(),
- }));
-
- createComponent();
- });
-
- afterEach(() => {
- wrapper.destroy();
- });
-
- const triggerChangeContent = (val) => {
- getValue.mockReturnValue(val);
- const [cb] = onDidChangeModelContent.mock.calls[0];
-
- cb();
-
- jest.runOnlyPendingTimers();
- };
-
- describe('rendering', () => {
- it('matches the snapshot', () => {
- expect(wrapper.element).toMatchSnapshot();
- });
-
- it('renders content', () => {
- expect(wrapper.text()).toContain(value);
- });
- });
-
- describe('functionality', () => {
- it('does not fail without content', () => {
- const spy = jest.spyOn(global.console, 'error');
- createComponent({ value: undefined });
-
- expect(spy).not.toHaveBeenCalled();
- expect(wrapper.find('#editor').exists()).toBe(true);
- });
-
- it('initialises Source Editor', () => {
- const el = wrapper.findComponent({ ref: 'editor' }).element;
- expect(utils.initSourceEditor).toHaveBeenCalledWith({
- el,
- blobPath: fileName,
- blobGlobalId: fileGlobalId,
- blobContent: value,
- });
- });
-
- it('reacts to the changes in fileName', () => {
- const newFileName = 'ipsum.txt';
-
- wrapper.setProps({
- fileName: newFileName,
- });
-
- return nextTick().then(() => {
- expect(updateModelLanguage).toHaveBeenCalledWith(newFileName);
- });
- });
-
- it('registers callback with editor onChangeContent', () => {
- expect(onDidChangeModelContent).toHaveBeenCalledWith(expect.any(Function));
- });
-
- it('emits input event when the blob content is changed', () => {
- expect(wrapper.emitted().input).toBeUndefined();
-
- triggerChangeContent(value);
-
- expect(wrapper.emitted().input).toEqual([[value]]);
- });
- });
-});
diff --git a/spec/frontend/blob/utils_spec.js b/spec/frontend/blob/utils_spec.js
index a543c0060cb..24f70acb093 100644
--- a/spec/frontend/blob/utils_spec.js
+++ b/spec/frontend/blob/utils_spec.js
@@ -1,44 +1,32 @@
import * as utils from '~/blob/utils';
-import Editor from '~/editor/source_editor';
-
-jest.mock('~/editor/source_editor');
describe('Blob utilities', () => {
- describe('initSourceEditor', () => {
- let editorEl;
- const blobPath = 'foo.txt';
- const blobContent = 'Foo bar';
- const blobGlobalId = 'snippet_777';
-
- beforeEach(() => {
- editorEl = document.createElement('div');
+ describe('getPageParamValue', () => {
+ it('returns empty string if no perPage parameter is provided', () => {
+ const pageParamValue = utils.getPageParamValue(5);
+ expect(pageParamValue).toEqual('');
});
-
- describe('Monaco editor', () => {
- it('initializes the Source Editor', () => {
- utils.initSourceEditor({ el: editorEl });
- expect(Editor).toHaveBeenCalledWith({
- scrollbar: {
- alwaysConsumeMouseWheel: false,
- },
- });
- });
-
- it.each([[{}], [{ blobPath, blobContent, blobGlobalId }]])(
- 'creates the instance with the passed parameters %s',
- (extraParams) => {
- const params = {
- el: editorEl,
- ...extraParams,
- };
-
- expect(Editor.prototype.createInstance).not.toHaveBeenCalled();
-
- utils.initSourceEditor(params);
-
- expect(Editor.prototype.createInstance).toHaveBeenCalledWith(params);
- },
- );
+ it('returns empty string if page is equal 1', () => {
+ const pageParamValue = utils.getPageParamValue(1000, 1000);
+ expect(pageParamValue).toEqual('');
+ });
+ it('returns correct page parameter value', () => {
+ const pageParamValue = utils.getPageParamValue(1001, 1000);
+ expect(pageParamValue).toEqual(2);
+ });
+ it('accepts strings as a parameter and returns correct result', () => {
+ const pageParamValue = utils.getPageParamValue('1001', '1000');
+ expect(pageParamValue).toEqual(2);
+ });
+ });
+ describe('getPageSearchString', () => {
+ it('returns empty search string if page parameter is empty value', () => {
+ const path = utils.getPageSearchString('/blamePath', '');
+ expect(path).toEqual('');
+ });
+ it('returns correct search string if value is provided', () => {
+ const searchString = utils.getPageSearchString('/blamePath', 3);
+ expect(searchString).toEqual('?page=3');
});
});
});