aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-09-29 02:34:34 +0300
committerGeoSot <[email protected]>2021-09-29 13:08:18 +0300
commitbeed99e50ffa16e6ad3d2b1296de539a3b0ea85a (patch)
tree486871bb176f4d10b8feb1265be734b76c83e970 /js/tests
parent4ffdef397f6b28729e1338625c73218765dcdbb9 (diff)
downloadbootstrap-gs/parse-json-config.tar.xz
bootstrap-gs/parse-json-config.zip
Manipulator: Add json parse supportgs/parse-json-config
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/dom/manipulator.spec.js15
-rw-r--r--js/tests/unit/tooltip.spec.js11
2 files changed, 15 insertions, 11 deletions
diff --git a/js/tests/unit/dom/manipulator.spec.js b/js/tests/unit/dom/manipulator.spec.js
index 13d0c3d17..7ba45c102 100644
--- a/js/tests/unit/dom/manipulator.spec.js
+++ b/js/tests/unit/dom/manipulator.spec.js
@@ -1,7 +1,7 @@
import Manipulator from '../../../src/dom/manipulator'
/** Test helpers */
-import { getFixture, clearFixture } from '../../helpers/fixture'
+import { clearFixture, getFixture } from '../../helpers/fixture'
describe('Manipulator', () => {
let fixtureEl
@@ -94,7 +94,7 @@ describe('Manipulator', () => {
})
it('should normalize data', () => {
- fixtureEl.innerHTML = '<div data-bs-test="false" ></div>'
+ fixtureEl.innerHTML = '<div data-bs-test="false" data-bs-test2=\'{"delay":{"show":100,"hide":10}}\'></div>'
const div = fixtureEl.querySelector('div')
@@ -103,8 +103,15 @@ describe('Manipulator', () => {
div.setAttribute('data-bs-test', 'true')
expect(Manipulator.getDataAttribute(div, 'test')).toEqual(true)
- div.setAttribute('data-bs-test', '1')
- expect(Manipulator.getDataAttribute(div, 'test')).toEqual(1)
+ const objectData = { 'Super Hero': ['Iron Man', 'Super Man'], url: 'http://localhost:8080/test?foo=bar' }
+ const dataStr = JSON.stringify(objectData)
+ div.setAttribute('data-bs-test', encodeURIComponent(dataStr))
+ expect(Manipulator.getDataAttribute(div, 'test')).toEqual(objectData)
+
+ div.setAttribute('data-bs-test', dataStr)
+ expect(Manipulator.getDataAttribute(div, 'test')).toEqual(objectData)
+
+ expect(Manipulator.getDataAttribute(div, 'test2')).toEqual({ delay: { show: 100, hide: 10 } })
})
})
diff --git a/js/tests/unit/tooltip.spec.js b/js/tests/unit/tooltip.spec.js
index 22a7edd01..c4f34e01c 100644
--- a/js/tests/unit/tooltip.spec.js
+++ b/js/tests/unit/tooltip.spec.js
@@ -680,15 +680,12 @@ describe('Tooltip', () => {
})
it('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', done => {
- fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'
+ fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip" data-bs-delay=\'{"show":0,"hide":150}\'>'
const tooltipEl = fixtureEl.querySelector('a')
- const tooltip = new Tooltip(tooltipEl, {
- delay: {
- show: 0,
- hide: 150
- }
- })
+ const tooltip = new Tooltip(tooltipEl)
+
+ expect(tooltip._config.delay).toEqual({ show: 0, hide: 150 })
setTimeout(() => {
expect(tooltip.getTipElement().classList.contains('show')).toEqual(true)