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/apollo_startup_js_link_spec.js2
-rw-r--r--spec/frontend/lib/utils/common_utils_spec.js2
-rw-r--r--spec/frontend/lib/utils/datetime/date_calculation_utility_spec.js18
-rw-r--r--spec/frontend/lib/utils/finite_state_machine_spec.js4
-rw-r--r--spec/frontend/lib/utils/is_navigating_away_spec.js2
-rw-r--r--spec/frontend/lib/utils/navigation_utility_spec.js2
-rw-r--r--spec/frontend/lib/utils/poll_spec.js4
-rw-r--r--spec/frontend/lib/utils/text_markdown_spec.js27
-rw-r--r--spec/frontend/lib/utils/text_utility_spec.js35
-rw-r--r--spec/frontend/lib/utils/vuex_module_mappers_spec.js2
10 files changed, 66 insertions, 32 deletions
diff --git a/spec/frontend/lib/utils/apollo_startup_js_link_spec.js b/spec/frontend/lib/utils/apollo_startup_js_link_spec.js
index 06573f346e0..b972f669ac4 100644
--- a/spec/frontend/lib/utils/apollo_startup_js_link_spec.js
+++ b/spec/frontend/lib/utils/apollo_startup_js_link_spec.js
@@ -84,7 +84,7 @@ describe('StartupJSLink', () => {
});
});
- describe('variable match errors: ', () => {
+ describe('variable match errors:', () => {
it('forwards requests if the variables are not matching', () => {
window.gl = {
startup_graphql_calls: [
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js
index a2ace8857ed..a0140d1d8a8 100644
--- a/spec/frontend/lib/utils/common_utils_spec.js
+++ b/spec/frontend/lib/utils/common_utils_spec.js
@@ -476,7 +476,7 @@ describe('common_utils', () => {
});
});
- it('catches the rejected promise from the callback ', () => {
+ it('catches the rejected promise from the callback', () => {
const errorMessage = 'Mistakes were made!';
return commonUtils
.backOff((next, stop) => {
diff --git a/spec/frontend/lib/utils/datetime/date_calculation_utility_spec.js b/spec/frontend/lib/utils/datetime/date_calculation_utility_spec.js
index 47bb512cbb5..59b3b4c02df 100644
--- a/spec/frontend/lib/utils/datetime/date_calculation_utility_spec.js
+++ b/spec/frontend/lib/utils/datetime/date_calculation_utility_spec.js
@@ -1,4 +1,4 @@
-import { newDateAsLocaleTime } from '~/lib/utils/datetime/date_calculation_utility';
+import { getDateWithUTC, newDateAsLocaleTime } from '~/lib/utils/datetime/date_calculation_utility';
describe('newDateAsLocaleTime', () => {
it.each`
@@ -15,3 +15,19 @@ describe('newDateAsLocaleTime', () => {
expect(newDateAsLocaleTime(string)).toEqual(expected);
});
});
+
+describe('getDateWithUTC', () => {
+ it.each`
+ date | expected
+ ${new Date('2022-03-22T01:23:45.678Z')} | ${new Date('2022-03-22T00:00:00.000Z')}
+ ${new Date('1999-12-31T23:59:59.999Z')} | ${new Date('1999-12-31T00:00:00.000Z')}
+ ${2022} | ${null}
+ ${[]} | ${null}
+ ${{}} | ${null}
+ ${true} | ${null}
+ ${null} | ${null}
+ ${undefined} | ${null}
+ `('returns $expected given $string', ({ date, expected }) => {
+ expect(getDateWithUTC(date)).toEqual(expected);
+ });
+});
diff --git a/spec/frontend/lib/utils/finite_state_machine_spec.js b/spec/frontend/lib/utils/finite_state_machine_spec.js
index 441dd24c758..cfde3b8596e 100644
--- a/spec/frontend/lib/utils/finite_state_machine_spec.js
+++ b/spec/frontend/lib/utils/finite_state_machine_spec.js
@@ -50,13 +50,13 @@ describe('Finite State Machine', () => {
});
it('throws an error if the machine definition is invalid', () => {
- expect(() => machine(badDefinition)).toThrowError(
+ expect(() => machine(badDefinition)).toThrow(
'A state machine must have an initial state (`.initial`) and a dictionary of possible states (`.states`)',
);
});
it('throws an error if the initial state is invalid', () => {
- expect(() => machine(unstartableDefinition)).toThrowError(
+ expect(() => machine(unstartableDefinition)).toThrow(
`Cannot initialize the state machine to state '${STATE_IMPOSSIBLE}'. Is that one of the machine's defined states?`,
);
});
diff --git a/spec/frontend/lib/utils/is_navigating_away_spec.js b/spec/frontend/lib/utils/is_navigating_away_spec.js
index e1230fe96bf..b8a01a1706c 100644
--- a/spec/frontend/lib/utils/is_navigating_away_spec.js
+++ b/spec/frontend/lib/utils/is_navigating_away_spec.js
@@ -6,7 +6,7 @@ describe('isNavigatingAway', () => {
setNavigatingForTestsOnly(false);
});
- it.each([false, true])('it returns the navigation flag with value %s', (flag) => {
+ it.each([false, true])('returns the navigation flag with value %s', (flag) => {
setNavigatingForTestsOnly(flag);
expect(isNavigatingAway()).toEqual(flag);
});
diff --git a/spec/frontend/lib/utils/navigation_utility_spec.js b/spec/frontend/lib/utils/navigation_utility_spec.js
index 6d3a871eb33..4dbd50223d5 100644
--- a/spec/frontend/lib/utils/navigation_utility_spec.js
+++ b/spec/frontend/lib/utils/navigation_utility_spec.js
@@ -63,7 +63,7 @@ describe('initPrefetchLinks', () => {
expect(newLink.addEventListener).toHaveBeenCalled();
});
- it('it is not fired when less then 100ms over link', () => {
+ it('is not fired when less then 100ms over link', () => {
const mouseOverEvent = new Event('mouseover');
const mouseOutEvent = new Event('mouseout');
diff --git a/spec/frontend/lib/utils/poll_spec.js b/spec/frontend/lib/utils/poll_spec.js
index 1f150599983..94a5f5385b7 100644
--- a/spec/frontend/lib/utils/poll_spec.js
+++ b/spec/frontend/lib/utils/poll_spec.js
@@ -128,9 +128,11 @@ describe('Poll', () => {
errorCallback: callbacks.error,
});
+ expect(Polling.timeoutID).toBeNull();
+
Polling.makeDelayedRequest(1);
- expect(Polling.timeoutID).toBeTruthy();
+ expect(Polling.timeoutID).not.toBeNull();
return waitForAllCallsToFinish(2, () => {
Polling.stop();
diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js
index 733d89fe08c..8d179baa505 100644
--- a/spec/frontend/lib/utils/text_markdown_spec.js
+++ b/spec/frontend/lib/utils/text_markdown_spec.js
@@ -586,6 +586,33 @@ describe('init markdown', () => {
);
});
+ it('only converts valid URLs', () => {
+ const notValidUrl = 'group::label';
+ const expectedUrlValue = 'url';
+ const expectedText = `other [${notValidUrl}](${expectedUrlValue}) text`;
+ const initialValue = `other ${notValidUrl} text`;
+
+ textArea.value = initialValue;
+ selectedIndex = initialValue.indexOf(notValidUrl);
+ textArea.setSelectionRange(selectedIndex, selectedIndex + notValidUrl.length);
+
+ insertMarkdownText({
+ textArea,
+ text: textArea.value,
+ tag,
+ blockTag: null,
+ selected: notValidUrl,
+ wrap: false,
+ select,
+ });
+
+ expect(textArea.value).toEqual(expectedText);
+ expect(textArea.selectionStart).toEqual(expectedText.indexOf(expectedUrlValue, 1));
+ expect(textArea.selectionEnd).toEqual(
+ expectedText.indexOf(expectedUrlValue, 1) + expectedUrlValue.length,
+ );
+ });
+
it('adds block tags on line above and below selection', () => {
selected = 'this text\nis multiple\nlines';
text = `before \n${selected}\nafter `;
diff --git a/spec/frontend/lib/utils/text_utility_spec.js b/spec/frontend/lib/utils/text_utility_spec.js
index 8e31fc792c5..49a160c9f23 100644
--- a/spec/frontend/lib/utils/text_utility_spec.js
+++ b/spec/frontend/lib/utils/text_utility_spec.js
@@ -45,29 +45,18 @@ describe('text_utility', () => {
});
describe('slugify', () => {
- it('should remove accents and convert to lower case', () => {
- expect(textUtils.slugify('João')).toEqual('jo-o');
- });
- it('should replaces whitespaces with hyphens and convert to lower case', () => {
- expect(textUtils.slugify('My Input String')).toEqual('my-input-string');
- });
- it('should remove trailing whitespace and replace whitespaces within string with a hyphen', () => {
- expect(textUtils.slugify(' a new project ')).toEqual('a-new-project');
- });
- it('should only remove non-allowed special characters', () => {
- expect(textUtils.slugify('test!_pro-ject~')).toEqual('test-_pro-ject');
- });
- it('should squash multiple hypens', () => {
- expect(textUtils.slugify('test!!!!_pro-ject~')).toEqual('test-_pro-ject');
- });
- it('should return empty string if only non-allowed characters', () => {
- expect(textUtils.slugify('здрасти')).toEqual('');
- });
- it('should squash multiple separators', () => {
- expect(textUtils.slugify('Test:-)')).toEqual('test');
- });
- it('should trim any separators from the beginning and end of the slug', () => {
- expect(textUtils.slugify('-Test:-)-')).toEqual('test');
+ it.each`
+ title | input | output
+ ${'should remove accents and convert to lower case'} | ${'João'} | ${'jo-o'}
+ ${'should replaces whitespaces with hyphens and convert to lower case'} | ${'My Input String'} | ${'my-input-string'}
+ ${'should remove trailing whitespace and replace whitespaces within string with a hyphen'} | ${' a new project '} | ${'a-new-project'}
+ ${'should only remove non-allowed special characters'} | ${'test!_pro-ject~'} | ${'test-_pro-ject'}
+ ${'should squash to multiple non-allowed special characters'} | ${'test!!!!_pro-ject~'} | ${'test-_pro-ject'}
+ ${'should return empty string if only non-allowed characters'} | ${'дружба'} | ${''}
+ ${'should squash multiple separators'} | ${'Test:-)'} | ${'test'}
+ ${'should trim any separators from the beginning and end of the slug'} | ${'-Test:-)-'} | ${'test'}
+ `('$title', ({ input, output }) => {
+ expect(textUtils.slugify(input)).toBe(output);
});
});
diff --git a/spec/frontend/lib/utils/vuex_module_mappers_spec.js b/spec/frontend/lib/utils/vuex_module_mappers_spec.js
index 1821a15f677..d25a692dfea 100644
--- a/spec/frontend/lib/utils/vuex_module_mappers_spec.js
+++ b/spec/frontend/lib/utils/vuex_module_mappers_spec.js
@@ -128,7 +128,7 @@ describe('~/lib/utils/vuex_module_mappers', () => {
describe('with non-string object value', () => {
it('throws helpful error', () => {
- expect(() => mapVuexModuleActions((vm) => vm.bogus, { foo: () => {} })).toThrowError(
+ expect(() => mapVuexModuleActions((vm) => vm.bogus, { foo: () => {} })).toThrow(
REQUIRE_STRING_ERROR_MESSAGE,
);
});