diff options
| author | GeoSot <[email protected]> | 2021-05-19 01:23:52 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-19 01:23:52 +0300 |
| commit | df72a21fa89a4885bb666f4a3bc0a9e757b870c2 (patch) | |
| tree | d80c2614184e53f73de9364ac46dbeef9f61aa08 /js/tests | |
| parent | 372890b67b28238c98ec4d5ffcdb777c9939e87c (diff) | |
| download | bootstrap-df72a21fa89a4885bb666f4a3bc0a9e757b870c2.tar.xz bootstrap-df72a21fa89a4885bb666f4a3bc0a9e757b870c2.zip | |
Add `getNextActiveElement` helper function to utils, replacing custom implementation through components (#33608)
Diffstat (limited to 'js/tests')
| -rw-r--r-- | js/tests/unit/util/index.spec.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index b4010e0e0..ca6430bee 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -611,4 +611,43 @@ describe('Util', () => { expect(spy).toHaveBeenCalled() }) }) + + describe('getNextActiveElement', () => { + it('should return first element if active not exists or not given', () => { + const array = ['a', 'b', 'c', 'd'] + + expect(Util.getNextActiveElement(array, '', true, true)).toEqual('a') + expect(Util.getNextActiveElement(array, 'g', true, true)).toEqual('a') + }) + + it('should return next element or same if is last', () => { + const array = ['a', 'b', 'c', 'd'] + + expect(Util.getNextActiveElement(array, 'a', true, true)).toEqual('b') + expect(Util.getNextActiveElement(array, 'b', true, true)).toEqual('c') + expect(Util.getNextActiveElement(array, 'd', true, false)).toEqual('d') + }) + + it('should return next element or first, if is last and "isCycleAllowed = true"', () => { + const array = ['a', 'b', 'c', 'd'] + + expect(Util.getNextActiveElement(array, 'c', true, true)).toEqual('d') + expect(Util.getNextActiveElement(array, 'd', true, true)).toEqual('a') + }) + + it('should return previous element or same if is first', () => { + const array = ['a', 'b', 'c', 'd'] + + expect(Util.getNextActiveElement(array, 'b', false, true)).toEqual('a') + expect(Util.getNextActiveElement(array, 'd', false, true)).toEqual('c') + expect(Util.getNextActiveElement(array, 'a', false, false)).toEqual('a') + }) + + it('should return next element or first, if is last and "isCycleAllowed = true"', () => { + const array = ['a', 'b', 'c', 'd'] + + expect(Util.getNextActiveElement(array, 'd', false, true)).toEqual('c') + expect(Util.getNextActiveElement(array, 'a', false, true)).toEqual('d') + }) + }) }) |
