Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
4fdf47f9
Commit
4fdf47f9
authored
Jun 17, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add qunit scenario test template.
This shows how to use localstorage, indexedDB, dav, replicate.
parent
bbbb2fe2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
205 additions
and
57 deletions
+205
-57
examples/scenario.html
examples/scenario.html
+3
-2
examples/scenario.js
examples/scenario.js
+202
-55
No files found.
examples/scenario.html
View file @
4fdf47f9
...
@@ -5,11 +5,12 @@
...
@@ -5,11 +5,12 @@
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<title>
jIO Coverage Scenario
</title>
<title>
jIO Coverage Scenario
</title>
<link
rel=
"stylesheet"
href=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.css"
type=
"text/css"
media=
"screen"
/>
<script
src=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"../node_modules/rsvp/dist/rsvp-2.0.4.js"
></script>
<script
src=
"../node_modules/rsvp/dist/rsvp-2.0.4.js"
></script>
<script
src=
"../node_modules/renderjs/dist/renderjs-latest.js"
></script>
<script
src=
"../node_modules/renderjs/dist/renderjs-latest.js"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<script
src=
"../dist/jio-latest.js"
></script>
<link
rel=
"stylesheet"
href=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.css"
type=
"text/css"
media=
"screen"
/>
<script
src=
"../node_modules/grunt-contrib-qunit/test/libs/qunit.js"
type=
"text/javascript"
></script>
<script
src=
"scenario.js"
></script>
<script
src=
"scenario.js"
></script>
</head>
</head>
...
...
examples/scenario.js
View file @
4fdf47f9
/*global console, btoa*/
/*global console, btoa
, Blob
*/
/*jslint nomen: true*/
/*jslint nomen: true
, maxlen: 200
*/
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
"
use strict
"
;
"
use strict
"
;
var
test
=
QUnit
.
test
,
var
test
=
QUnit
.
test
,
...
@@ -11,34 +11,116 @@
...
@@ -11,34 +11,116 @@
deepEqual
=
QUnit
.
deepEqual
;
deepEqual
=
QUnit
.
deepEqual
;
rJS
(
window
)
rJS
(
window
)
.
ready
(
function
(
g
)
{
.
ready
(
function
(
g
)
{
return
g
.
run
({
"
type
"
:
"
indexeddb
"
,
///////////////////////////
"
database
"
:
"
test
"
// Local storage
});
///////////////////////////
})
// return g.run({
.
ready
(
function
(
g
)
{
// type: "query",
return
g
.
run
({
// sub_storage: {
type
:
"
query
"
,
// type: "uuid",
sub_storage
:
{
// sub_storage: {
type
:
"
local
"
// type: "document",
}
// document_id: "/",
});
// sub_storage: {
})
// type: "local"
.
ready
(
function
(
g
)
{
// }
return
g
.
run
({
// }
type
:
"
query
"
,
// }
sub_storage
:
{
// });
"
type
"
:
"
dav
"
}
///////////////////////////
});
// Memory storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "union",
// storage_list: [{
// type: "memory"
// }]
// }
// }
// });
///////////////////////////
// IndexedDB storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "indexeddb",
// "database": "test"
// }
// }
// });
///////////////////////////
// DAV storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "drivetojiomapping",
// sub_storage: {
// "type": "dav",
// "url": "DAVURL",
// "basic_login": btoa("LOGIN:PASSWD")
// }
// }
// }
// });
///////////////////////////
// Qiniu storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// "type": "qiniu",
// "bucket": "BUCKET",
// "access_key": "ACCESSKEY",
// "secret_key": "SECRETKEY"
// }
// }
// });
///////////////////////////
// Replicate storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "replicate",
// local_sub_storage: {
// type: "memory"
// },
// remote_sub_storage: {
// "type": "memory"
// }
// }
// }
// });
})
})
.
declareMethod
(
'
run
'
,
function
(
jio_options
)
{
.
declareMethod
(
'
run
'
,
function
(
jio_options
)
{
test
(
'
Test "
'
+
jio_options
.
type
+
'
"scenario
'
,
function
()
{
test
(
'
Test "
'
+
jio_options
.
type
+
'
"scenario
'
,
function
()
{
var
jio
;
var
jio
;
stop
();
stop
();
expect
(
9
);
expect
(
14
);
try
{
try
{
jio
=
jIO
.
createJIO
(
jio_options
);
jio
=
jIO
.
createJIO
(
jio_options
);
...
@@ -49,33 +131,40 @@
...
@@ -49,33 +131,40 @@
}
}
// Try to fetch inexistent document
// Try to fetch inexistent document
jio
.
get
(
{
"
_id
"
:
"
inexistent
"
}
)
jio
.
get
(
"
inexistent
"
)
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
if
(
error
.
status_code
!==
404
)
{
throw
error
;
}
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
// Post a document without ID
// Post a document without ID
return
jio
.
post
({
"
title
"
:
"
I don't have ID
"
});
return
jio
.
post
({
"
title
"
:
"
I don't have ID
éà&
\n
"
});
})
})
.
then
(
function
(
doc_id
)
{
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document without ID created
"
);
ok
(
doc_id
,
"
Document without ID created
(
"
+
doc_id
+
"
)
"
);
// Fetch the newly created document
// Fetch the newly created document
return
jio
.
get
({
"
_id
"
:
doc_id
});
return
RSVP
.
all
([
jio
.
get
(
doc_id
),
doc_id
]);
})
})
.
then
(
function
(
doc
)
{
.
then
(
function
(
result_list
)
{
var
doc
_id
=
doc
.
_id
;
var
doc
=
result_list
[
0
],
delete
doc
.
_id
;
doc_id
=
result_list
[
1
]
;
deepEqual
(
doc
,
{
"
title
"
:
"
I don't have ID
"
},
deepEqual
(
doc
,
{
"
title
"
:
"
I don't have ID
éà&
\n
"
},
"
Document correctly fetched
"
);
"
Document correctly fetched
"
);
// Remove the doc
// Remove the doc
return
jio
.
remove
(
{
"
_id
"
:
doc_id
}
);
return
jio
.
remove
(
doc_id
);
})
})
.
then
(
function
(
doc_id
)
{
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document removed
"
);
ok
(
doc_id
,
"
Document removed
"
);
// Create some documents to check allDocs
// Create some documents to check allDocs
return
RSVP
.
all
([
return
RSVP
.
all
([
jio
.
put
(
{
"
_id
"
:
"
id1
"
,
"
title
"
:
"
1 ID
"
,
"
int_index
"
:
1
}),
jio
.
put
(
"
id1
"
,
{
"
title
"
:
"
1 ID
"
,
"
int_index
"
:
1
}),
jio
.
put
(
{
"
_id
"
:
"
id2
"
,
"
title
"
:
"
2 ID
"
,
"
int_index
"
:
2
}),
jio
.
put
(
"
id2
"
,
{
"
title
"
:
"
2 ID
"
,
"
int_index
"
:
2
}),
jio
.
put
(
{
"
_id
"
:
"
id3
"
,
"
title
"
:
"
3 ID
"
,
"
int_index
"
:
3
})
jio
.
put
(
"
id3
"
,
{
"
title
"
:
"
3 ID
"
,
"
int_index
"
:
3
})
]);
]);
})
})
.
then
(
function
(
all_doc_id
)
{
.
then
(
function
(
all_doc_id
)
{
...
@@ -83,27 +172,28 @@
...
@@ -83,27 +172,28 @@
equal
(
all_doc_id
[
1
],
"
id2
"
,
"
Document 2 correctly created
"
);
equal
(
all_doc_id
[
1
],
"
id2
"
,
"
Document 2 correctly created
"
);
equal
(
all_doc_id
[
2
],
"
id3
"
,
"
Document 3 correctly created
"
);
equal
(
all_doc_id
[
2
],
"
id3
"
,
"
Document 3 correctly created
"
);
// Default allDocs call
//
// Default allDocs call
return
jio
.
allDocs
();
//
return jio.allDocs();
})
//
})
.
then
(
function
(
result
)
{
//
.then(function (result) {
deepEqual
(
result
,
{
//
deepEqual(result, {
data
:
{
//
data: {
rows
:
[{
//
rows: [{
id
:
"
id1
"
,
//
id: "id1",
value
:
{}
//
value: {}
},
{
//
}, {
id
:
"
id2
"
,
//
id: "id2",
value
:
{}
//
value: {}
},
{
//
}, {
id
:
"
id3
"
,
//
id: "id3",
value
:
{}
//
value: {}
}],
//
}],
total_rows
:
3
//
total_rows: 3
}
//
}
},
"
default allDocs OK
"
);
//
}, "default allDocs OK");
// Filter the result
// Filter the result
console
.
log
(
"
START ALLDOCS
"
);
return
jio
.
allDocs
({
return
jio
.
allDocs
({
query
:
'
title: "2 ID"
'
,
query
:
'
title: "2 ID"
'
,
select_list
:
[
"
int_index
"
]
select_list
:
[
"
int_index
"
]
...
@@ -123,7 +213,65 @@
...
@@ -123,7 +213,65 @@
// XXX Check include docs, sort, limit, select
// XXX Check include docs, sort, limit, select
})
})
.
then
(
function
()
{
return
jio
.
getAttachment
(
"
inexistent
"
,
"
enclosure
"
)
.
fail
(
function
(
error
)
{
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
console
.
log
(
error
);
});
})
.
then
(
function
()
{
return
jio
.
put
(
"
test.txt
"
,
{});
})
.
then
(
function
()
{
return
jio
.
putAttachment
(
"
test.txt
"
,
"
enclosure
"
,
new
Blob
([
"
fooé
\n
bar
"
],
{
type
:
"
text/plain
"
})
);
})
.
then
(
function
()
{
ok
(
true
,
"
Attachment stored
"
);
return
jio
.
getAttachment
(
"
test.txt
"
,
"
enclosure
"
);
})
.
then
(
function
(
blob
)
{
return
jIO
.
util
.
readBlobAsText
(
blob
);
})
.
then
(
function
(
result
)
{
equal
(
result
.
target
.
result
,
"
fooé
\n
bar
"
,
"
Attachment correctly fetched
"
);
return
jio
.
get
(
"
test.txt
"
);
})
.
then
(
function
(
doc
)
{
deepEqual
(
doc
,
{},
"
Document correctly fetched
"
);
return
jio
.
allAttachments
(
"
test.txt
"
);
})
.
then
(
function
(
doc
)
{
deepEqual
(
doc
,
{
enclosure
:
{}
},
"
Attachment list correctly fetched
"
);
return
jio
.
removeAttachment
(
"
test.txt
"
,
"
enclosure
"
);
})
.
then
(
function
()
{
ok
(
"
Attachment removed
"
);
})
.
then
(
function
()
{
return
jio
.
repair
();
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
console
.
error
(
"
---
"
);
console
.
error
(
error
.
stack
);
console
.
error
(
error
.
stack
);
console
.
error
(
error
);
console
.
error
(
error
);
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -134,5 +282,4 @@
...
@@ -134,5 +282,4 @@
});
});
});
});
}(
window
,
QUnit
,
jIO
,
rJS
));
}(
window
,
QUnit
,
jIO
,
rJS
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment