Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohann-S <johann.servoire@gmail.com>2018-06-16 23:20:27 +0300
committerXhmikosR <xhmikosr@gmail.com>2019-02-20 23:05:45 +0300
commit096413a9942178aa68925f032822b40900bac346 (patch)
treec4c6acc502b2df8788ec5e2b69122dcb081d3490 /js/tests/unit/dom
parent4510e7e61db27b264c1fadc125beb2d4c80f07df (diff)
fix(selector-engine): increase coverage for selector engine
Diffstat (limited to 'js/tests/unit/dom')
-rw-r--r--js/tests/unit/dom/eventHandler.js2
-rw-r--r--js/tests/unit/dom/selectorEngine.js77
2 files changed, 78 insertions, 1 deletions
diff --git a/js/tests/unit/dom/eventHandler.js b/js/tests/unit/dom/eventHandler.js
index f282616328..076a28a8a1 100644
--- a/js/tests/unit/dom/eventHandler.js
+++ b/js/tests/unit/dom/eventHandler.js
@@ -1,7 +1,7 @@
$(function () {
'use strict'
- QUnit.module('event handler')
+ QUnit.module('eventHandler')
QUnit.test('should be defined', function (assert) {
assert.expect(1)
diff --git a/js/tests/unit/dom/selectorEngine.js b/js/tests/unit/dom/selectorEngine.js
new file mode 100644
index 0000000000..80bee7800e
--- /dev/null
+++ b/js/tests/unit/dom/selectorEngine.js
@@ -0,0 +1,77 @@
+$(function () {
+ 'use strict'
+
+ QUnit.module('selectorEngine')
+
+ QUnit.test('should be defined', function (assert) {
+ assert.expect(1)
+ assert.ok(SelectorEngine, 'Manipulator is defined')
+ })
+
+ QUnit.test('should determine if an element match the selector', function (assert) {
+ assert.expect(2)
+ $('<input type="checkbox" /> <button class="btn"></button>').appendTo('#qunit-fixture')
+
+ assert.ok(!SelectorEngine.matches($('#qunit-fixture')[0], '.btn'))
+ assert.ok(SelectorEngine.matches($('.btn')[0], '.btn'))
+ })
+
+ QUnit.test('should find the selector, according to an element or not', function (assert) {
+ assert.expect(3)
+ $('<input type="checkbox" /> <button class="btn"></button>').appendTo('#qunit-fixture')
+
+ var btn = $('.btn').first()[0]
+ assert.strictEqual(SelectorEngine.find($('.btn')), null)
+ assert.equal(SelectorEngine.find('.btn')[0], btn)
+ assert.equal(SelectorEngine.find('.btn', $('#qunit-fixture')[0])[0], btn)
+ })
+
+ QUnit.test('should find the first element which match the selector, according to an element or not', function (assert) {
+ assert.expect(3)
+ $('<button class="btn">btn1</button> <button class="btn">btn2</button>').appendTo('#qunit-fixture')
+
+ var btn = $('.btn').first()[0]
+ assert.strictEqual(SelectorEngine.findOne($('.btn')), null)
+ assert.equal(SelectorEngine.findOne('.btn'), btn)
+ assert.equal(SelectorEngine.findOne('.btn', $('#qunit-fixture')[0]), btn)
+ })
+
+ QUnit.test('should find children', function (assert) {
+ assert.expect(2)
+ $('<button class="btn">btn1</button> <button class="btn">btn2</button> <input type="text" />').appendTo('#qunit-fixture')
+
+ assert.strictEqual(SelectorEngine.children($('.btn')), null)
+ assert.equal(SelectorEngine.children($('#qunit-fixture')[0], '.btn').length, 2)
+ })
+
+ QUnit.test('should find the selector in parents', function (assert) {
+ assert.expect(2)
+
+ $('<input type="text" />').appendTo('#qunit-fixture')
+ assert.strictEqual(SelectorEngine.parents($('.container')[0], {}), null)
+ assert.strictEqual(SelectorEngine.parents($('input')[0], 'body').length, 1)
+ })
+
+ QUnit.test('should find the closest element according to the selector', function (assert) {
+ assert.expect(2)
+ var html =
+ '<div class="test">' +
+ ' <button class="btn"></button>' +
+ '</div>'
+
+ $(html).appendTo('#qunit-fixture')
+ assert.strictEqual(SelectorEngine.closest($('.btn')[0], {}), null)
+ assert.strictEqual(SelectorEngine.closest($('.btn')[0], '.test'), $('.test')[0])
+ })
+
+ QUnit.test('should fin previous element', function (assert) {
+ assert.expect(2)
+ var html =
+ '<div class="test"></div>' +
+ '<button class="btn"></button>'
+
+ $(html).appendTo('#qunit-fixture')
+ assert.strictEqual(SelectorEngine.prev($('.btn')[0], {}), null)
+ assert.strictEqual(SelectorEngine.prev($('.btn')[0], '.test')[0], $('.test')[0])
+ })
+})