Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
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 @@
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<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/renderjs/dist/renderjs-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>
</head>
...
...
examples/scenario.js
View file @
4fdf47f9
/*global console, btoa*/
/*jslint nomen: true*/
/*global console, btoa
, Blob
*/
/*jslint nomen: true
, maxlen: 200
*/
(
function
(
window
,
QUnit
,
jIO
,
rJS
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
...
...
@@ -11,34 +11,116 @@
deepEqual
=
QUnit
.
deepEqual
;
rJS
(
window
)
.
ready
(
function
(
g
)
{
return
g
.
run
({
"
type
"
:
"
indexeddb
"
,
"
database
"
:
"
test
"
});
})
.
ready
(
function
(
g
)
{
return
g
.
run
({
type
:
"
query
"
,
sub_storage
:
{
type
:
"
local
"
}
});
})
.
ready
(
function
(
g
)
{
return
g
.
run
({
type
:
"
query
"
,
sub_storage
:
{
"
type
"
:
"
dav
"
}
});
///////////////////////////
// Local storage
///////////////////////////
// return g.run({
// type: "query",
// sub_storage: {
// type: "uuid",
// sub_storage: {
// type: "document",
// document_id: "/",
// sub_storage: {
// type: "local"
// }
// }
// }
// });
///////////////////////////
// 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
)
{
test
(
'
Test "
'
+
jio_options
.
type
+
'
"scenario
'
,
function
()
{
var
jio
;
stop
();
expect
(
9
);
expect
(
14
);
try
{
jio
=
jIO
.
createJIO
(
jio_options
);
...
...
@@ -49,33 +131,40 @@
}
// Try to fetch inexistent document
jio
.
get
(
{
"
_id
"
:
"
inexistent
"
}
)
jio
.
get
(
"
inexistent
"
)
.
fail
(
function
(
error
)
{
console
.
error
(
error
);
if
(
error
.
status_code
!==
404
)
{
throw
error
;
}
equal
(
error
.
status_code
,
404
,
"
404 if inexistent
"
);
// 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
)
{
ok
(
doc_id
,
"
Document without ID created
"
);
ok
(
doc_id
,
"
Document without ID created
(
"
+
doc_id
+
"
)
"
);
// Fetch the newly created document
return
jio
.
get
({
"
_id
"
:
doc_id
});
return
RSVP
.
all
([
jio
.
get
(
doc_id
),
doc_id
]);
})
.
then
(
function
(
doc
)
{
var
doc
_id
=
doc
.
_id
;
delete
doc
.
_id
;
deepEqual
(
doc
,
{
"
title
"
:
"
I don't have ID
"
},
.
then
(
function
(
result_list
)
{
var
doc
=
result_list
[
0
],
doc_id
=
result_list
[
1
]
;
deepEqual
(
doc
,
{
"
title
"
:
"
I don't have ID
éà&
\n
"
},
"
Document correctly fetched
"
);
// Remove the doc
return
jio
.
remove
(
{
"
_id
"
:
doc_id
}
);
return
jio
.
remove
(
doc_id
);
})
.
then
(
function
(
doc_id
)
{
ok
(
doc_id
,
"
Document removed
"
);
// Create some documents to check allDocs
return
RSVP
.
all
([
jio
.
put
(
{
"
_id
"
:
"
id1
"
,
"
title
"
:
"
1 ID
"
,
"
int_index
"
:
1
}),
jio
.
put
(
{
"
_id
"
:
"
id2
"
,
"
title
"
:
"
2 ID
"
,
"
int_index
"
:
2
}),
jio
.
put
(
{
"
_id
"
:
"
id3
"
,
"
title
"
:
"
3 ID
"
,
"
int_index
"
:
3
})
jio
.
put
(
"
id1
"
,
{
"
title
"
:
"
1 ID
"
,
"
int_index
"
:
1
}),
jio
.
put
(
"
id2
"
,
{
"
title
"
:
"
2 ID
"
,
"
int_index
"
:
2
}),
jio
.
put
(
"
id3
"
,
{
"
title
"
:
"
3 ID
"
,
"
int_index
"
:
3
})
]);
})
.
then
(
function
(
all_doc_id
)
{
...
...
@@ -83,27 +172,28 @@
equal
(
all_doc_id
[
1
],
"
id2
"
,
"
Document 2 correctly created
"
);
equal
(
all_doc_id
[
2
],
"
id3
"
,
"
Document 3 correctly created
"
);
// Default allDocs call
return
jio
.
allDocs
();
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
id1
"
,
value
:
{}
},
{
id
:
"
id2
"
,
value
:
{}
},
{
id
:
"
id3
"
,
value
:
{}
}],
total_rows
:
3
}
},
"
default allDocs OK
"
);
//
// Default allDocs call
//
return jio.allDocs();
//
})
//
.then(function (result) {
//
deepEqual(result, {
//
data: {
//
rows: [{
//
id: "id1",
//
value: {}
//
}, {
//
id: "id2",
//
value: {}
//
}, {
//
id: "id3",
//
value: {}
//
}],
//
total_rows: 3
//
}
//
}, "default allDocs OK");
// Filter the result
console
.
log
(
"
START ALLDOCS
"
);
return
jio
.
allDocs
({
query
:
'
title: "2 ID"
'
,
select_list
:
[
"
int_index
"
]
...
...
@@ -123,7 +213,65 @@
// 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
)
{
console
.
error
(
"
---
"
);
console
.
error
(
error
.
stack
);
console
.
error
(
error
);
ok
(
false
,
error
);
...
...
@@ -134,5 +282,4 @@
});
});
}(
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