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/lib/utils')
-rw-r--r--spec/frontend/lib/utils/common_utils_spec.js81
-rw-r--r--spec/frontend/lib/utils/text_markdown_spec.js16
-rw-r--r--spec/frontend/lib/utils/text_utility_spec.js16
-rw-r--r--spec/frontend/lib/utils/url_utility_spec.js17
4 files changed, 122 insertions, 8 deletions
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js
index c8dc90c9ace..f597255538c 100644
--- a/spec/frontend/lib/utils/common_utils_spec.js
+++ b/spec/frontend/lib/utils/common_utils_spec.js
@@ -1,4 +1,5 @@
import * as commonUtils from '~/lib/utils/common_utils';
+import $ from 'jquery';
describe('common_utils', () => {
describe('parseUrl', () => {
@@ -211,6 +212,59 @@ describe('common_utils', () => {
});
});
+ describe('scrollToElement*', () => {
+ let elem;
+ const windowHeight = 1000;
+ const elemTop = 100;
+
+ beforeEach(() => {
+ elem = document.createElement('div');
+ window.innerHeight = windowHeight;
+ jest.spyOn($.fn, 'animate');
+ jest.spyOn($.fn, 'offset').mockReturnValue({ top: elemTop });
+ });
+
+ afterEach(() => {
+ $.fn.animate.mockRestore();
+ $.fn.offset.mockRestore();
+ });
+
+ describe('scrollToElement', () => {
+ it('scrolls to element', () => {
+ commonUtils.scrollToElement(elem);
+ expect($.fn.animate).toHaveBeenCalledWith(
+ {
+ scrollTop: elemTop,
+ },
+ expect.any(Number),
+ );
+ });
+
+ it('scrolls to element with offset', () => {
+ const offset = 50;
+ commonUtils.scrollToElement(elem, { offset });
+ expect($.fn.animate).toHaveBeenCalledWith(
+ {
+ scrollTop: elemTop + offset,
+ },
+ expect.any(Number),
+ );
+ });
+ });
+
+ describe('scrollToElementWithContext', () => {
+ it('scrolls with context', () => {
+ commonUtils.scrollToElementWithContext();
+ expect($.fn.animate).toHaveBeenCalledWith(
+ {
+ scrollTop: elemTop - windowHeight * 0.1,
+ },
+ expect.any(Number),
+ );
+ });
+ });
+ });
+
describe('debounceByAnimationFrame', () => {
it('debounces a function to allow a maximum of one call per animation frame', done => {
const spy = jest.fn();
@@ -535,6 +589,7 @@ describe('common_utils', () => {
id: 1,
group_name: 'GitLab.org',
absolute_web_url: 'https://gitlab.com/gitlab-org/',
+ milestones: ['12.3', '12.4'],
},
objNested: {
project_name: 'GitLab CE',
@@ -545,6 +600,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
},
convertObjectPropsToCamelCase: {
@@ -552,6 +608,7 @@ describe('common_utils', () => {
id: 1,
group_name: 'GitLab.org',
absolute_web_url: 'https://gitlab.com/gitlab-org/',
+ milestones: ['12.3', '12.4'],
},
objNested: {
project_name: 'GitLab CE',
@@ -562,6 +619,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
},
convertObjectPropsToSnakeCase: {
@@ -569,6 +627,7 @@ describe('common_utils', () => {
id: 1,
groupName: 'GitLab.org',
absoluteWebUrl: 'https://gitlab.com/gitlab-org/',
+ milestones: ['12.3', '12.4'],
},
objNested: {
projectName: 'GitLab CE',
@@ -579,6 +638,7 @@ describe('common_utils', () => {
frontendFramework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
},
};
@@ -615,16 +675,19 @@ describe('common_utils', () => {
id_converted: 1,
group_name_converted: 'GitLab.org',
absolute_web_url_converted: 'https://gitlab.com/gitlab-org/',
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
id: 1,
groupName: 'GitLab.org',
absoluteWebUrl: 'https://gitlab.com/gitlab-org/',
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
id: 1,
group_name: 'GitLab.org',
absolute_web_url: 'https://gitlab.com/gitlab-org/',
+ milestones: ['12.3', '12.4'],
},
};
@@ -642,6 +705,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
projectName: 'GitLab CE',
@@ -652,6 +716,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
project_name: 'GitLab CE',
@@ -662,6 +727,7 @@ describe('common_utils', () => {
frontendFramework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
};
@@ -680,6 +746,7 @@ describe('common_utils', () => {
frontend_framework_converted: 'Vue',
database_converted: 'PostgreSQL',
},
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
projectName: 'GitLab CE',
@@ -690,6 +757,7 @@ describe('common_utils', () => {
frontendFramework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
project_name: 'GitLab CE',
@@ -700,6 +768,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
};
@@ -729,6 +798,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
projectName: 'GitLab CE',
@@ -738,6 +808,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
project_name: 'GitLab CE',
@@ -747,6 +818,7 @@ describe('common_utils', () => {
frontendFramework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
};
@@ -772,6 +844,7 @@ describe('common_utils', () => {
backend_converted: 'Ruby',
frontend_framework_converted: 'Vue',
},
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
projectName: 'GitLab CE',
@@ -780,6 +853,7 @@ describe('common_utils', () => {
backend: 'Ruby',
frontendFramework: 'Vue',
},
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
project_name: 'GitLab CE',
@@ -788,6 +862,7 @@ describe('common_utils', () => {
backend: 'Ruby',
frontend_framework: 'Vue',
},
+ milestones: ['12.3', '12.4'],
},
};
@@ -818,6 +893,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
projectName: 'GitLab CE',
@@ -828,6 +904,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
project_name: 'GitLab CE',
@@ -838,6 +915,7 @@ describe('common_utils', () => {
frontendFramework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
};
@@ -865,6 +943,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database_converted: 'PostgreSQL',
},
+ milestones_converted: ['12.3', '12.4'],
},
convertObjectPropsToCamelCase: {
projectName: 'GitLab CE',
@@ -875,6 +954,7 @@ describe('common_utils', () => {
frontend_framework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
convertObjectPropsToSnakeCase: {
project_name: 'GitLab CE',
@@ -885,6 +965,7 @@ describe('common_utils', () => {
frontendFramework: 'Vue',
database: 'PostgreSQL',
},
+ milestones: ['12.3', '12.4'],
},
};
diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js
index 1d616a7da0b..aca299aea0f 100644
--- a/spec/frontend/lib/utils/text_markdown_spec.js
+++ b/spec/frontend/lib/utils/text_markdown_spec.js
@@ -25,13 +25,13 @@ describe('init markdown', () => {
insertMarkdownText({
textArea,
text: textArea.value,
- tag: '* ',
+ tag: '- ',
blockTag: null,
selected: '',
wrap: false,
});
- expect(textArea.value).toEqual(`${initialValue}* `);
+ expect(textArea.value).toEqual(`${initialValue}- `);
});
it('inserts the tag on a new line if the current one is not empty', () => {
@@ -43,13 +43,13 @@ describe('init markdown', () => {
insertMarkdownText({
textArea,
text: textArea.value,
- tag: '* ',
+ tag: '- ',
blockTag: null,
selected: '',
wrap: false,
});
- expect(textArea.value).toEqual(`${initialValue}\n* `);
+ expect(textArea.value).toEqual(`${initialValue}\n- `);
});
it('inserts the tag on the same line if the current line only contains spaces', () => {
@@ -61,13 +61,13 @@ describe('init markdown', () => {
insertMarkdownText({
textArea,
text: textArea.value,
- tag: '* ',
+ tag: '- ',
blockTag: null,
selected: '',
wrap: false,
});
- expect(textArea.value).toEqual(`${initialValue}* `);
+ expect(textArea.value).toEqual(`${initialValue}- `);
});
it('inserts the tag on the same line if the current line only contains tabs', () => {
@@ -79,13 +79,13 @@ describe('init markdown', () => {
insertMarkdownText({
textArea,
text: textArea.value,
- tag: '* ',
+ tag: '- ',
blockTag: null,
selected: '',
wrap: false,
});
- expect(textArea.value).toEqual(`${initialValue}* `);
+ expect(textArea.value).toEqual(`${initialValue}- `);
});
it('places the cursor inside the tags', () => {
diff --git a/spec/frontend/lib/utils/text_utility_spec.js b/spec/frontend/lib/utils/text_utility_spec.js
index 4969c591dcd..76e0e435860 100644
--- a/spec/frontend/lib/utils/text_utility_spec.js
+++ b/spec/frontend/lib/utils/text_utility_spec.js
@@ -126,6 +126,8 @@ describe('text_utility', () => {
${'snake case'} | ${'snake_case'}
${'snake_case'} | ${'snake_case'}
${'snakeCasesnake Case'} | ${'snake_casesnake_case'}
+ ${'123'} | ${'123'}
+ ${'123 456'} | ${'123_456'}
`('converts string $txt to $result string', ({ txt, result }) => {
expect(textUtils.convertToSnakeCase(txt)).toEqual(result);
});
@@ -190,6 +192,20 @@ describe('text_utility', () => {
'app/…/…/diff',
);
});
+
+ describe('given a path too long for the maxWidth', () => {
+ it.each`
+ path | maxWidth | result
+ ${'aa/bb/cc'} | ${1} | ${'…'}
+ ${'aa/bb/cc'} | ${2} | ${'…'}
+ ${'aa/bb/cc'} | ${3} | ${'…/…'}
+ ${'aa/bb/cc'} | ${4} | ${'…/…'}
+ ${'aa/bb/cc'} | ${5} | ${'…/…/…'}
+ `('truncates ($path, $maxWidth) to $result', ({ path, maxWidth, result }) => {
+ expect(result.length).toBeLessThanOrEqual(maxWidth);
+ expect(textUtils.truncatePathMiddleToLength(path, maxWidth)).toEqual(result);
+ });
+ });
});
describe('slugifyWithUnderscore', () => {
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index c494033badd..85e680fe216 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -371,6 +371,23 @@ describe('URL utility', () => {
});
});
+ describe('isBase64DataUrl', () => {
+ it.each`
+ url | valid
+ ${undefined} | ${false}
+ ${'http://gitlab.com'} | ${false}
+ ${'data:image/png;base64,abcdef'} | ${true}
+ ${'data:application/smil+xml;base64,abcdef'} | ${true}
+ ${'data:application/vnd.syncml+xml;base64,abcdef'} | ${true}
+ ${'data:application/vnd.3m.post-it-notes;base64,abcdef'} | ${true}
+ ${'notaurl'} | ${false}
+ ${'../relative_url'} | ${false}
+ ${'<a></a>'} | ${false}
+ `('returns $valid for $url', ({ url, valid }) => {
+ expect(urlUtils.isBase64DataUrl(url)).toBe(valid);
+ });
+ });
+
describe('relativePathToAbsolute', () => {
it.each`
path | base | result