123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816 |
- import * as Util from '../../../src/util/index'
- import { clearFixture, getFixture } from '../../helpers/fixture'
- describe('Util', () => {
- let fixtureEl
- beforeAll(() => {
- fixtureEl = getFixture()
- })
- afterEach(() => {
- clearFixture()
- })
- describe('getUID', () => {
- it('should generate uid', () => {
- const uid = Util.getUID('bs')
- const uid2 = Util.getUID('bs')
- expect(uid).not.toEqual(uid2)
- })
- })
- describe('getSelectorFromElement', () => {
- it('should get selector from data-bs-target', () => {
- fixtureEl.innerHTML = [
- '<div id="test" data-bs-target=".target"></div>',
- '<div class="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getSelectorFromElement(testEl)).toEqual('.target')
- })
- it('should get selector from href if no data-bs-target set', () => {
- fixtureEl.innerHTML = [
- '<a id="test" href=".target"></a>',
- '<div class="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getSelectorFromElement(testEl)).toEqual('.target')
- })
- it('should get selector from href if data-bs-target equal to #', () => {
- fixtureEl.innerHTML = [
- '<a id="test" data-bs-target="#" href=".target"></a>',
- '<div class="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getSelectorFromElement(testEl)).toEqual('.target')
- })
- it('should return null if a selector from a href is a url without an anchor', () => {
- fixtureEl.innerHTML = [
- '<a id="test" data-bs-target="#" href="foo/bar.html"></a>',
- '<div class="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getSelectorFromElement(testEl)).toBeNull()
- })
- it('should return the anchor if a selector from a href is a url', () => {
- fixtureEl.innerHTML = [
- '<a id="test" data-bs-target="#" href="foo/bar.html#target"></a>',
- '<div id="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getSelectorFromElement(testEl)).toEqual('#target')
- })
- it('should return null if selector not found', () => {
- fixtureEl.innerHTML = '<a id="test" href=".target"></a>'
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getSelectorFromElement(testEl)).toBeNull()
- })
- it('should return null if no selector', () => {
- fixtureEl.innerHTML = '<div></div>'
- const testEl = fixtureEl.querySelector('div')
- expect(Util.getSelectorFromElement(testEl)).toBeNull()
- })
- })
- describe('getElementFromSelector', () => {
- it('should get element from data-bs-target', () => {
- fixtureEl.innerHTML = [
- '<div id="test" data-bs-target=".target"></div>',
- '<div class="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getElementFromSelector(testEl)).toEqual(fixtureEl.querySelector('.target'))
- })
- it('should get element from href if no data-bs-target set', () => {
- fixtureEl.innerHTML = [
- '<a id="test" href=".target"></a>',
- '<div class="target"></div>'
- ].join('')
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getElementFromSelector(testEl)).toEqual(fixtureEl.querySelector('.target'))
- })
- it('should return null if element not found', () => {
- fixtureEl.innerHTML = '<a id="test" href=".target"></a>'
- const testEl = fixtureEl.querySelector('#test')
- expect(Util.getElementFromSelector(testEl)).toBeNull()
- })
- it('should return null if no selector', () => {
- fixtureEl.innerHTML = '<div></div>'
- const testEl = fixtureEl.querySelector('div')
- expect(Util.getElementFromSelector(testEl)).toBeNull()
- })
- })
- describe('getTransitionDurationFromElement', () => {
- it('should get transition from element', () => {
- fixtureEl.innerHTML = '<div style="transition: all 300ms ease-out;"></div>'
- expect(Util.getTransitionDurationFromElement(fixtureEl.querySelector('div'))).toEqual(300)
- })
- it('should return 0 if the element is undefined or null', () => {
- expect(Util.getTransitionDurationFromElement(null)).toEqual(0)
- expect(Util.getTransitionDurationFromElement(undefined)).toEqual(0)
- })
- it('should return 0 if the element do not possess transition', () => {
- fixtureEl.innerHTML = '<div></div>'
- expect(Util.getTransitionDurationFromElement(fixtureEl.querySelector('div'))).toEqual(0)
- })
- })
- describe('triggerTransitionEnd', () => {
- it('should trigger transitionend event', done => {
- fixtureEl.innerHTML = '<div></div>'
- const el = fixtureEl.querySelector('div')
- const spy = spyOn(el, 'dispatchEvent').and.callThrough()
- el.addEventListener('transitionend', () => {
- expect(spy).toHaveBeenCalled()
- done()
- })
- Util.triggerTransitionEnd(el)
- })
- })
- describe('isElement', () => {
- it('should detect if the parameter is an element or not and return Boolean', () => {
- fixtureEl.innerHTML =
- [
- '<div id="foo" class="test"></div>',
- '<div id="bar" class="test"></div>'
- ].join('')
- const el = fixtureEl.querySelector('#foo')
- expect(Util.isElement(el)).toEqual(true)
- expect(Util.isElement({})).toEqual(false)
- expect(Util.isElement(fixtureEl.querySelectorAll('.test'))).toEqual(false)
- })
- it('should detect jQuery element', () => {
- fixtureEl.innerHTML = '<div></div>'
- const el = fixtureEl.querySelector('div')
- const fakejQuery = {
- 0: el,
- jquery: 'foo'
- }
- expect(Util.isElement(fakejQuery)).toEqual(true)
- })
- })
- describe('getElement', () => {
- it('should try to parse element', () => {
- fixtureEl.innerHTML =
- [
- '<div id="foo" class="test"></div>',
- '<div id="bar" class="test"></div>'
- ].join('')
- const el = fixtureEl.querySelector('div')
- expect(Util.getElement(el)).toEqual(el)
- expect(Util.getElement('#foo')).toEqual(el)
- expect(Util.getElement('#fail')).toBeNull()
- expect(Util.getElement({})).toBeNull()
- expect(Util.getElement([])).toBeNull()
- expect(Util.getElement()).toBeNull()
- expect(Util.getElement(null)).toBeNull()
- expect(Util.getElement(fixtureEl.querySelectorAll('.test'))).toBeNull()
- const fakejQueryObject = {
- 0: el,
- jquery: 'foo'
- }
- expect(Util.getElement(fakejQueryObject)).toEqual(el)
- })
- })
- describe('typeCheckConfig', () => {
- const namePlugin = 'collapse'
- it('should check type of the config object', () => {
- const defaultType = {
- toggle: 'boolean',
- parent: '(string|element)'
- }
- const config = {
- toggle: true,
- parent: 777
- }
- expect(() => {
- Util.typeCheckConfig(namePlugin, config, defaultType)
- }).toThrowError(TypeError, 'COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".')
- })
- it('should return null stringified when null is passed', () => {
- const defaultType = {
- toggle: 'boolean',
- parent: '(null|element)'
- }
- const config = {
- toggle: true,
- parent: null
- }
- Util.typeCheckConfig(namePlugin, config, defaultType)
- expect().nothing()
- })
- it('should return undefined stringified when undefined is passed', () => {
- const defaultType = {
- toggle: 'boolean',
- parent: '(undefined|element)'
- }
- const config = {
- toggle: true,
- parent: undefined
- }
- Util.typeCheckConfig(namePlugin, config, defaultType)
- expect().nothing()
- })
- })
- describe('isVisible', () => {
- it('should return false if the element is not defined', () => {
- expect(Util.isVisible(null)).toEqual(false)
- expect(Util.isVisible(undefined)).toEqual(false)
- })
- it('should return false if the element provided is not a dom element', () => {
- expect(Util.isVisible({})).toEqual(false)
- })
- it('should return false if the element is not visible with display none', () => {
- fixtureEl.innerHTML = '<div style="display: none;"></div>'
- const div = fixtureEl.querySelector('div')
- expect(Util.isVisible(div)).toEqual(false)
- })
- it('should return false if the element is not visible with visibility hidden', () => {
- fixtureEl.innerHTML = '<div style="visibility: hidden;"></div>'
- const div = fixtureEl.querySelector('div')
- expect(Util.isVisible(div)).toEqual(false)
- })
- it('should return false if an ancestor element is display none', () => {
- fixtureEl.innerHTML = [
- '<div style="display: none;">',
- ' <div>',
- ' <div>',
- ' <div class="content"></div>',
- ' </div>',
- ' </div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('.content')
- expect(Util.isVisible(div)).toEqual(false)
- })
- it('should return false if an ancestor element is visibility hidden', () => {
- fixtureEl.innerHTML = [
- '<div style="visibility: hidden;">',
- ' <div>',
- ' <div>',
- ' <div class="content"></div>',
- ' </div>',
- ' </div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('.content')
- expect(Util.isVisible(div)).toEqual(false)
- })
- it('should return true if an ancestor element is visibility hidden, but reverted', () => {
- fixtureEl.innerHTML = [
- '<div style="visibility: hidden;">',
- ' <div style="visibility: visible;">',
- ' <div>',
- ' <div class="content"></div>',
- ' </div>',
- ' </div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('.content')
- expect(Util.isVisible(div)).toEqual(true)
- })
- it('should return true if the element is visible', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <div id="element"></div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('#element')
- expect(Util.isVisible(div)).toEqual(true)
- })
- it('should return false if the element is hidden, but not via display or visibility', () => {
- fixtureEl.innerHTML = [
- '<details>',
- ' <div id="element"></div>',
- '</details>'
- ].join('')
- const div = fixtureEl.querySelector('#element')
- expect(Util.isVisible(div)).toEqual(false)
- })
- })
- describe('isDisabled', () => {
- it('should return true if the element is not defined', () => {
- expect(Util.isDisabled(null)).toEqual(true)
- expect(Util.isDisabled(undefined)).toEqual(true)
- expect(Util.isDisabled()).toEqual(true)
- })
- it('should return true if the element provided is not a dom element', () => {
- expect(Util.isDisabled({})).toEqual(true)
- expect(Util.isDisabled('test')).toEqual(true)
- })
- it('should return true if the element has disabled attribute', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <div id="element" disabled="disabled"></div>',
- ' <div id="element1" disabled="true"></div>',
- ' <div id="element2" disabled></div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('#element')
- const div1 = fixtureEl.querySelector('#element1')
- const div2 = fixtureEl.querySelector('#element2')
- expect(Util.isDisabled(div)).toEqual(true)
- expect(Util.isDisabled(div1)).toEqual(true)
- expect(Util.isDisabled(div2)).toEqual(true)
- })
- it('should return false if the element has disabled attribute with "false" value, or doesn\'t have attribute', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <div id="element" disabled="false"></div>',
- ' <div id="element1" ></div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('#element')
- const div1 = fixtureEl.querySelector('#element1')
- expect(Util.isDisabled(div)).toEqual(false)
- expect(Util.isDisabled(div1)).toEqual(false)
- })
- it('should return false if the element is not disabled ', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <button id="button"></button>',
- ' <select id="select"></select>',
- ' <select id="input"></select>',
- '</div>'
- ].join('')
- const el = selector => fixtureEl.querySelector(selector)
- expect(Util.isDisabled(el('#button'))).toEqual(false)
- expect(Util.isDisabled(el('#select'))).toEqual(false)
- expect(Util.isDisabled(el('#input'))).toEqual(false)
- })
- it('should return true if the element has disabled attribute', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <input id="input" disabled="disabled"/>',
- ' <input id="input1" disabled="disabled"/>',
- ' <button id="button" disabled="true"></button>',
- ' <button id="button1" disabled="disabled"></button>',
- ' <button id="button2" disabled></button>',
- ' <select id="select" disabled></select>',
- ' <select id="input" disabled></select>',
- '</div>'
- ].join('')
- const el = selector => fixtureEl.querySelector(selector)
- expect(Util.isDisabled(el('#input'))).toEqual(true)
- expect(Util.isDisabled(el('#input1'))).toEqual(true)
- expect(Util.isDisabled(el('#button'))).toEqual(true)
- expect(Util.isDisabled(el('#button1'))).toEqual(true)
- expect(Util.isDisabled(el('#button2'))).toEqual(true)
- expect(Util.isDisabled(el('#input'))).toEqual(true)
- })
- it('should return true if the element has class "disabled"', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <div id="element" class="disabled"></div>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('#element')
- expect(Util.isDisabled(div)).toEqual(true)
- })
- it('should return true if the element has class "disabled" but disabled attribute is false', () => {
- fixtureEl.innerHTML = [
- '<div>',
- ' <input id="input" class="disabled" disabled="false"/>',
- '</div>'
- ].join('')
- const div = fixtureEl.querySelector('#input')
- expect(Util.isDisabled(div)).toEqual(true)
- })
- })
- describe('findShadowRoot', () => {
- it('should return null if shadow dom is not available', () => {
-
- if (!document.documentElement.attachShadow) {
- expect().nothing()
- return
- }
- fixtureEl.innerHTML = '<div></div>'
- const div = fixtureEl.querySelector('div')
- spyOn(document.documentElement, 'attachShadow').and.returnValue(null)
- expect(Util.findShadowRoot(div)).toEqual(null)
- })
- it('should return null when we do not find a shadow root', () => {
-
- if (!document.documentElement.attachShadow) {
- expect().nothing()
- return
- }
- spyOn(document, 'getRootNode').and.returnValue(undefined)
- expect(Util.findShadowRoot(document)).toEqual(null)
- })
- it('should return the shadow root when found', () => {
-
- if (!document.documentElement.attachShadow) {
- expect().nothing()
- return
- }
- fixtureEl.innerHTML = '<div></div>'
- const div = fixtureEl.querySelector('div')
- const shadowRoot = div.attachShadow({
- mode: 'open'
- })
- expect(Util.findShadowRoot(shadowRoot)).toEqual(shadowRoot)
- shadowRoot.innerHTML = '<button>Shadow Button</button>'
- expect(Util.findShadowRoot(shadowRoot.firstChild)).toEqual(shadowRoot)
- })
- })
- describe('noop', () => {
- it('should be a function', () => {
- expect(typeof Util.noop).toEqual('function')
- })
- })
- describe('reflow', () => {
- it('should return element offset height to force the reflow', () => {
- fixtureEl.innerHTML = '<div></div>'
- const div = fixtureEl.querySelector('div')
- expect(Util.reflow(div)).toEqual(0)
- })
- })
- describe('getjQuery', () => {
- const fakejQuery = { trigger() {} }
- beforeEach(() => {
- Object.defineProperty(window, 'jQuery', {
- value: fakejQuery,
- writable: true
- })
- })
- afterEach(() => {
- window.jQuery = undefined
- })
- it('should return jQuery object when present', () => {
- expect(Util.getjQuery()).toEqual(fakejQuery)
- })
- it('should not return jQuery object when present if data-bs-no-jquery', () => {
- document.body.setAttribute('data-bs-no-jquery', '')
- expect(window.jQuery).toEqual(fakejQuery)
- expect(Util.getjQuery()).toEqual(null)
- document.body.removeAttribute('data-bs-no-jquery')
- })
- it('should not return jQuery if not present', () => {
- window.jQuery = undefined
- expect(Util.getjQuery()).toEqual(null)
- })
- })
- describe('onDOMContentLoaded', () => {
- it('should execute callbacks when DOMContentLoaded is fired and should not add more than one listener', () => {
- const spy = jasmine.createSpy()
- const spy2 = jasmine.createSpy()
- spyOn(document, 'addEventListener').and.callThrough()
- spyOnProperty(document, 'readyState').and.returnValue('loading')
- Util.onDOMContentLoaded(spy)
- Util.onDOMContentLoaded(spy2)
- document.dispatchEvent(new Event('DOMContentLoaded', {
- bubbles: true,
- cancelable: true
- }))
- expect(spy).toHaveBeenCalled()
- expect(spy2).toHaveBeenCalled()
- expect(document.addEventListener).toHaveBeenCalledTimes(1)
- })
- it('should execute callback if readyState is not "loading"', () => {
- const spy = jasmine.createSpy()
- Util.onDOMContentLoaded(spy)
- expect(spy).toHaveBeenCalled()
- })
- })
- describe('defineJQueryPlugin', () => {
- const fakejQuery = { fn: {} }
- beforeEach(() => {
- Object.defineProperty(window, 'jQuery', {
- value: fakejQuery,
- writable: true
- })
- })
- afterEach(() => {
- window.jQuery = undefined
- })
- it('should define a plugin on the jQuery instance', () => {
- const pluginMock = function () {}
- pluginMock.NAME = 'test'
- pluginMock.jQueryInterface = function () {}
- Util.defineJQueryPlugin(pluginMock)
- expect(fakejQuery.fn.test).toBe(pluginMock.jQueryInterface)
- expect(fakejQuery.fn.test.Constructor).toBe(pluginMock)
- expect(typeof fakejQuery.fn.test.noConflict).toEqual('function')
- })
- })
- describe('execute', () => {
- it('should execute if arg is function', () => {
- const spy = jasmine.createSpy('spy')
- Util.execute(spy)
- expect(spy).toHaveBeenCalled()
- })
- })
- describe('executeAfterTransition', () => {
- it('should immediately execute a function when waitForTransition parameter is false', () => {
- const el = document.createElement('div')
- const callbackSpy = jasmine.createSpy('callback spy')
- const eventListenerSpy = spyOn(el, 'addEventListener')
- Util.executeAfterTransition(callbackSpy, el, false)
- expect(callbackSpy).toHaveBeenCalled()
- expect(eventListenerSpy).not.toHaveBeenCalled()
- })
- it('should execute a function when a transitionend event is dispatched', () => {
- const el = document.createElement('div')
- const callbackSpy = jasmine.createSpy('callback spy')
- spyOn(window, 'getComputedStyle').and.returnValue({
- transitionDuration: '0.05s',
- transitionDelay: '0s'
- })
- Util.executeAfterTransition(callbackSpy, el)
- el.dispatchEvent(new TransitionEvent('transitionend'))
- expect(callbackSpy).toHaveBeenCalled()
- })
- it('should execute a function after a computed CSS transition duration and there was no transitionend event dispatched', done => {
- const el = document.createElement('div')
- const callbackSpy = jasmine.createSpy('callback spy')
- spyOn(window, 'getComputedStyle').and.returnValue({
- transitionDuration: '0.05s',
- transitionDelay: '0s'
- })
- Util.executeAfterTransition(callbackSpy, el)
- setTimeout(() => {
- expect(callbackSpy).toHaveBeenCalled()
- done()
- }, 70)
- })
- it('should not execute a function a second time after a computed CSS transition duration and if a transitionend event has already been dispatched', done => {
- const el = document.createElement('div')
- const callbackSpy = jasmine.createSpy('callback spy')
- spyOn(window, 'getComputedStyle').and.returnValue({
- transitionDuration: '0.05s',
- transitionDelay: '0s'
- })
- Util.executeAfterTransition(callbackSpy, el)
- setTimeout(() => {
- el.dispatchEvent(new TransitionEvent('transitionend'))
- }, 50)
- setTimeout(() => {
- expect(callbackSpy).toHaveBeenCalledTimes(1)
- done()
- }, 70)
- })
- it('should not trigger a transitionend event if another transitionend event had already happened', done => {
- const el = document.createElement('div')
- spyOn(window, 'getComputedStyle').and.returnValue({
- transitionDuration: '0.05s',
- transitionDelay: '0s'
- })
- Util.executeAfterTransition(() => {}, el)
-
- el.dispatchEvent(new TransitionEvent('transitionend'))
- const dispatchSpy = spyOn(el, 'dispatchEvent').and.callThrough()
- setTimeout(() => {
-
- expect(dispatchSpy).not.toHaveBeenCalled()
- done()
- }, 70)
- })
- it('should ignore transitionend events from nested elements', done => {
- fixtureEl.innerHTML = [
- '<div class="outer">',
- ' <div class="nested"></div>',
- '</div>'
- ].join('')
- const outer = fixtureEl.querySelector('.outer')
- const nested = fixtureEl.querySelector('.nested')
- const callbackSpy = jasmine.createSpy('callback spy')
- spyOn(window, 'getComputedStyle').and.returnValue({
- transitionDuration: '0.05s',
- transitionDelay: '0s'
- })
- Util.executeAfterTransition(callbackSpy, outer)
- nested.dispatchEvent(new TransitionEvent('transitionend', {
- bubbles: true
- }))
- setTimeout(() => {
- expect(callbackSpy).not.toHaveBeenCalled()
- }, 20)
- setTimeout(() => {
- expect(callbackSpy).toHaveBeenCalled()
- done()
- }, 70)
- })
- })
- describe('getNextActiveElement', () => {
- it('should return first element if active not exists or not given and shouldGetNext is either true, or false with cycling being disabled', () => {
- const array = ['a', 'b', 'c', 'd']
- expect(Util.getNextActiveElement(array, '', true, true)).toEqual('a')
- expect(Util.getNextActiveElement(array, 'g', true, true)).toEqual('a')
- expect(Util.getNextActiveElement(array, '', true, false)).toEqual('a')
- expect(Util.getNextActiveElement(array, 'g', true, false)).toEqual('a')
- expect(Util.getNextActiveElement(array, '', false, false)).toEqual('a')
- expect(Util.getNextActiveElement(array, 'g', false, false)).toEqual('a')
- })
- it('should return last element if active not exists or not given and shouldGetNext is false but cycling is enabled', () => {
- const array = ['a', 'b', 'c', 'd']
- expect(Util.getNextActiveElement(array, '', false, true)).toEqual('d')
- expect(Util.getNextActiveElement(array, 'g', false, true)).toEqual('d')
- })
- 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')
- })
- })
- })
|