Skip to content

Commit 8255586

Browse files
committed
Additional tree test to verify that tree works with query and search as intended
1 parent 12ba14c commit 8255586

File tree

5 files changed

+191
-3
lines changed

5 files changed

+191
-3
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gitana",
33
"description": "Gitana JavaScript Driver for Cloud CMS",
4-
"version": "1.0.300",
4+
"version": "1.0.305",
55
"main": "dist/gitana.js",
66
"license": "Apache-2.0",
77
"keywords": [

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitana",
3-
"version": "1.0.300",
3+
"version": "1.0.305",
44
"main": [
55
"dist/gitana.js"
66
],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitanajs",
3-
"version": "1.0.304",
3+
"version": "1.0.305",
44
"repository": {
55
"type": "git",
66
"url": "git://github.com/gitana/gitana-javascript-driver.git"

tests/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@
296296
<!-- access policy -->
297297
<script type="text/javascript" src="js/testAccessPolicy.js"></script>
298298

299+
<!-- tree -->
300+
<script type="text/javascript" src="js/testTree1.js"></script>
301+
299302
</head>
300303
<body>
301304
<h1 id="qunit-header">Gitana JavaScript Driver Test Suite</h1>

tests/js/testTree1.js

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
(function($) {
2+
3+
module("tree1");
4+
5+
// Test case : Tree Test #1
6+
_asyncTest("Tree #1", function()
7+
{
8+
expect(3);
9+
10+
var createFolder = function(branch, parentFolderPath, title, callback)
11+
{
12+
Chain(branch).createNode({
13+
"title": title
14+
}, {
15+
"folderPath": parentFolderPath
16+
}).then(function() {
17+
callback();
18+
});
19+
};
20+
21+
var defineArticleType = function(branch, callback)
22+
{
23+
Chain(branch).createNode({
24+
"_type": "d:type",
25+
"_qname": "my:article",
26+
"title": "My Article",
27+
"type": "object",
28+
"properties": {
29+
"title": {
30+
"type": "string"
31+
},
32+
"category": {
33+
"type": "string"
34+
},
35+
"published": {
36+
"type": "boolean"
37+
}
38+
}
39+
}).then(function() {
40+
callback();
41+
});
42+
};
43+
44+
var createArticle = function(branch, parentFolderPath, title, category, published, text, callback)
45+
{
46+
var o = {
47+
"_type": "my:article",
48+
"title": title,
49+
"category": category
50+
};
51+
52+
if (published) {
53+
o.published = published;
54+
}
55+
56+
if (text) {
57+
o.text = text;
58+
}
59+
60+
Chain(branch).createNode(o, {
61+
"folderPath": parentFolderPath
62+
}).then(function() {
63+
callback();
64+
});
65+
};
66+
67+
var countArticles = function(obj)
68+
{
69+
var count = 0;
70+
71+
var type = obj["typeQName"];
72+
if ("my:article" === type)
73+
{
74+
count++;
75+
}
76+
77+
var children = obj["children"];
78+
if (children)
79+
{
80+
for (var i = 0; i < children.length; i++)
81+
{
82+
count += countArticles(children[i]);
83+
}
84+
}
85+
86+
return count;
87+
};
88+
89+
var loadTree = function(rootNode, depth, query, search, callback) {
90+
91+
var o = {
92+
"properties": true,
93+
"depth": -1
94+
};
95+
if (depth) {
96+
o.depth = depth;
97+
}
98+
if (query) {
99+
o.query = query;
100+
}
101+
if (search) {
102+
o.search = search;
103+
}
104+
105+
Chain(rootNode).loadTree(o, function(tree) {
106+
callback(tree);
107+
});
108+
};
109+
110+
var runTests = function(branch, rootNode, callback)
111+
{
112+
// find all articles (should be 6)
113+
loadTree(rootNode, 3, { "_type": "my:article" }, null, function(tree) {
114+
equal(countArticles(tree), 6, "Should find 6 articles");
115+
116+
// find published articles (should be 2)
117+
loadTree(rootNode, 3, { "published": true, "_type": "my:article" }, null, function(tree) {
118+
equal(countArticles(tree), 2, "Should find 2 published articles");
119+
120+
// find published articles with text "brewers" (should be 1)
121+
loadTree(rootNode, 3, { "published": true, "_type": "my:article" }, { "query_string": { "query": "brewers" }}, function(tree) {
122+
equal(countArticles(tree), 1, "Should find 1 published article for 'brewers'");
123+
124+
callback();
125+
});
126+
});
127+
});
128+
};
129+
130+
var gitana = GitanaTest.authenticateFullOAuth();
131+
gitana.then(function() {
132+
133+
// NOTE: this = platform
134+
135+
this.createRepository().readBranch("master").then(function() {
136+
137+
// NOTE: this = branch
138+
var branch = this;
139+
140+
createFolder(branch, "/", "folder1", function() {
141+
createFolder(branch, "/folder1", "folder11", function () {
142+
createFolder(branch, "/folder1", "folder12", function () {
143+
defineArticleType(branch, function() {
144+
createArticle(branch, "/folder1/folder11", "Article 1", "red", false, null, function() {
145+
createArticle(branch, "/folder1/folder11", "Article 2", "blue", false, null, function() {
146+
createArticle(branch, "/folder1/folder11", "Article 3", "green", true, null, function() {
147+
createArticle(branch, "/folder1/folder12", "Article 4", "red", false, null, function() {
148+
createArticle(branch, "/folder1/folder12", "Article 5", "red", false, null, function() {
149+
createArticle(branch, "/folder1/folder12", "Article 6", "green", true, "brewers", function() {
150+
151+
branch.rootNode().then(function() {
152+
var rootNode = this;
153+
154+
// wait a bit to allow indexing
155+
setTimeout(function() {
156+
157+
// now run the actual tests
158+
runTests(branch, rootNode, function() {
159+
success();
160+
});
161+
162+
}, 5000);
163+
})
164+
});
165+
});
166+
});
167+
});
168+
});
169+
});
170+
});
171+
});
172+
});
173+
});
174+
});
175+
176+
});
177+
178+
var success = function()
179+
{
180+
start();
181+
};
182+
183+
});
184+
185+
}(jQuery) );

0 commit comments

Comments
 (0)