From 7a3fdda9650a06792d9278a8cef06d544d49300f Mon Sep 17 00:00:00 2001
From: Di Peng
Date: Thu, 14 Jul 2011 17:50:06 -0700
Subject: feat(jqlite): added show(),hide() and eq() methods to jqlite
- add those three methods to jqlite
---
test/jqLiteSpec.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
test/testabilityPatch.js | 6 ++++-
2 files changed, 71 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index c920a250..8dd66d36 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -507,4 +507,70 @@ describe('jqLite', function(){
expect(innerDiv.html()).toEqual('text');
});
});
+
+
+ describe('hide', function() {
+ var element;
+
+ afterEach(function() {
+ if (element) dealoc(element);
+ });
+
+ it('should hide the element', function() {
+ element = jqLite('
');
+ expect(isCssVisible(element)).toBe(true);
+ element.hide();
+ expect(isCssVisible(element)).toBe(false);
+ });
+ });
+
+
+ describe('show', function() {
+ var element;
+
+ afterEach(function() {
+ if (element) dealoc(element);
+ element.remove();
+ });
+
+
+ it('should show the element ', function() {
+ element = jqLite('');
+ element[0].style.display = 'none';
+ expect(isCssVisible(element)).toBe(false);
+ element.show();
+ expect(isCssVisible(element)).toBe(true);
+ });
+
+
+ it('should show previously hidden element and preserve the display value', function() {
+ element = jqLite('xx
');
+ jqLite(document.body).append(element);
+ element.hide();
+ expect(isCssVisible(element)).toBe(false);
+ element.show();
+ expect(element[0].style.display).toBe('inline');
+ expect(isCssVisible(element)).toBe(true);
+
+ element[0].style.display = 'block';
+ element.hide();
+ expect(isCssVisible(element)).toBe(false);
+ element.show();
+ expect(isCssVisible(element)).toBe(true);
+
+ // this totally doesn't make sense, it should be 'block', but jquery (1.4.2+1.6.2) behaves
+ // this way.
+ expect(element[0].style.display).toBe('inline');
+ });
+ });
+
+
+ describe('eq', function() {
+ it('should select the nth element ', function() {
+ var element = jqLite('aa
bb
');
+ expect(element.find('span').eq(0).html()).toBe('aa');
+ expect(element.find('span').eq(-1).html()).toBe('bb');
+ expect(element.find('span').eq(20).length).toBe(0);;
+ });
+ });
});
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index 0b22b2ae..34e1710b 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -274,9 +274,13 @@ function sortedHtml(element, showNgClass) {
return html;
}
+
+/**
+ * This method is a cheap way of testing if css for a given node is not set to 'none'. It doesn't
+ * actually test if an element is displayed by the browser. Be aware!!!
+ */
function isCssVisible(node) {
var display = node.css('display');
- if (display == 'block') display = "";
return display != 'none';
}
--
cgit v1.2.3