summaryrefslogtreecommitdiff
path: root/spec/frontend/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/lib')
-rw-r--r--spec/frontend/lib/utils/datetime_utility_spec.js17
-rw-r--r--spec/frontend/lib/utils/number_utility_spec.js4
-rw-r--r--spec/frontend/lib/utils/table_utility_spec.js11
-rw-r--r--spec/frontend/lib/utils/url_utility_spec.js88
4 files changed, 63 insertions, 57 deletions
diff --git a/spec/frontend/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js
index 6180cd8e94d..df0ccb19cb7 100644
--- a/spec/frontend/lib/utils/datetime_utility_spec.js
+++ b/spec/frontend/lib/utils/datetime_utility_spec.js
@@ -101,13 +101,13 @@ describe('Date time utils', () => {
it('should format date properly', () => {
const formattedDate = datetimeUtility.formatDate(new Date('07/23/2016'));
- expect(formattedDate).toBe('Jul 23, 2016 12:00am GMT+0000');
+ expect(formattedDate).toBe('Jul 23, 2016 12:00am UTC');
});
it('should format ISO date properly', () => {
const formattedDate = datetimeUtility.formatDate('2016-07-23T00:00:00.559Z');
- expect(formattedDate).toBe('Jul 23, 2016 12:00am GMT+0000');
+ expect(formattedDate).toBe('Jul 23, 2016 12:00am UTC');
});
it('should throw an error if date is invalid', () => {
@@ -878,7 +878,7 @@ describe('localTimeAgo', () => {
it.each`
timeagoArg | title
${false} | ${'some time'}
- ${true} | ${'Feb 18, 2020 10:22pm GMT+0000'}
+ ${true} | ${'Feb 18, 2020 10:22pm UTC'}
`('converts $seconds seconds to $approximation', ({ timeagoArg, title }) => {
const element = document.querySelector('time');
datetimeUtility.localTimeAgo($(element), timeagoArg);
@@ -889,17 +889,6 @@ describe('localTimeAgo', () => {
});
});
-describe('dateFromParams', () => {
- it('returns the expected date object', () => {
- const expectedDate = new Date('2019-07-17T00:00:00.000Z');
- const date = datetimeUtility.dateFromParams(2019, 6, 17);
-
- expect(date.getYear()).toBe(expectedDate.getYear());
- expect(date.getMonth()).toBe(expectedDate.getMonth());
- expect(date.getDate()).toBe(expectedDate.getDate());
- });
-});
-
describe('differenceInSeconds', () => {
const startDateTime = new Date('2019-07-17T00:00:00.000Z');
diff --git a/spec/frontend/lib/utils/number_utility_spec.js b/spec/frontend/lib/utils/number_utility_spec.js
index f4483f5098b..e743678ea90 100644
--- a/spec/frontend/lib/utils/number_utility_spec.js
+++ b/spec/frontend/lib/utils/number_utility_spec.js
@@ -80,18 +80,22 @@ describe('Number Utils', () => {
describe('numberToHumanSize', () => {
it('should return bytes', () => {
expect(numberToHumanSize(654)).toEqual('654 bytes');
+ expect(numberToHumanSize(-654)).toEqual('-654 bytes');
});
it('should return KiB', () => {
expect(numberToHumanSize(1079)).toEqual('1.05 KiB');
+ expect(numberToHumanSize(-1079)).toEqual('-1.05 KiB');
});
it('should return MiB', () => {
expect(numberToHumanSize(10485764)).toEqual('10.00 MiB');
+ expect(numberToHumanSize(-10485764)).toEqual('-10.00 MiB');
});
it('should return GiB', () => {
expect(numberToHumanSize(10737418240)).toEqual('10.00 GiB');
+ expect(numberToHumanSize(-10737418240)).toEqual('-10.00 GiB');
});
});
diff --git a/spec/frontend/lib/utils/table_utility_spec.js b/spec/frontend/lib/utils/table_utility_spec.js
new file mode 100644
index 00000000000..75b9252aa40
--- /dev/null
+++ b/spec/frontend/lib/utils/table_utility_spec.js
@@ -0,0 +1,11 @@
+import { DEFAULT_TH_CLASSES } from '~/lib/utils/constants';
+import * as tableUtils from '~/lib/utils/table_utility';
+
+describe('table_utility', () => {
+ describe('thWidthClass', () => {
+ it('returns the width class including default table header classes', () => {
+ const width = 50;
+ expect(tableUtils.thWidthClass(width)).toBe(`gl-w-${width}p ${DEFAULT_TH_CLASSES}`);
+ });
+ });
+});
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index e12cd8b0e37..305d3de3c53 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -471,6 +471,7 @@ describe('URL utility', () => {
${'notaurl'} | ${false}
${'../relative_url'} | ${false}
${'<a></a>'} | ${false}
+ ${'//other-host.test'} | ${false}
`('returns $valid for $url', ({ url, valid }) => {
expect(urlUtils.isRootRelative(url)).toBe(valid);
});
@@ -650,45 +651,24 @@ describe('URL utility', () => {
});
describe('queryToObject', () => {
- it('converts search query into an object', () => {
- const searchQuery = '?one=1&two=2';
-
- expect(urlUtils.queryToObject(searchQuery)).toEqual({ one: '1', two: '2' });
- });
-
- it('removes undefined values from the search query', () => {
- const searchQuery = '?one=1&two=2&three';
-
- expect(urlUtils.queryToObject(searchQuery)).toEqual({ one: '1', two: '2' });
- });
-
- describe('with gatherArrays=false', () => {
- it('overwrites values with the same array-key and does not change the key', () => {
- const searchQuery = '?one[]=1&one[]=2&two=2&two=3';
-
- expect(urlUtils.queryToObject(searchQuery)).toEqual({ 'one[]': '2', two: '3' });
- });
- });
-
- describe('with gatherArrays=true', () => {
- const options = { gatherArrays: true };
- it('gathers only values with the same array-key and strips `[]` from the key', () => {
- const searchQuery = '?one[]=1&one[]=2&two=2&two=3';
-
- expect(urlUtils.queryToObject(searchQuery, options)).toEqual({ one: ['1', '2'], two: '3' });
- });
-
- it('overwrites values with the same array-key name', () => {
- const searchQuery = '?one=1&one[]=2&two=2&two=3';
-
- expect(urlUtils.queryToObject(searchQuery, options)).toEqual({ one: ['2'], two: '3' });
- });
-
- it('overwrites values with the same key name', () => {
- const searchQuery = '?one[]=1&one=2&two=2&two=3';
-
- expect(urlUtils.queryToObject(searchQuery, options)).toEqual({ one: '2', two: '3' });
- });
+ it.each`
+ case | query | options | result
+ ${'converts query'} | ${'?one=1&two=2'} | ${undefined} | ${{ one: '1', two: '2' }}
+ ${'converts query without ?'} | ${'one=1&two=2'} | ${undefined} | ${{ one: '1', two: '2' }}
+ ${'removes undefined values'} | ${'?one=1&two=2&three'} | ${undefined} | ${{ one: '1', two: '2' }}
+ ${'overwrites values with same key and does not change key'} | ${'?one[]=1&one[]=2&two=2&two=3'} | ${undefined} | ${{ 'one[]': '2', two: '3' }}
+ ${'gathers values with the same array-key, strips `[]` from key'} | ${'?one[]=1&one[]=2&two=2&two=3'} | ${{ gatherArrays: true }} | ${{ one: ['1', '2'], two: '3' }}
+ ${'overwrites values with the same array-key name'} | ${'?one=1&one[]=2&two=2&two=3'} | ${{ gatherArrays: true }} | ${{ one: ['2'], two: '3' }}
+ ${'overwrites values with the same key name'} | ${'?one[]=1&one=2&two=2&two=3'} | ${{ gatherArrays: true }} | ${{ one: '2', two: '3' }}
+ ${'ignores plus symbols'} | ${'?search=a+b'} | ${{ legacySpacesDecode: true }} | ${{ search: 'a+b' }}
+ ${'ignores plus symbols in keys'} | ${'?search+term=a'} | ${{ legacySpacesDecode: true }} | ${{ 'search+term': 'a' }}
+ ${'ignores plus symbols when gathering arrays'} | ${'?search[]=a+b'} | ${{ gatherArrays: true, legacySpacesDecode: true }} | ${{ search: ['a+b'] }}
+ ${'replaces plus symbols with spaces'} | ${'?search=a+b'} | ${undefined} | ${{ search: 'a b' }}
+ ${'replaces plus symbols in keys with spaces'} | ${'?search+term=a'} | ${undefined} | ${{ 'search term': 'a' }}
+ ${'replaces plus symbols when gathering arrays'} | ${'?search[]=a+b'} | ${{ gatherArrays: true }} | ${{ search: ['a b'] }}
+ ${'replaces plus symbols when gathering arrays for values with same key'} | ${'?search[]=a+b&search[]=c+d'} | ${{ gatherArrays: true }} | ${{ search: ['a b', 'c d'] }}
+ `('$case', ({ query, options, result }) => {
+ expect(urlUtils.queryToObject(query, options)).toEqual(result);
});
});
@@ -798,15 +778,29 @@ describe('URL utility', () => {
);
});
- it('handles arrays properly', () => {
+ it('adds parameters from arrays', () => {
const url = 'https://gitlab.com/test';
- expect(urlUtils.setUrlParams({ label_name: ['foo', 'bar'] }, url)).toEqual(
- 'https://gitlab.com/test?label_name=foo&label_name=bar',
+ expect(urlUtils.setUrlParams({ labels: ['foo', 'bar'] }, url)).toEqual(
+ 'https://gitlab.com/test?labels=foo&labels=bar',
);
});
- it('handles arrays properly when railsArraySyntax=true', () => {
+ it('removes parameters from empty arrays', () => {
+ const url = 'https://gitlab.com/test?labels=foo&labels=bar';
+
+ expect(urlUtils.setUrlParams({ labels: [] }, url)).toEqual('https://gitlab.com/test');
+ });
+
+ it('removes parameters from empty arrays while keeping other parameters', () => {
+ const url = 'https://gitlab.com/test?labels=foo&labels=bar&unrelated=unrelated';
+
+ expect(urlUtils.setUrlParams({ labels: [] }, url)).toEqual(
+ 'https://gitlab.com/test?unrelated=unrelated',
+ );
+ });
+
+ it('adds parameters from arrays when railsArraySyntax=true', () => {
const url = 'https://gitlab.com/test';
expect(urlUtils.setUrlParams({ labels: ['foo', 'bar'] }, url, false, true)).toEqual(
@@ -814,6 +808,14 @@ describe('URL utility', () => {
);
});
+ it('removes parameters from empty arrays when railsArraySyntax=true', () => {
+ const url = 'https://gitlab.com/test?labels%5B%5D=foo&labels%5B%5D=bar';
+
+ expect(urlUtils.setUrlParams({ labels: [] }, url, false, true)).toEqual(
+ 'https://gitlab.com/test',
+ );
+ });
+
it('decodes URI when decodeURI=true', () => {
const url = 'https://gitlab.com/test';