diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/frontend/lib/utils/array_utility_spec.js | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/frontend/lib/utils/array_utility_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/array_utility_spec.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/array_utility_spec.js b/spec/frontend/lib/utils/array_utility_spec.js new file mode 100644 index 00000000000..b95286ff254 --- /dev/null +++ b/spec/frontend/lib/utils/array_utility_spec.js @@ -0,0 +1,32 @@ +import * as arrayUtils from '~/lib/utils/array_utility'; + +describe('array_utility', () => { + describe('swapArrayItems', () => { + it.each` + array | leftIndex | rightIndex | result + ${[]} | ${0} | ${0} | ${[]} + ${[1]} | ${0} | ${1} | ${[1]} + ${[1, 2]} | ${0} | ${0} | ${[1, 2]} + ${[1, 2]} | ${0} | ${1} | ${[2, 1]} + ${[1, 2]} | ${1} | ${2} | ${[1, 2]} + ${[1, 2]} | ${2} | ${1} | ${[1, 2]} + ${[1, 2]} | ${1} | ${10} | ${[1, 2]} + ${[1, 2]} | ${10} | ${1} | ${[1, 2]} + ${[1, 2]} | ${1} | ${-1} | ${[1, 2]} + ${[1, 2]} | ${-1} | ${1} | ${[1, 2]} + ${[1, 2, 3]} | ${1} | ${1} | ${[1, 2, 3]} + ${[1, 2, 3]} | ${0} | ${2} | ${[3, 2, 1]} + ${[1, 2, 3, 4]} | ${0} | ${2} | ${[3, 2, 1, 4]} + ${[1, 2, 3, 4, 5]} | ${0} | ${4} | ${[5, 2, 3, 4, 1]} + ${[1, 2, 3, 4, 5]} | ${1} | ${2} | ${[1, 3, 2, 4, 5]} + ${[1, 2, 3, 4, 5]} | ${2} | ${1} | ${[1, 3, 2, 4, 5]} + `( + 'given $array with index $leftIndex and $rightIndex will return $result', + ({ array, leftIndex, rightIndex, result }) => { + const actual = arrayUtils.swapArrayItems(array, leftIndex, rightIndex); + expect(actual).toEqual(result); + expect(actual).not.toBe(array); + }, + ); + }); +}); |