aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2018-06-09 21:11:05 +0200
committerXhmikosR <[email protected]>2019-02-20 22:05:45 +0200
commit64591b3722128d89252b8f1c840cd846940b7f5c (patch)
tree971c65a6fd9f506da55e4be31d1fece7f9b20b89 /js/tests
parent4d6e41dea6492f18029f0dd70b118217c02f27d8 (diff)
downloadbootstrap-64591b3722128d89252b8f1c840cd846940b7f5c.tar.xz
bootstrap-64591b3722128d89252b8f1c840cd846940b7f5c.zip
fix(manipulator): increase coverage for manipulator
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/index.html5
-rw-r--r--js/tests/karma.conf.js10
-rw-r--r--js/tests/unit/dom/manipulator.js179
-rw-r--r--js/tests/unit/modal.js6
4 files changed, 196 insertions, 4 deletions
diff --git a/js/tests/index.html b/js/tests/index.html
index 19ff53ce8..f4a99df44 100644
--- a/js/tests/index.html
+++ b/js/tests/index.html
@@ -97,10 +97,11 @@
</script>
<!-- Transpiled Plugins -->
+ <script src="../dist/dom/polyfill.js"></script>
+ <script src="../dist/dom/manipulator.js"></script>
<script src="../dist/dom/eventHandler.js"></script>
<script src="../dist/dom/selectorEngine.js"></script>
<script src="../dist/dom/data.js"></script>
- <script src="../dist/dom/manipulator.js"></script>
<script src="../dist/util.js"></script>
<script src="../dist/alert.js"></script>
<script src="../dist/button.js"></script>
@@ -116,6 +117,8 @@
<!-- Unit Tests -->
<script src="unit/dom/eventHandler.js"></script>
+ <script src="unit/dom/manipulator.js"></script>
+ <script src="unit/dom/data.js"></script>
<script src="unit/alert.js"></script>
<script src="unit/button.js"></script>
<script src="unit/carousel.js"></script>
diff --git a/js/tests/karma.conf.js b/js/tests/karma.conf.js
index 066165a14..469a95561 100644
--- a/js/tests/karma.conf.js
+++ b/js/tests/karma.conf.js
@@ -140,6 +140,16 @@ if (bundle) {
branches: 86,
functions: 89,
lines: 90
+ },
+ each: {
+ overrides: {
+ 'js/src/dom/polyfill.js': {
+ statements: 39,
+ lines: 37,
+ branches: 19,
+ functions: 50
+ }
+ }
}
}
}
diff --git a/js/tests/unit/dom/manipulator.js b/js/tests/unit/dom/manipulator.js
new file mode 100644
index 000000000..19effa423
--- /dev/null
+++ b/js/tests/unit/dom/manipulator.js
@@ -0,0 +1,179 @@
+$(function () {
+ 'use strict'
+
+ QUnit.module('manipulator')
+
+ QUnit.test('should be defined', function (assert) {
+ assert.expect(1)
+ assert.ok(Manipulator, 'Manipulator is defined')
+ })
+
+ QUnit.test('should set checked for input', function (assert) {
+ assert.expect(2)
+
+ var $input = $('<input type="checkbox" />').appendTo('#qunit-fixture')
+ Manipulator.setChecked($input[0], true)
+
+ assert.ok($input[0].checked)
+
+ Manipulator.setChecked($input[0], false)
+
+ assert.ok(!$input[0].checked)
+ })
+
+ QUnit.test('should not set checked for non input element', function (assert) {
+ assert.expect(1)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+ Manipulator.setChecked($div[0], true)
+
+ assert.ok(typeof $div[0].checked === 'undefined')
+ })
+
+ QUnit.test('should verify if an element is checked', function (assert) {
+ assert.expect(2)
+
+ var $input = $('<input type="checkbox" />').appendTo('#qunit-fixture')
+ Manipulator.setChecked($input[0], true)
+
+ assert.ok(Manipulator.isChecked($input[0]))
+
+ Manipulator.setChecked($input[0], false)
+
+ assert.ok(!Manipulator.isChecked($input[0]))
+ })
+
+ QUnit.test('should throw an error when the element is not an input', function (assert) {
+ assert.expect(1)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+ try {
+ Manipulator.isChecked($div[0])
+ } catch (e) {
+ assert.strictEqual(e.message, 'INPUT parameter is not an HTMLInputElement')
+ }
+ })
+
+ QUnit.test('should set data attribute', function (assert) {
+ assert.expect(1)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+
+ Manipulator.setDataAttribute($div[0], 'test', 'test')
+
+ assert.strictEqual($div[0].getAttribute('data-test'), 'test')
+ })
+
+ QUnit.test('should set data attribute in lower case', function (assert) {
+ assert.expect(1)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+
+ Manipulator.setDataAttribute($div[0], 'tEsT', 'test')
+
+ assert.strictEqual($div[0].getAttribute('data-test'), 'test')
+ })
+
+ QUnit.test('should get data attribute', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div data-test="null" />').appendTo('#qunit-fixture')
+
+ assert.strictEqual(Manipulator.getDataAttribute($div[0], 'test'), null)
+
+ var $div2 = $('<div data-test2="js" />').appendTo('#qunit-fixture')
+
+ assert.strictEqual(Manipulator.getDataAttribute($div2[0], 'tEst2'), 'js')
+ })
+
+ QUnit.test('should get data attributes', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div data-test="js" data-test2="js2" />').appendTo('#qunit-fixture')
+ var $div2 = $('<div data-test3="js" data-test4="js2" />').appendTo('#qunit-fixture')
+
+ assert.propEqual(Manipulator.getDataAttributes($div[0]), {
+ test: 'js',
+ test2: 'js2'
+ })
+
+ var stub = sinon
+ .stub(Object, 'getOwnPropertyDescriptor')
+ .callsFake(function () {
+ return false
+ })
+
+ assert.propEqual(Manipulator.getDataAttributes($div2[0]), {
+ test3: 'js',
+ test4: 'js2'
+ })
+
+ stub.restore()
+ })
+
+ QUnit.test('should remove data attribute', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+
+ Manipulator.setDataAttribute($div[0], 'test', 'test')
+
+ assert.strictEqual($div[0].getAttribute('data-test'), 'test')
+
+ Manipulator.removeDataAttribute($div[0], 'test')
+
+ assert.strictEqual($div[0].getAttribute('data-test'), null)
+ })
+
+ QUnit.test('should remove data attribute in lower case', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+
+ Manipulator.setDataAttribute($div[0], 'test', 'test')
+
+ assert.strictEqual($div[0].getAttribute('data-test'), 'test')
+
+ Manipulator.removeDataAttribute($div[0], 'tESt')
+
+ assert.strictEqual($div[0].getAttribute('data-test'), null)
+ })
+
+ QUnit.test('should return element offsets', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+
+ var offset = Manipulator.offset($div[0])
+
+ assert.ok(typeof offset.top === 'number')
+ assert.ok(typeof offset.left === 'number')
+ })
+
+ QUnit.test('should return element position', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div />').appendTo('#qunit-fixture')
+
+ var offset = Manipulator.position($div[0])
+
+ assert.ok(typeof offset.top === 'number')
+ assert.ok(typeof offset.left === 'number')
+ })
+
+ QUnit.test('should toggle class', function (assert) {
+ assert.expect(2)
+
+ var $div = $('<div class="test" />').appendTo('#qunit-fixture')
+
+ Manipulator.toggleClass($div[0], 'test')
+
+ assert.ok(!$div.hasClass('test'))
+
+ Manipulator.toggleClass($div[0], 'test')
+
+ assert.ok($div.hasClass('test'))
+
+ Manipulator.toggleClass(null)
+ })
+})
diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js
index 7aa7a95b3..0739f0378 100644
--- a/js/tests/unit/modal.js
+++ b/js/tests/unit/modal.js
@@ -422,7 +422,7 @@ $(function () {
$('<div id="modal-test"/>')
.on('hidden.bs.modal', function () {
- assert.strictEqual(typeof $body.data('padding-right'), 'undefined', 'data-padding-right should be cleared after closing')
+ assert.strictEqual(document.body.getAttribute('data-padding-right'), null, 'data-padding-right should be cleared after closing')
$body.removeAttr('style')
done()
})
@@ -488,7 +488,7 @@ $(function () {
$('<div id="modal-test"/>')
.on('hidden.bs.modal', function () {
- assert.strictEqual(typeof $element.data('padding-right'), 'undefined', 'data-padding-right should be cleared after closing')
+ assert.strictEqual($element[0].getAttribute('data-padding-right'), null, 'data-padding-right should be cleared after closing')
$element.remove()
done()
})
@@ -530,7 +530,7 @@ $(function () {
$('<div id="modal-test"/>')
.on('hidden.bs.modal', function () {
- assert.strictEqual(typeof $element.data('margin-right'), 'undefined', 'data-margin-right should be cleared after closing')
+ assert.strictEqual($element[0].getAttribute('data-margin-right'), null, 'data-margin-right should be cleared after closing')
$element.remove()
done()
})