diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-15 06:06:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-15 06:06:13 +0000 |
commit | 3fe34368770022c88fd89c8df58b39bf0789e646 (patch) | |
tree | 0b8aa07f8b17e4565c491383b5b8b6cc728a1e4a /spec/frontend/lib | |
parent | 41d446ba3f0518097eb350b142ecfbeeb6be83e6 (diff) | |
download | gitlab-ce-3fe34368770022c88fd89c8df58b39bf0789e646.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/lib')
-rw-r--r-- | spec/frontend/lib/utils/chart_utils_spec.js | 11 | ||||
-rw-r--r-- | spec/frontend/lib/utils/number_utility_spec.js | 40 |
2 files changed, 51 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/chart_utils_spec.js b/spec/frontend/lib/utils/chart_utils_spec.js new file mode 100644 index 00000000000..e811b8405fb --- /dev/null +++ b/spec/frontend/lib/utils/chart_utils_spec.js @@ -0,0 +1,11 @@ +import { firstAndLastY } from '~/lib/utils/chart_utils'; + +describe('Chart utils', () => { + describe('firstAndLastY', () => { + it('returns the first and last y-values of a given data set as an array', () => { + const data = [['', 1], ['', 2], ['', 3]]; + + expect(firstAndLastY(data)).toEqual([1, 3]); + }); + }); +}); diff --git a/spec/frontend/lib/utils/number_utility_spec.js b/spec/frontend/lib/utils/number_utility_spec.js index 381d7c6f8d9..2f8f1092612 100644 --- a/spec/frontend/lib/utils/number_utility_spec.js +++ b/spec/frontend/lib/utils/number_utility_spec.js @@ -7,6 +7,8 @@ import { sum, isOdd, median, + changeInPercent, + formattedChangeInPercent, } from '~/lib/utils/number_utils'; describe('Number Utils', () => { @@ -122,4 +124,42 @@ describe('Number Utils', () => { expect(median(items)).toBe(14.5); }); }); + + describe('changeInPercent', () => { + it.each` + firstValue | secondValue | expectedOutput + ${99} | ${100} | ${1} + ${100} | ${99} | ${-1} + ${0} | ${99} | ${Infinity} + ${2} | ${2} | ${0} + ${-100} | ${-99} | ${1} + `( + 'computes the change between $firstValue and $secondValue in percent', + ({ firstValue, secondValue, expectedOutput }) => { + expect(changeInPercent(firstValue, secondValue)).toBe(expectedOutput); + }, + ); + }); + + describe('formattedChangeInPercent', () => { + it('prepends "%" to the output', () => { + expect(formattedChangeInPercent(1, 2)).toMatch(/%$/); + }); + + it('indicates if the change was a decrease', () => { + expect(formattedChangeInPercent(100, 99)).toContain('-1'); + }); + + it('indicates if the change was an increase', () => { + expect(formattedChangeInPercent(99, 100)).toContain('+1'); + }); + + it('shows "-" per default if the change can not be expressed in an integer', () => { + expect(formattedChangeInPercent(0, 1)).toBe('-'); + }); + + it('shows the given fallback if the change can not be expressed in an integer', () => { + expect(formattedChangeInPercent(0, 1, { nonFiniteResult: '*' })).toBe('*'); + }); + }); }); |