1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Frank Celler 2014-05-09 17:15:11 +02:00
commit 65ad94d9cf
50 changed files with 5206 additions and 4121 deletions

View File

@ -17,9 +17,9 @@ import (
// event happens between the end of the first watch command and the start
// of the second command.
type watcherHub struct {
count int64 // current number of watchers.
mutex sync.Mutex // protect the hash map
watchers map[string]*list.List
count int64 // current number of watchers.
EventHistory *EventHistory
}

View File

@ -26,12 +26,12 @@ import (
// Logger is user-immutable immutable struct which can log to several outputs
type Logger struct {
seq uint64 // sequential number of log message, starting at 1
sinks []Sink // the sinks this logger will log to
verbose bool // gather expensive logging data?
prefix string // static field available to all log sinks under this logger
created time.Time // time when this logger was created
seq uint64 // sequential number of log message, starting at 1
executable string // executable name
}

View File

@ -77,11 +77,11 @@ func (NilEWMA) Update(n int64) {}
// of uncounted events and processes them on each tick. It uses the
// sync/atomic package to manage uncounted events.
type StandardEWMA struct {
uncounted int64
alpha float64
init bool
mutex sync.Mutex
rate float64
uncounted int64
}
// Rate returns the moving average rate of events per second.

View File

@ -37,8 +37,8 @@ type Sample interface {
//
// <http://www.research.att.com/people/Cormode_Graham/library/publications/CormodeShkapenyukSrivastavaXu09.pdf>
type ExpDecaySample struct {
alpha float64
count int64
alpha float64
mutex sync.Mutex
reservoirSize int
t0, t1 time.Time
@ -390,9 +390,9 @@ func SampleVariance(values []int64) float64 {
// <http://www.cs.umd.edu/~samir/498/vitter.pdf>
type UniformSample struct {
count int64
values []int64
mutex sync.Mutex
reservoirSize int
values []int64
}
// NewUniformSample constructs a new uniform sample with the given reservoir
@ -519,8 +519,8 @@ func (s *UniformSample) Variance() float64 {
// expDecaySample represents an individual sample in a heap.
type expDecaySample struct {
k float64
v int64
k float64
}
// expDecaySampleHeap is a min-heap of expDecaySamples.

View File

@ -1,6 +1,10 @@
v2.1.0 (XXXX-XX-XX)
-------------------
* decrease the size of some seldomly used system collections on creation.
This will make these collections use less disk space and mapped memory.
* fixed issue #848: db.someEdgeCollection.inEdge does not return correct
value when called the 2nd time after a .save to the edge collection
@ -105,7 +109,26 @@ v2.1.0 (XXXX-XX-XX)
* export the sort attribute for graph traversals to the HTTP interface
v2.0.7 (XXXX-XX-XX)
v2.0.8 (XXXX-XX-XX)
-------------------
* fixed timeout overflows on 32 bit systems
this bug has led to problems when select was called with a high timeout
value (2000+ seconds) on 32bit systems that don't have a forgiving select
implementation. when the call was made on these systems, select failed
so no data would be read or sent over the connection
this might have affected some cluster-internal operations.
* fixed ETCD issues on 32 bit systems
ETCD was non-functional on 32 bit systems at all. The first call to the
watch API crashed it. This was because atomic operations worked on data
structures that were not properly aligned on 32 bit systems.
v2.0.7 (2014-05-05)
-------------------
* issue #839: Foxx Manager missing "unfetch"

View File

@ -101,6 +101,14 @@ namespace triagens {
return triagens::basics::JsonHelper::stringUInt64(_json, "id");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection id as a string
////////////////////////////////////////////////////////////////////////////////
string id_as_string () const {
return triagens::basics::JsonHelper::getStringValue(_json, "id", "");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection name
////////////////////////////////////////////////////////////////////////////////

View File

@ -45,6 +45,7 @@
#include "VocBase/replication-logger.h"
#include "VocBase/server.h"
#include "VocBase/update-policy.h"
#include "VocBase/index.h"
#ifdef TRI_ENABLE_CLUSTER
#include "Cluster/ClusterMethods.h"
@ -2158,7 +2159,7 @@ int RestReplicationHandler::processRestoreCollectionCoordinator (
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
TRI_json_t const* parameters = JsonHelper::getArrayElement(collection, "parameters");
TRI_json_t* parameters = JsonHelper::getArrayElement(collection, "parameters");
if (! JsonHelper::isArray(parameters)) {
errorMsg = "collection parameters declaration is invalid";
@ -2166,14 +2167,6 @@ int RestReplicationHandler::processRestoreCollectionCoordinator (
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
TRI_json_t const* indexes = JsonHelper::getArrayElement(collection, "indexes");
if (! JsonHelper::isList(indexes)) {
errorMsg = "collection indexes declaration is invalid";
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
const string name = JsonHelper::getStringValue(parameters, "name", "");
if (name.empty()) {
@ -2187,56 +2180,24 @@ int RestReplicationHandler::processRestoreCollectionCoordinator (
return TRI_ERROR_NO_ERROR;
}
TRI_vocbase_col_t* col = 0;
string dbName = _vocbase->_name;
if (reuseId) {
TRI_json_t const* idString = JsonHelper::getArrayElement(parameters, "cid");
if (! JsonHelper::isString(idString)) {
errorMsg = "collection id is missing";
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
TRI_voc_cid_t cid = StringUtils::uint64(idString->_value._string.data, idString->_value._string.length - 1);
// first look up the collection by the cid
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
}
if (col == 0) {
// not found, try name next
col = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
}
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
TRI_shared_ptr<CollectionInfo> col = ci->getCollection(dbName, name);
// drop an existing collection if it exists
if (col != 0) {
if (! col->empty()) {
if (dropExisting) {
int res = TRI_DropCollectionVocBase(_vocbase, col, remoteServerId);
int res = ci->dropCollectionCoordinator(dbName, col->id_as_string(),
errorMsg, 0.0);
if (res == TRI_ERROR_FORBIDDEN) {
// some collections must not be dropped
// instead, truncate them
CollectionNameResolver resolver(_vocbase);
SingleCollectionWriteTransaction<EmbeddableTransaction<RestTransactionContext>, UINT64_MAX> trx(_vocbase, resolver, col->_cid);
res = trx.begin();
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
TRI_barrier_t* barrier = TRI_CreateBarrierElement(&(trx.primaryCollection()->_barrierList));
if (barrier == 0) {
return TRI_ERROR_INTERNAL;
}
res = trx.truncate(false);
res = trx.finish(res);
TRI_FreeBarrier(barrier);
// ...
// do a fanout to all shards and truncate them, use col and asyncreq.
// return res;
return res;
}
@ -2256,7 +2217,78 @@ int RestReplicationHandler::processRestoreCollectionCoordinator (
}
// now re-create the collection
int res = createCollection(parameters, &col, reuseId, remoteServerId);
// dig out number of shards:
TRI_json_t const* shards = JsonHelper::getArrayElement(parameters, "shards");
if (0 == shards) {
errorMsg = "did not find \"shards\" attribute in parameters";
return TRI_ERROR_INTERNAL;
}
if (! TRI_IsArrayJson(shards)) {
errorMsg = "\"shards\" attribute in parameters is not an array";
return TRI_ERROR_INTERNAL;
}
uint64_t numberOfShards = TRI_LengthVector(&shards->_value._objects)/2;
TRI_voc_tick_t new_id_tick = ci->uniqid(1);
string new_id = StringUtils::itoa(new_id_tick);
TRI_ReplaceArrayJson(TRI_UNKNOWN_MEM_ZONE, parameters, "id",
TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE,
new_id.c_str(), new_id.size()));
// Now put in the primary and an edge index if needed:
TRI_json_t* indexes = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE);
if (indexes == 0) {
errorMsg = "out of memory";
return TRI_ERROR_OUT_OF_MEMORY;
}
// create a dummy primary index
TRI_index_t* idx = TRI_CreatePrimaryIndex(0);
if (idx == 0) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, indexes);
errorMsg = "out of memory";
return TRI_ERROR_OUT_OF_MEMORY;
}
TRI_json_t* idxJson = idx->json(idx);
TRI_FreeIndex(idx);
TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, indexes, TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, idxJson));
TRI_FreeJson(TRI_CORE_MEM_ZONE, idxJson);
TRI_json_t* type = TRI_LookupArrayJson(parameters, "type");
TRI_col_type_e collectionType;
if (TRI_IsNumberJson(type)) {
collectionType = (TRI_col_type_e) type->_value._number;
}
else {
errorMsg = "collection type not given or wrong";
return TRI_ERROR_HTTP_BAD_PARAMETER;
}
if (collectionType == TRI_COL_TYPE_EDGE) {
// create a dummy edge index
idx = TRI_CreateEdgeIndex(0, new_id_tick);
if (idx == 0) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, indexes);
errorMsg = "cannot create edge index";
return TRI_ERROR_INTERNAL;
}
idxJson = idx->json(idx);
TRI_FreeIndex(idx);
TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, indexes, TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, idxJson));
TRI_FreeJson(TRI_CORE_MEM_ZONE, idxJson);
}
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, parameters, "indexes", indexes);
int res = ci->createCollectionCoordinator(dbName, new_id, numberOfShards,
parameters, errorMsg, 0.0);
if (res != TRI_ERROR_NO_ERROR) {
errorMsg = "unable to create collection: " + string(TRI_errno_string(res));
@ -2422,57 +2454,30 @@ int RestReplicationHandler::processRestoreIndexesCoordinator (
return TRI_ERROR_NO_ERROR;
}
// look up the collection
TRI_vocbase_col_t* col = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
string dbName = _vocbase->_name;
if (col == 0) {
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
TRI_shared_ptr<CollectionInfo> col = ci->getCollection(dbName, name);
if (col->empty()) {
errorMsg = "could not find collection '" + name + "'";
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
int res = TRI_UseCollectionVocBase(_vocbase, col);
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
TRI_primary_collection_t* primary = col->_collection;
TRI_ReadLockReadWriteLock(&_vocbase->_inventoryLock);
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
int res = TRI_ERROR_NO_ERROR;
for (size_t i = 0; i < n; ++i) {
TRI_json_t const* idxDef = (TRI_json_t const*) TRI_AtVector(&indexes->_value._objects, i);
TRI_index_t* idx = 0;
// {"id":"229907440927234","type":"hash","unique":false,"fields":["x","Y"]}
res = TRI_FromJsonIndexDocumentCollection((TRI_document_collection_t*) primary, idxDef, &idx);
TRI_json_t* res_json = 0;
res = ci->ensureIndexCoordinator(dbName, col->id_as_string(), idxDef,
true, IndexComparator, res_json, errorMsg, 3600.0);
if (res != TRI_ERROR_NO_ERROR) {
errorMsg = "could not create index: " + string(TRI_errno_string(res));
break;
}
else {
assert(idx != 0);
res = TRI_SaveIndex(primary, idx, remoteServerId);
if (res != TRI_ERROR_NO_ERROR) {
errorMsg = "could not save index: " + string(TRI_errno_string(res));
break;
}
}
}
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(primary);
TRI_ReadUnlockReadWriteLock(&_vocbase->_inventoryLock);
TRI_ReleaseCollectionVocBase(_vocbase, col);
return TRI_ERROR_NO_ERROR;
return res;
}
#endif
@ -2825,54 +2830,252 @@ void RestReplicationHandler::handleCommandRestoreData () {
#ifdef TRI_ENABLE_CLUSTER
void RestReplicationHandler::handleCommandRestoreDataCoordinator () {
char const* value = _request->value("collection");
char const* name = _request->value("collection");
if (value == 0) {
if (name == 0) {
generateError(HttpResponse::BAD,
TRI_ERROR_HTTP_BAD_PARAMETER,
"invalid collection parameter");
return;
}
CollectionNameResolver resolver(_vocbase);
TRI_voc_cid_t cid = resolver.getCollectionId(value);
if (cid == 0) {
generateError(HttpResponse::BAD,
TRI_ERROR_HTTP_BAD_PARAMETER,
"invalid collection parameter");
return;
}
bool recycleIds = false;
value = _request->value("recycleIds");
if (value != 0) {
recycleIds = StringUtils::boolean(value);
}
bool force = false;
value = _request->value("force");
if (value != 0) {
force = StringUtils::boolean(value);
}
TRI_server_id_t remoteServerId = 0; // TODO
string dbName = _vocbase->_name;
string errorMsg;
int res = processRestoreData(resolver, cid, remoteServerId, recycleIds, force, errorMsg);
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
TRI_shared_ptr<CollectionInfo> col = ci->getCollection(dbName, name);
if (col->empty()) {
generateError(HttpResponse::BAD, TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
return;
}
// We need to distribute the documents we get over the shards:
map<ShardID, ServerID> shardIdsMap = col->shardIds();
map<string, size_t> shardTab;
vector<string> shardIds;
map<ShardID, ServerID>::iterator it;
map<string, size_t>::iterator it2;
for (it = shardIdsMap.begin(); it != shardIdsMap.end(); it++) {
shardTab.insert(make_pair(it->first,shardIds.size()));
shardIds.push_back(it->first);
}
vector<StringBuffer*> bufs;
size_t j;
for (j = 0; j < shardIds.size(); j++) {
bufs.push_back(new StringBuffer(TRI_UNKNOWN_MEM_ZONE));
}
const string invalidMsg = string("received invalid JSON data for collection ")
+ name;
char const* ptr = _request->body();
char const* end = ptr + _request->bodySize();
int res = TRI_ERROR_NO_ERROR;
while (ptr < end) {
char const* pos = strchr(ptr, '\n');
if (pos == 0) {
pos = end;
}
else {
*((char*) pos) = '\0';
}
if (pos - ptr > 1) {
// found something
TRI_json_t* json = TRI_JsonString(TRI_CORE_MEM_ZONE, ptr);
if (! JsonHelper::isArray(json)) {
if (json != 0) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
}
errorMsg = invalidMsg;
res = TRI_ERROR_HTTP_CORRUPTED_JSON;
break;
}
const char* key = 0;
TRI_json_t const* doc = 0;
TRI_replication_operation_e type;
const size_t n = json->_value._objects._length;
for (size_t i = 0; i < n; i += 2) {
TRI_json_t const* element
= (TRI_json_t const*) TRI_AtVector(&json->_value._objects, i);
if (! JsonHelper::isString(element)) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
errorMsg = invalidMsg;
res = TRI_ERROR_HTTP_CORRUPTED_JSON;
break;
}
const char* attributeName = element->_value._string.data;
TRI_json_t const* value = (TRI_json_t const*) TRI_AtVector(&json->_value._objects, i + 1);
if (TRI_EqualString(attributeName, "type")) {
if (JsonHelper::isNumber(value)) {
type = (TRI_replication_operation_e) (int) value->_value._number;
}
}
else if (TRI_EqualString(attributeName, "key")) {
if (JsonHelper::isString(value)) {
key = value->_value._string.data;
}
}
else if (TRI_EqualString(attributeName, "data")) {
if (JsonHelper::isArray(value)) {
doc = value;
}
}
}
if (res != TRI_ERROR_NO_ERROR) {
break;
}
// key must not be 0, but doc can be 0!
if (key == 0) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
errorMsg = invalidMsg;
res = TRI_ERROR_HTTP_BAD_PARAMETER;
break;
}
if (0 != doc && type != MARKER_REMOVE) {
ShardID responsibleShard;
bool usesDefaultSharding;
res = ci->getResponsibleShard(col->id_as_string(), doc, true,
responsibleShard, usesDefaultSharding);
if (res != TRI_ERROR_NO_ERROR) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
errorMsg = "error during determining responsible shard";
res = TRI_ERROR_INTERNAL;
break;
}
else {
it2 = shardTab.find(responsibleShard);
if (it2 == shardTab.end()) {
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
errorMsg = "cannot find responsible shard";
res = TRI_ERROR_INTERNAL;
break;
}
else {
bufs[it2->second]->appendText(ptr, pos-ptr);
bufs[it2->second]->appendText("\n");
}
}
}
else if (type == MARKER_REMOVE) {
// A remove marker, this has to be appended to all!
for (j = 0; j < bufs.size(); j++) {
bufs[j]->appendText(ptr, pos-ptr);
bufs[j]->appendText("\n");
}
}
else {
// How very strange!
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
errorMsg = invalidMsg;
res = TRI_ERROR_HTTP_BAD_PARAMETER;
break;
}
TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
}
ptr = pos + 1;
}
if (res == TRI_ERROR_NO_ERROR) {
// Set a few variables needed for our work:
ClusterComm* cc = ClusterComm::instance();
// Send a synchronous request to that shard using ClusterComm:
ClusterCommResult* result;
CoordTransactionID coordTransactionID = TRI_NewTickServer();
for (it = shardIdsMap.begin(); it != shardIdsMap.end(); ++it) {
map<string, string>* headers = new map<string, string>;
it2 = shardTab.find(it->first);
if (it2 == shardTab.end()) {
errorMsg = "cannot find shard";
res = TRI_ERROR_INTERNAL;
}
else {
j = it2->second;
result = cc->asyncRequest("", coordTransactionID, "shard:" + it->first,
triagens::rest::HttpRequest::HTTP_REQUEST_PUT,
"/_db/" + StringUtils::urlEncode(dbName) +
"/_api/replication/restore-data?collection=" +
it->first,
new string(bufs[j]->c_str(), bufs[j]->length()),
true, headers, NULL, 300.0);
delete result;
}
}
// Now listen to the results:
int count;
int nrok = 0;
for (count = (int) shardIdsMap.size(); count > 0; count--) {
result = cc->wait( "", coordTransactionID, 0, "", 0.0);
if (result->status == CL_COMM_RECEIVED) {
if (result->answer_code == triagens::rest::HttpResponse::OK ||
result->answer_code == triagens::rest::HttpResponse::CREATED) {
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE,
result->answer->body());
if (JsonHelper::isArray(json)) {
TRI_json_t const* r = TRI_LookupArrayJson(json, "result");
if (TRI_IsBooleanJson(r)) {
if (r->_value._boolean) {
nrok++;
}
}
}
if (json != 0) {
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
}
}
}
delete result;
}
if (nrok != shardIdsMap.size()) {
errorMsg = "some shard produced an error";
res = TRI_ERROR_INTERNAL;
}
}
// Free all the string buffers:
for (j = 0; j < shardIds.size(); j++) {
delete bufs[j];
}
if (res != TRI_ERROR_NO_ERROR) {
generateError(HttpResponse::SERVER_ERROR, res);
generateError(HttpResponse::BAD, res, errorMsg);
}
else {
TRI_json_t result;
TRI_InitArrayJson(TRI_CORE_MEM_ZONE, &result);
TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, &result, "result", TRI_CreateBooleanJson(TRI_CORE_MEM_ZONE, true));
TRI_json_t result;
generateResult(&result);
}
TRI_InitArrayJson(TRI_CORE_MEM_ZONE, &result);
TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, &result, "result", TRI_CreateBooleanJson(TRI_CORE_MEM_ZONE, true));
generateResult(&result);
}
#endif

View File

@ -529,7 +529,7 @@ static v8::Handle<v8::Object> RequestCppToV8 ( TRI_v8_global_t const* v8g,
////////////////////////////////////////////////////////////////////////////////
static HttpResponse* ResponseV8ToCpp (TRI_v8_global_t const* v8g,
v8::Handle<v8::Object> const& res,
v8::Handle<v8::Object> const res,
uint32_t compatibility) {
HttpResponse::HttpResponseCode code = HttpResponse::OK;

View File

@ -229,7 +229,7 @@ static void CleanupExampleObject (TRI_memory_zone_t* zone,
/// @brief sets up the example object
////////////////////////////////////////////////////////////////////////////////
static int SetupExampleObject (v8::Handle<v8::Object> const& example,
static int SetupExampleObject (v8::Handle<v8::Object> const example,
TRI_shaper_t* shaper,
size_t& n,
TRI_shape_pid_t*& pids,

View File

@ -73,6 +73,7 @@
#include "VocBase/replication-logger.h"
#include "VocBase/server.h"
#include "VocBase/voc-shaper.h"
#include "VocBase/index.h"
#include "v8.h"
#include "V8/JSLoader.h"
@ -202,7 +203,7 @@ static int32_t const WRP_SHAPED_JSON_TYPE = 4;
////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_ENABLE_CLUSTER
static int ParseKeyAndRef (v8::Handle<v8::Value> const& arg,
static int ParseKeyAndRef (v8::Handle<v8::Value> const arg,
string& key,
TRI_voc_rid_t& rev) {
TRI_v8_global_t* v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData();
@ -497,7 +498,7 @@ static inline TRI_vocbase_t* GetContextVocBase () {
/// @brief checks if argument is a document identifier
////////////////////////////////////////////////////////////////////////////////
static bool ParseDocumentHandle (v8::Handle<v8::Value> const& arg,
static bool ParseDocumentHandle (v8::Handle<v8::Value> const arg,
string& collectionName,
TRI_voc_key_t& key) {
assert(collectionName == "");
@ -534,7 +535,7 @@ static bool ParseDocumentHandle (v8::Handle<v8::Value> const& arg,
/// @brief extracts a document key from a document
////////////////////////////////////////////////////////////////////////////////
static int ExtractDocumentKey (v8::Handle<v8::Value> const& arg,
static int ExtractDocumentKey (v8::Handle<v8::Value> const arg,
TRI_voc_key_t& key) {
TRI_v8_global_t* v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData();
key = 0;
@ -576,7 +577,7 @@ static int ExtractDocumentKey (v8::Handle<v8::Value> const& arg,
/// @brief parse document or document handle from a v8 value (string | object)
////////////////////////////////////////////////////////////////////////////////
static bool ExtractDocumentHandle (v8::Handle<v8::Value> const& val,
static bool ExtractDocumentHandle (v8::Handle<v8::Value> const val,
string& collectionName,
TRI_voc_key_t& key,
TRI_voc_rid_t& rid) {
@ -656,7 +657,7 @@ static v8::Handle<v8::Value> ParseDocumentOrDocumentHandle (TRI_vocbase_t* vocba
TRI_vocbase_col_t const*& collection,
TRI_voc_key_t& key,
TRI_voc_rid_t& rid,
v8::Handle<v8::Value> const& val) {
v8::Handle<v8::Value> const val) {
v8::HandleScope scope;
assert(key == 0);
@ -745,7 +746,7 @@ static v8::Handle<v8::Value> ParseDocumentOrDocumentHandle (TRI_vocbase_t* vocba
/// @brief checks if argument is an index identifier
////////////////////////////////////////////////////////////////////////////////
static bool IsIndexHandle (v8::Handle<v8::Value> const& arg,
static bool IsIndexHandle (v8::Handle<v8::Value> const arg,
string& collectionName,
TRI_idx_iid_t& iid) {
@ -876,162 +877,11 @@ static v8::Handle<v8::Value> IndexRep (string const& collectionName,
return scope.Close(rep);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief index comparator, used by the coordinator to detect if two index
/// contents are the same
////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_ENABLE_CLUSTER
static bool IndexComparator (TRI_json_t const* lhs,
TRI_json_t const* rhs) {
TRI_json_t* typeJson = TRI_LookupArrayJson(lhs, "type");
assert(TRI_IsStringJson(typeJson));
// type must be identical
if (! TRI_CheckSameValueJson(typeJson, TRI_LookupArrayJson(rhs, "type"))) {
return false;
}
TRI_idx_type_e type = TRI_TypeIndex(typeJson->_value._string.data);
// unique must be identical if present
TRI_json_t* value = TRI_LookupArrayJson(lhs, "unique");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "unique"))) {
return false;
}
}
if (type == TRI_IDX_TYPE_GEO1_INDEX) {
// geoJson must be identical if present
value = TRI_LookupArrayJson(lhs, "geoJson");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "geoJson"))) {
return false;
}
}
value = TRI_LookupArrayJson(lhs, "ignoreNull");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "ignoreNull"))) {
return false;
}
}
}
else if (type == TRI_IDX_TYPE_GEO2_INDEX) {
value = TRI_LookupArrayJson(lhs, "ignoreNull");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "ignoreNull"))) {
return false;
}
}
}
else if (type == TRI_IDX_TYPE_FULLTEXT_INDEX) {
// minLength
value = TRI_LookupArrayJson(lhs, "minLength");
if (TRI_IsNumberJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "minLength"))) {
return false;
}
}
}
else if (type == TRI_IDX_TYPE_CAP_CONSTRAINT) {
// size, byteSize
value = TRI_LookupArrayJson(lhs, "size");
if (TRI_IsNumberJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "size"))) {
return false;
}
}
value = TRI_LookupArrayJson(lhs, "byteSize");
if (TRI_IsNumberJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "byteSize"))) {
return false;
}
}
}
if (type == TRI_IDX_TYPE_BITARRAY_INDEX) {
// bitarray indexes are considered identical if they are based on the same attributes
TRI_json_t const* r = TRI_LookupArrayJson(rhs, "fields");
value = TRI_LookupArrayJson(lhs, "fields");
if (TRI_IsListJson(value) &&
TRI_IsListJson(r) &&
value->_value._objects._length == r->_value._objects._length) {
for (size_t i = 0; i < value->_value._objects._length; ++i) {
TRI_json_t const* l1 = TRI_LookupListJson(value, i);
TRI_json_t const* r1 = TRI_LookupListJson(r, i);
if (TRI_IsListJson(l1) &&
TRI_IsListJson(r1) &&
l1->_value._objects._length == 2 &&
r1->_value._objects._length == 2) {
// element at position 0 is the attribute name
if (! TRI_CheckSameValueJson(TRI_LookupListJson(l1, 0), TRI_LookupListJson(r1, 0))) {
return false;
}
}
}
}
// we must always exit here to avoid the "regular" fields comparison
return true;
}
// other index types: fields must be identical if present
value = TRI_LookupArrayJson(lhs, "fields");
if (TRI_IsListJson(value)) {
if (type == TRI_IDX_TYPE_HASH_INDEX) {
// compare fields in arbitrary order
TRI_json_t const* r = TRI_LookupArrayJson(rhs, "fields");
if (! TRI_IsListJson(r) ||
value->_value._objects._length != r->_value._objects._length) {
return false;
}
for (size_t i = 0; i < value->_value._objects._length; ++i) {
TRI_json_t const* v = TRI_LookupListJson(value, i);
bool found = false;
for (size_t j = 0; j < r->_value._objects._length; ++j) {
if (TRI_CheckSameValueJson(v, TRI_LookupListJson(r, j))) {
found = true;
break;
}
}
if (! found) {
return false;
}
}
}
else {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "fields"))) {
return false;
}
}
}
return true;
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief extract the unique flag from the data
////////////////////////////////////////////////////////////////////////////////
bool ExtractBoolFlag (v8::Handle<v8::Object> const& obj,
bool ExtractBoolFlag (v8::Handle<v8::Object> const obj,
char const* name,
bool defaultValue) {
// extract unique flag
@ -1046,7 +896,7 @@ bool ExtractBoolFlag (v8::Handle<v8::Object> const& obj,
/// @brief process the fields list and add them to the json
////////////////////////////////////////////////////////////////////////////////
int ProcessBitarrayIndexFields (v8::Handle<v8::Object> const& obj,
int ProcessBitarrayIndexFields (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
vector<string> fields;
@ -1136,7 +986,7 @@ int ProcessBitarrayIndexFields (v8::Handle<v8::Object> const& obj,
/// @brief process the fields list and add them to the json
////////////////////////////////////////////////////////////////////////////////
int ProcessIndexFields (v8::Handle<v8::Object> const& obj,
int ProcessIndexFields (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
int numFields,
bool create) {
@ -1189,7 +1039,7 @@ int ProcessIndexFields (v8::Handle<v8::Object> const& obj,
/// @brief process the geojson flag and add it to the json
////////////////////////////////////////////////////////////////////////////////
int ProcessIndexGeoJsonFlag (v8::Handle<v8::Object> const& obj,
int ProcessIndexGeoJsonFlag (v8::Handle<v8::Object> const obj,
TRI_json_t* json) {
bool geoJson = ExtractBoolFlag(obj, "geoJson", false);
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "geoJson", TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, geoJson));
@ -1201,7 +1051,7 @@ int ProcessIndexGeoJsonFlag (v8::Handle<v8::Object> const& obj,
/// @brief process the unique flag and add it to the json
////////////////////////////////////////////////////////////////////////////////
int ProcessIndexUniqueFlag (v8::Handle<v8::Object> const& obj,
int ProcessIndexUniqueFlag (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool fillConstraint = false) {
bool unique = ExtractBoolFlag(obj, "unique", false);
@ -1217,7 +1067,7 @@ int ProcessIndexUniqueFlag (v8::Handle<v8::Object> const& obj,
/// @brief process the ignoreNull flag and add it to the json
////////////////////////////////////////////////////////////////////////////////
int ProcessIndexIgnoreNullFlag (v8::Handle<v8::Object> const& obj,
int ProcessIndexIgnoreNullFlag (v8::Handle<v8::Object> const obj,
TRI_json_t* json) {
bool ignoreNull = ExtractBoolFlag(obj, "ignoreNull", false);
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "ignoreNull", TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, ignoreNull));
@ -1229,7 +1079,7 @@ int ProcessIndexIgnoreNullFlag (v8::Handle<v8::Object> const& obj,
/// @brief process the undefined flag and add it to the json
////////////////////////////////////////////////////////////////////////////////
int ProcessIndexUndefinedFlag (v8::Handle<v8::Object> const& obj,
int ProcessIndexUndefinedFlag (v8::Handle<v8::Object> const obj,
TRI_json_t* json) {
bool undefined = ExtractBoolFlag(obj, "undefined", false);
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "undefined", TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, undefined));
@ -1241,7 +1091,7 @@ int ProcessIndexUndefinedFlag (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a geo1 index
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexGeo1 (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexGeo1 (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
int res = ProcessIndexFields(obj, json, 1, create);
@ -1255,7 +1105,7 @@ static int EnhanceJsonIndexGeo1 (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a geo2 index
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexGeo2 (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexGeo2 (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
int res = ProcessIndexFields(obj, json, 2, create);
@ -1268,7 +1118,7 @@ static int EnhanceJsonIndexGeo2 (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a hash index
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexHash (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexHash (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
int res = ProcessIndexFields(obj, json, 0, create);
@ -1280,7 +1130,7 @@ static int EnhanceJsonIndexHash (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a skiplist index
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexSkiplist (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexSkiplist (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
int res = ProcessIndexFields(obj, json, 0, create);
@ -1292,7 +1142,7 @@ static int EnhanceJsonIndexSkiplist (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a bitarray index
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexBitarray (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexBitarray (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
int res = ProcessBitarrayIndexFields(obj, json, create);
@ -1308,7 +1158,7 @@ static int EnhanceJsonIndexBitarray (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a fulltext index
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexFulltext (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexFulltext (v8::Handle<v8::Object> const obj,
TRI_json_t* json,
bool create) {
int res = ProcessIndexFields(obj, json, 1, create);
@ -1327,7 +1177,7 @@ static int EnhanceJsonIndexFulltext (v8::Handle<v8::Object> const& obj,
/// @brief enhances the json of a cap constraint
////////////////////////////////////////////////////////////////////////////////
static int EnhanceJsonIndexCap (v8::Handle<v8::Object> const& obj,
static int EnhanceJsonIndexCap (v8::Handle<v8::Object> const obj,
TRI_json_t* json) {
// handle "size" attribute
size_t count = 0;
@ -5380,9 +5230,6 @@ static v8::Handle<v8::Value> JS_RunAhuacatl (v8::Arguments const& argv) {
TRI_ObjectToString(tryCatch.Exception()).c_str());
return scope.Close(v8::ThrowException(errorObject));
}
else {
return scope.Close(result);
}
}
return scope.Close(result);
@ -6425,7 +6272,7 @@ static v8::Handle<v8::Value> JS_DropVocbaseCol (v8::Arguments const& argv) {
#ifdef TRI_ENABLE_CLUSTER
static v8::Handle<v8::Value> DropIndexCoordinator (CollectionNameResolver const& resolver,
TRI_vocbase_col_t const* collection,
v8::Handle<v8::Value> const& val) {
v8::Handle<v8::Value> const val) {
v8::HandleScope scope;
string collectionName = "";
@ -7755,7 +7602,7 @@ static v8::Handle<v8::Value> SaveVocbaseColCoordinator (TRI_vocbase_col_t* colle
/// @brief extract a key from a v8 object
////////////////////////////////////////////////////////////////////////////////
static string GetId (v8::Handle<v8::Value> const& arg) {
static string GetId (v8::Handle<v8::Value> const arg) {
if (arg->IsObject() && ! arg->IsArray()) {
v8::Local<v8::Object> obj = arg->ToObject();
@ -8402,7 +8249,7 @@ static v8::Handle<v8::Value> MapGetVocBase (v8::Local<v8::String> const name,
////////////////////////////////////////////////////////////////////////////////
static TRI_vocbase_col_t* GetCollectionFromArgument (TRI_vocbase_t* vocbase,
v8::Handle<v8::Value> const& val) {
v8::Handle<v8::Value> const val) {
// number
if (val->IsNumber() || val->IsNumberObject()) {
uint64_t cid = (uint64_t) TRI_ObjectToUInt64(val, true);
@ -9225,16 +9072,20 @@ static v8::Handle<v8::Value> ListDatabasesCoordinator (v8::Arguments const& argv
ClusterCommResult* res;
map<string, string> headers;
headers["Authentication"] = TRI_ObjectToString(argv[2]);
res = cc->syncRequest("", 0, "server:"+sid,
res = cc->syncRequest("", 0, "server:" + sid,
triagens::rest::HttpRequest::HTTP_REQUEST_GET,
"/_api/database/user", string(""), headers, 0.0);
if (res->status == CL_COMM_SENT) {
// We got an array back as JSON, let's parse it and build a v8
StringBuffer& body = res->result->getBody();
delete res;
TRI_json_t* json = JsonHelper::fromString(body.c_str());
delete res;
if (json != 0 && JsonHelper::isArray(json)) {
TRI_json_t const* dotresult = JsonHelper::getArrayElement(json,"result");
TRI_json_t const* dotresult = JsonHelper::getArrayElement(json, "result");
if (dotresult != 0) {
vector<string> list = JsonHelper::stringList(dotresult);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
@ -10122,7 +9973,7 @@ static v8::Handle<v8::Value> MapGetIndexedShapedJson (uint32_t idx,
int TRI_ParseVertex (CollectionNameResolver const& resolver,
TRI_voc_cid_t& cid,
TRI_voc_key_t& key,
v8::Handle<v8::Value> const& val,
v8::Handle<v8::Value> const val,
bool translateName) {
v8::HandleScope scope;

View File

@ -60,7 +60,7 @@ namespace triagens {
int TRI_ParseVertex (triagens::arango::CollectionNameResolver const&,
TRI_voc_cid_t&,
TRI_voc_key_t&,
v8::Handle<v8::Value> const&,
v8::Handle<v8::Value> const,
bool);
////////////////////////////////////////////////////////////////////////////////

View File

@ -30,6 +30,7 @@
#include "BasicsC/conversions.h"
#include "BasicsC/files.h"
#include "BasicsC/json.h"
#include "BasicsC/json-utilities.h"
#include "BasicsC/linked-list.h"
#include "BasicsC/logging.h"
#include "BasicsC/string-buffer.h"
@ -2680,6 +2681,156 @@ void TRI_FreeBitarrayIndex (TRI_index_t* idx) {
TRI_Free(TRI_CORE_MEM_ZONE, idx);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief index comparator, used by the coordinator to detect if two index
/// contents are the same
////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_ENABLE_CLUSTER
bool IndexComparator (TRI_json_t const* lhs,
TRI_json_t const* rhs) {
TRI_json_t* typeJson = TRI_LookupArrayJson(lhs, "type");
assert(TRI_IsStringJson(typeJson));
// type must be identical
if (! TRI_CheckSameValueJson(typeJson, TRI_LookupArrayJson(rhs, "type"))) {
return false;
}
TRI_idx_type_e type = TRI_TypeIndex(typeJson->_value._string.data);
// unique must be identical if present
TRI_json_t* value = TRI_LookupArrayJson(lhs, "unique");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "unique"))) {
return false;
}
}
if (type == TRI_IDX_TYPE_GEO1_INDEX) {
// geoJson must be identical if present
value = TRI_LookupArrayJson(lhs, "geoJson");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "geoJson"))) {
return false;
}
}
value = TRI_LookupArrayJson(lhs, "ignoreNull");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "ignoreNull"))) {
return false;
}
}
}
else if (type == TRI_IDX_TYPE_GEO2_INDEX) {
value = TRI_LookupArrayJson(lhs, "ignoreNull");
if (TRI_IsBooleanJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "ignoreNull"))) {
return false;
}
}
}
else if (type == TRI_IDX_TYPE_FULLTEXT_INDEX) {
// minLength
value = TRI_LookupArrayJson(lhs, "minLength");
if (TRI_IsNumberJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "minLength"))) {
return false;
}
}
}
else if (type == TRI_IDX_TYPE_CAP_CONSTRAINT) {
// size, byteSize
value = TRI_LookupArrayJson(lhs, "size");
if (TRI_IsNumberJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "size"))) {
return false;
}
}
value = TRI_LookupArrayJson(lhs, "byteSize");
if (TRI_IsNumberJson(value)) {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "byteSize"))) {
return false;
}
}
}
if (type == TRI_IDX_TYPE_BITARRAY_INDEX) {
// bitarray indexes are considered identical if they are based on the same attributes
TRI_json_t const* r = TRI_LookupArrayJson(rhs, "fields");
value = TRI_LookupArrayJson(lhs, "fields");
if (TRI_IsListJson(value) &&
TRI_IsListJson(r) &&
value->_value._objects._length == r->_value._objects._length) {
for (size_t i = 0; i < value->_value._objects._length; ++i) {
TRI_json_t const* l1 = TRI_LookupListJson(value, i);
TRI_json_t const* r1 = TRI_LookupListJson(r, i);
if (TRI_IsListJson(l1) &&
TRI_IsListJson(r1) &&
l1->_value._objects._length == 2 &&
r1->_value._objects._length == 2) {
// element at position 0 is the attribute name
if (! TRI_CheckSameValueJson(TRI_LookupListJson(l1, 0), TRI_LookupListJson(r1, 0))) {
return false;
}
}
}
}
// we must always exit here to avoid the "regular" fields comparison
return true;
}
// other index types: fields must be identical if present
value = TRI_LookupArrayJson(lhs, "fields");
if (TRI_IsListJson(value)) {
if (type == TRI_IDX_TYPE_HASH_INDEX) {
// compare fields in arbitrary order
TRI_json_t const* r = TRI_LookupArrayJson(rhs, "fields");
if (! TRI_IsListJson(r) ||
value->_value._objects._length != r->_value._objects._length) {
return false;
}
for (size_t i = 0; i < value->_value._objects._length; ++i) {
TRI_json_t const* v = TRI_LookupListJson(value, i);
bool found = false;
for (size_t j = 0; j < r->_value._objects._length; ++j) {
if (TRI_CheckSameValueJson(v, TRI_LookupListJson(r, j))) {
found = true;
break;
}
}
if (! found) {
return false;
}
}
}
else {
if (! TRI_CheckSameValueJson(value, TRI_LookupArrayJson(rhs, "fields"))) {
return false;
}
}
}
return true;
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -600,6 +600,15 @@ void TRI_DestroyBitarrayIndex (TRI_index_t*);
void TRI_FreeBitarrayIndex (TRI_index_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief index comparator, used by the coordinator to detect if two index
/// contents are the same
////////////////////////////////////////////////////////////////////////////////
#ifdef TRI_ENABLE_CLUSTER
bool IndexComparator (TRI_json_t const* lhs, TRI_json_t const* rhs);
#endif
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -16,7 +16,7 @@
<input type="checkbox" value="useSSLonDBservers" class="useSSLonDBservers" <%=useSSLonDBservers?'checked="checked"':''%>> on DBServers
</label>
<label class="checkbox inline">
<input type="checkbox" value="useSSLonCoordinators" class="useSSLonCoordinators" <%=useSSLonCoordinators?'checked="checked"':''%>> on Coordinators
<input type="checkbox" disabled=true value="useSSLonCoordinators" class="useSSLonCoordinators" <%=useSSLonCoordinators?'checked="checked"':''%>> on Coordinators
</label>
</div>
</div>

View File

@ -251,12 +251,16 @@
"test/specs/views/dbSelectionViewSpec.js",
"test/specs/views/navigationViewSpec.js",
"test/specs/views/graphViewSpec.js",
"test/specs/views/loginViewSpec.js",
"test/specs/views/userBarViewSpec.js",
"test/specs/views/documentsViewSpec.js",
"test/specs/views/documentViewSpec.js",
"test/specs/views/dashboardViewSpec.js",
"test/specs/views/graphManagementViewSpec.js",
"test/specs/views/newLogsViewSpec.js",
"test/specs/views/notificationViewSpec.js",
"test/specs/views/statisticBarViewSpec.js",
"test/clusterSpecs/views/shutdownButtonViewSpec.js",

View File

@ -3,206 +3,206 @@
/*global spyOn, runs, expect, waitsFor, jasmine*/
/*global AddNewGraphView, _, $, arangoHelper */
(function() {
"use strict";
(function () {
"use strict";
describe("Add new Graph View", function() {
var view,
div,
graphs,
collections,
v1, v2, e1, e2, sys1, cols;
beforeEach(function() {
var createCol = function(name, type, isSystem) {
return new window.arangoCollectionModel({
id: name,
type: type,
isSystem: isSystem || false,
name: name,
status: "loaded"
});
};
v1 = createCol("z1", "document");
v2 = createCol("a2", "document");
e1 = createCol("y1", "edge");
e2 = createCol("b2", "edge");
sys1 = createCol("_sys1", "document (system)", true);
cols = [sys1, v1, v2, e1, e2];
collections = new window.arangoCollections(cols);
graphs = new window.GraphCollection();
div = document.createElement("div");
div.id = "modalPlaceholder";
document.body.appendChild(div);
view = new window.AddNewGraphView({
collection: collections,
graphs: graphs
});
});
describe("Add new Graph View", function () {
afterEach(function() {
document.body.removeChild(div);
});
var view,
div,
graphs,
collections,
v1, v2, e1, e2, sys1, cols;
it("should fetch the collections on render", function () {
spyOn(graphs, "fetch");
spyOn(collections, "fetch");
view.render();
expect(graphs.fetch).toHaveBeenCalledWith({async: false});
expect(collections.fetch).toHaveBeenCalledWith({async: false});
});
describe("after rendering", function () {
var g1, g2, g3;
beforeEach(function() {
g1 = {
_id: "_graphs/x1",
_key: "x1",
_rev: "123",
vertices: "v1",
edges: "e2"
};
g2 = {
_id: "_graphs/c2",
_key: "c2",
_rev: "321",
vertices: "v2",
edges: "e1"
};
g3 = {
_id: "_graphs/g3",
_key: "g3",
_rev: "111",
vertices: "v3",
edges: "e3"
};
spyOn(graphs, "fetch");
spyOn(collections, "fetch");
graphs.add(g1);
graphs.add(g2);
graphs.add(g3);
view.render();
});
/*
it("should offer the list of collections", function() {
});
*/
it("should be able to create a new graph", function() {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "v",
e = "e";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
spyOn(graphs, "create");
$("#createNewGraph").click();
expect(graphs.create).toHaveBeenCalledWith({
_key: name,
vertices: v,
edges: e
}, {
success: jasmine.any(Function),
error: jasmine.any(Function)
});
});
describe("if invalid information is added", function() {
beforeEach(function() {
spyOn(arangoHelper, "arangoNotification");
spyOn(graphs, "create");
});
it("should alert unnamed graph", function() {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "",
v = "v",
e = "e";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
$("#createNewGraph").click();
expect(arangoHelper.arangoNotification)
.toHaveBeenCalledWith(
"A name for the graph has to be provided."
);
expect(graphs.create).not.toHaveBeenCalled();
});
it("should alert unnamed vertices", function() {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "",
e = "e";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
$("#createNewGraph").click();
expect(arangoHelper.arangoNotification)
.toHaveBeenCalledWith(
"A vertex collection has to be provided."
);
expect(graphs.create).not.toHaveBeenCalled();
});
it("should alert unnamed edges", function() {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "v",
e = "";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
$("#createNewGraph").click();
expect(arangoHelper.arangoNotification)
.toHaveBeenCalledWith(
"An edge collection has to be provided."
);
expect(graphs.create).not.toHaveBeenCalled();
});
it("should alert arango errors", function() {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "v",
e = "e",
errMsg = "ArangoDB internal errror";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
graphs.create.andCallFake(function (info, opts) {
expect(opts.error).toBeDefined();
opts.error(info, {
responseText: JSON.stringify({
error: true,
code: 400,
errorNum: 1093,
errorMessage: errMsg
})
beforeEach(function () {
var createCol = function (name, type, isSystem) {
return new window.arangoCollectionModel({
id: name,
type: type,
isSystem: isSystem || false,
name: name,
status: "loaded"
});
};
v1 = createCol("z1", "document");
v2 = createCol("a2", "document");
e1 = createCol("y1", "edge");
e2 = createCol("b2", "edge");
sys1 = createCol("_sys1", "document (system)", true);
cols = [sys1, v1, v2, e1, e2];
collections = new window.arangoCollections(cols);
graphs = new window.GraphCollection();
div = document.createElement("div");
div.id = "modalPlaceholder";
document.body.appendChild(div);
view = new window.AddNewGraphView({
collection: collections,
graphs: graphs
});
});
afterEach(function () {
document.body.removeChild(div);
});
it("should fetch the collections on render", function () {
spyOn(graphs, "fetch");
spyOn(collections, "fetch");
view.render();
expect(graphs.fetch).toHaveBeenCalledWith({async: false});
expect(collections.fetch).toHaveBeenCalledWith({async: false});
});
describe("after rendering", function () {
var g1, g2, g3;
beforeEach(function () {
g1 = {
_id: "_graphs/x1",
_key: "x1",
_rev: "123",
vertices: "v1",
edges: "e2"
};
g2 = {
_id: "_graphs/c2",
_key: "c2",
_rev: "321",
vertices: "v2",
edges: "e1"
};
g3 = {
_id: "_graphs/g3",
_key: "g3",
_rev: "111",
vertices: "v3",
edges: "e3"
};
spyOn(graphs, "fetch");
spyOn(collections, "fetch");
graphs.add(g1);
graphs.add(g2);
graphs.add(g3);
view.render();
});
/*
it("should offer the list of collections", function() {
});
*/
it("should be able to create a new graph", function () {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "v",
e = "e";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
spyOn(graphs, "create");
$("#createNewGraph").click();
expect(graphs.create).toHaveBeenCalledWith({
_key: name,
vertices: v,
edges: e
}, {
success: jasmine.any(Function),
error: jasmine.any(Function)
});
});
describe("if invalid information is added", function () {
beforeEach(function () {
spyOn(arangoHelper, "arangoNotification");
spyOn(graphs, "create");
});
it("should alert unnamed graph", function () {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "",
v = "v",
e = "e";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
$("#createNewGraph").click();
expect(arangoHelper.arangoNotification)
.toHaveBeenCalledWith(
"A name for the graph has to be provided."
);
expect(graphs.create).not.toHaveBeenCalled();
});
it("should alert unnamed vertices", function () {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "",
e = "e";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
$("#createNewGraph").click();
expect(arangoHelper.arangoNotification)
.toHaveBeenCalledWith(
"A vertex collection has to be provided."
);
expect(graphs.create).not.toHaveBeenCalled();
});
it("should alert unnamed edges", function () {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "v",
e = "";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
$("#createNewGraph").click();
expect(arangoHelper.arangoNotification)
.toHaveBeenCalledWith(
"An edge collection has to be provided."
);
expect(graphs.create).not.toHaveBeenCalled();
});
it("should alert arango errors", function () {
var nField = "#newGraphName",
vField = "#newGraphVertices",
eField = "#newGraphEdges",
name = "g",
v = "v",
e = "e",
errMsg = "ArangoDB internal errror";
$(nField).val(name);
$(vField).val(v);
$(eField).val(e);
graphs.create.andCallFake(function (info, opts) {
expect(opts.error).toBeDefined();
opts.error(info, {
responseText: JSON.stringify({
error: true,
code: 400,
errorNum: 1093,
errorMessage: errMsg
})
});
});
spyOn(arangoHelper, "arangoError");
$("#createNewGraph").click();
expect(graphs.create).toHaveBeenCalled();
expect(arangoHelper.arangoError)
.toHaveBeenCalledWith(errMsg);
});
});
});
spyOn(arangoHelper, "arangoError");
$("#createNewGraph").click();
expect(graphs.create).toHaveBeenCalled();
expect(arangoHelper.arangoError)
.toHaveBeenCalledWith(errMsg);
});
});
});
});
}());

View File

@ -2,104 +2,104 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect, jasmine*/
/*global window, document, hljs, $*/
(function() {
"use strict";
(function () {
"use strict";
describe("The API view", function() {
var div;
describe("The API view", function () {
var div;
beforeEach(function() {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
});
afterEach(function() {
document.body.removeChild(div);
});
it("should define the swagger UI on create", function() {
spyOn(window, "SwaggerUi");
var view = new window.ApiView();
expect(window.SwaggerUi).toHaveBeenCalledWith({
discoveryUrl: "api-docs.json",
apiKey: false,
dom_id:"swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'],
onComplete: jasmine.any(Function),
onFailure: jasmine.any(Function),
docExpansion: "none"
});
});
describe("after initialize", function() {
var view, swaggerDummy;
beforeEach(function() {
swaggerDummy = {
load: function() {
throw "should always be spied upon";
}
};
spyOn(window, "SwaggerUi").andCallFake(function(opts) {
swaggerDummy.onComplete = opts.onComplete;
swaggerDummy.onFailure = opts.onFailure;
return swaggerDummy;
beforeEach(function () {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
});
view = new window.ApiView();
});
it("swagger onComplete should highlight blocks", function() {
spyOn(hljs, "highlightBlock");
var pre = document.createElement("pre"),
code = document.createElement("code");
document.body.appendChild(pre);
pre.appendChild(code);
swaggerDummy.onComplete();
expect(hljs.highlightBlock).toHaveBeenCalledWith($(code)[0]);
expect(hljs.highlightBlock.callCount).toEqual(1);
document.body.removeChild(pre);
});
it("should create appropriate onFailure info", function() {
var dummyDiv = document.createElement("div"),
dummyStrong = document.createElement("strong"),
dummyBr = document.createElement("br"),
dummyText = document.createTextNode("dummy"),
fakeData = {fake: "data"};
spyOn(document, "createElement").andCallFake(function(name) {
switch (name) {
case "div":
return dummyDiv;
case "strong":
return dummyStrong;
case "br":
return dummyBr;
default:
throw "creating unwanted element";
}
afterEach(function () {
document.body.removeChild(div);
});
it("should define the swagger UI on create", function () {
spyOn(window, "SwaggerUi");
var view = new window.ApiView();
expect(window.SwaggerUi).toHaveBeenCalledWith({
discoveryUrl: "api-docs.json",
apiKey: false,
dom_id: "swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'],
onComplete: jasmine.any(Function),
onFailure: jasmine.any(Function),
docExpansion: "none"
});
});
describe("after initialize", function () {
var view, swaggerDummy;
beforeEach(function () {
swaggerDummy = {
load: function () {
throw "should always be spied upon";
}
};
spyOn(window, "SwaggerUi").andCallFake(function (opts) {
swaggerDummy.onComplete = opts.onComplete;
swaggerDummy.onFailure = opts.onFailure;
return swaggerDummy;
});
view = new window.ApiView();
});
it("swagger onComplete should highlight blocks", function () {
spyOn(hljs, "highlightBlock");
var pre = document.createElement("pre"),
code = document.createElement("code");
document.body.appendChild(pre);
pre.appendChild(code);
swaggerDummy.onComplete();
expect(hljs.highlightBlock).toHaveBeenCalledWith($(code)[0]);
expect(hljs.highlightBlock.callCount).toEqual(1);
document.body.removeChild(pre);
});
it("should create appropriate onFailure info", function () {
var dummyDiv = document.createElement("div"),
dummyStrong = document.createElement("strong"),
dummyBr = document.createElement("br"),
dummyText = document.createTextNode("dummy"),
fakeData = {fake: "data"};
spyOn(document, "createElement").andCallFake(function (name) {
switch (name) {
case "div":
return dummyDiv;
case "strong":
return dummyStrong;
case "br":
return dummyBr;
default:
throw "creating unwanted element";
}
});
spyOn(document, "createTextNode").andReturn(dummyText);
spyOn(dummyDiv, "appendChild");
spyOn(dummyStrong, "appendChild");
swaggerDummy.onFailure(fakeData);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyStrong);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyBr);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyText);
expect(dummyStrong.appendChild).toHaveBeenCalledWith(dummyText);
expect(document.createTextNode)
.toHaveBeenCalledWith("Sorry the code is not documented properly");
expect(document.createTextNode).toHaveBeenCalledWith(JSON.stringify(fakeData));
});
it("should load the SwaggerUI on render", function () {
spyOn(swaggerDummy, "load");
view.render();
expect(swaggerDummy.load).toHaveBeenCalled();
});
});
spyOn(document, "createTextNode").andReturn(dummyText);
spyOn(dummyDiv, "appendChild");
spyOn(dummyStrong, "appendChild");
swaggerDummy.onFailure(fakeData);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyStrong);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyBr);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyText);
expect(dummyStrong.appendChild).toHaveBeenCalledWith(dummyText);
expect(document.createTextNode)
.toHaveBeenCalledWith("Sorry the code is not documented properly");
expect(document.createTextNode).toHaveBeenCalledWith(JSON.stringify(fakeData));
});
it("should load the SwaggerUI on render", function() {
spyOn(swaggerDummy, "load");
view.render();
expect(swaggerDummy.load).toHaveBeenCalled();
});
});
});
}());

View File

@ -2,114 +2,114 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect, jasmine*/
/*global window, document, hljs, $, require*/
(function() {
"use strict";
(function () {
"use strict";
describe("The App documentation view", function() {
var div;
describe("The App documentation view", function () {
var div;
beforeEach(function() {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
});
afterEach(function() {
document.body.removeChild(div);
});
it("should define the swagger UI on create", function() {
var fakeURL = "/fake/url",
fakeKey = "fakeKey",
view,
internal = require("internal");
spyOn(internal.arango, "databasePrefix").andReturn(fakeURL);
spyOn(window, "SwaggerUi");
view = new window.AppDocumentationView({
key: fakeKey
});
expect(internal.arango.databasePrefix).toHaveBeenCalledWith(
"/_admin/aardvark/docu/" + fakeKey
);
expect(window.SwaggerUi).toHaveBeenCalledWith({
discoveryUrl: fakeURL,
apiKey: false,
dom_id:"swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'],
onComplete: jasmine.any(Function),
onFailure: jasmine.any(Function),
docExpansion: "none"
});
});
describe("after initialize", function() {
var view, swaggerDummy;
beforeEach(function() {
swaggerDummy = {
load: function() {
throw "should always be spied upon";
}
};
spyOn(window, "SwaggerUi").andCallFake(function(opts) {
swaggerDummy.onComplete = opts.onComplete;
swaggerDummy.onFailure = opts.onFailure;
return swaggerDummy;
beforeEach(function () {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
});
view = new window.AppDocumentationView();
});
it("swagger onComplete should highlight blocks", function() {
spyOn(hljs, "highlightBlock");
var pre = document.createElement("pre"),
code = document.createElement("code");
document.body.appendChild(pre);
pre.appendChild(code);
swaggerDummy.onComplete();
expect(hljs.highlightBlock).toHaveBeenCalledWith($(code)[0]);
expect(hljs.highlightBlock.callCount).toEqual(1);
document.body.removeChild(pre);
});
it("should create appropriate onFailure info", function() {
var dummyDiv = document.createElement("div"),
dummyStrong = document.createElement("strong"),
dummyBr = document.createElement("br"),
dummyText = document.createTextNode("dummy"),
fakeData = {fake: "data"};
spyOn(document, "createElement").andCallFake(function(name) {
switch (name) {
case "div":
return dummyDiv;
case "strong":
return dummyStrong;
case "br":
return dummyBr;
default:
throw "creating unwanted element";
}
afterEach(function () {
document.body.removeChild(div);
});
it("should define the swagger UI on create", function () {
var fakeURL = "/fake/url",
fakeKey = "fakeKey",
view,
internal = require("internal");
spyOn(internal.arango, "databasePrefix").andReturn(fakeURL);
spyOn(window, "SwaggerUi");
view = new window.AppDocumentationView({
key: fakeKey
});
expect(internal.arango.databasePrefix).toHaveBeenCalledWith(
"/_admin/aardvark/docu/" + fakeKey
);
expect(window.SwaggerUi).toHaveBeenCalledWith({
discoveryUrl: fakeURL,
apiKey: false,
dom_id: "swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch', 'head'],
onComplete: jasmine.any(Function),
onFailure: jasmine.any(Function),
docExpansion: "none"
});
});
describe("after initialize", function () {
var view, swaggerDummy;
beforeEach(function () {
swaggerDummy = {
load: function () {
throw "should always be spied upon";
}
};
spyOn(window, "SwaggerUi").andCallFake(function (opts) {
swaggerDummy.onComplete = opts.onComplete;
swaggerDummy.onFailure = opts.onFailure;
return swaggerDummy;
});
view = new window.AppDocumentationView();
});
it("swagger onComplete should highlight blocks", function () {
spyOn(hljs, "highlightBlock");
var pre = document.createElement("pre"),
code = document.createElement("code");
document.body.appendChild(pre);
pre.appendChild(code);
swaggerDummy.onComplete();
expect(hljs.highlightBlock).toHaveBeenCalledWith($(code)[0]);
expect(hljs.highlightBlock.callCount).toEqual(1);
document.body.removeChild(pre);
});
it("should create appropriate onFailure info", function () {
var dummyDiv = document.createElement("div"),
dummyStrong = document.createElement("strong"),
dummyBr = document.createElement("br"),
dummyText = document.createTextNode("dummy"),
fakeData = {fake: "data"};
spyOn(document, "createElement").andCallFake(function (name) {
switch (name) {
case "div":
return dummyDiv;
case "strong":
return dummyStrong;
case "br":
return dummyBr;
default:
throw "creating unwanted element";
}
});
spyOn(document, "createTextNode").andReturn(dummyText);
spyOn(dummyDiv, "appendChild");
spyOn(dummyStrong, "appendChild");
swaggerDummy.onFailure(fakeData);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyStrong);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyBr);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyText);
expect(dummyStrong.appendChild).toHaveBeenCalledWith(dummyText);
expect(document.createTextNode)
.toHaveBeenCalledWith("Sorry the code is not documented properly");
expect(document.createTextNode).toHaveBeenCalledWith(JSON.stringify(fakeData));
});
it("should load the SwaggerUI on render", function () {
spyOn(swaggerDummy, "load");
view.render();
expect(swaggerDummy.load).toHaveBeenCalled();
});
});
spyOn(document, "createTextNode").andReturn(dummyText);
spyOn(dummyDiv, "appendChild");
spyOn(dummyStrong, "appendChild");
swaggerDummy.onFailure(fakeData);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyStrong);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyBr);
expect(dummyDiv.appendChild).toHaveBeenCalledWith(dummyText);
expect(dummyStrong.appendChild).toHaveBeenCalledWith(dummyText);
expect(document.createTextNode)
.toHaveBeenCalledWith("Sorry the code is not documented properly");
expect(document.createTextNode).toHaveBeenCalledWith(JSON.stringify(fakeData));
});
it("should load the SwaggerUI on render", function() {
spyOn(swaggerDummy, "load");
view.render();
expect(swaggerDummy.load).toHaveBeenCalled();
});
});
});
}());

View File

@ -2,143 +2,145 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine, $, uiMatchers*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Collection View", function() {
var view, div, shardsView, shardCol, server, db;
describe("Cluster Collection View", function () {
var view, div, shardsView, shardCol, server, db;
beforeEach(function() {
server = "pavel";
db = "_system";
div = document.createElement("div");
div.id = "clusterCollections";
document.body.appendChild(div);
shardsView = {
render: function() {},
unrender: function() {}
};
shardCol = {
__refId: "testId"
};
spyOn(window, "ClusterShardsView").andReturn(shardsView);
spyOn(window, "ClusterShards").andReturn(shardCol);
uiMatchers.define(this);
});
afterEach(function() {
document.body.removeChild(div);
});
describe("initialisation", function() {
it("should create a Cluster Server View", function() {
view = new window.ClusterCollectionView();
expect(window.ClusterShards).toHaveBeenCalled();
expect(window.ClusterShardsView).toHaveBeenCalledWith({
collection: shardCol
beforeEach(function () {
server = "pavel";
db = "_system";
div = document.createElement("div");
div.id = "clusterCollections";
document.body.appendChild(div);
shardsView = {
render: function () {
},
unrender: function () {
}
};
shardCol = {
__refId: "testId"
};
spyOn(window, "ClusterShardsView").andReturn(shardsView);
spyOn(window, "ClusterShards").andReturn(shardCol);
uiMatchers.define(this);
});
});
afterEach(function () {
document.body.removeChild(div);
});
describe("initialisation", function () {
it("should create a Cluster Server View", function () {
view = new window.ClusterCollectionView();
expect(window.ClusterShards).toHaveBeenCalled();
expect(window.ClusterShardsView).toHaveBeenCalledWith({
collection: shardCol
});
});
});
describe("rendering", function () {
var docs, edges, people, colls, collCol,
checkButtonContent = function (col, cls) {
var btn = document.getElementById(col.name);
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("btn-server");
expect(btn).toBeOfClass("collection");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(col.name);
};
beforeEach(function () {
docs = {
name: "Documents",
status: "ok"
};
edges = {
name: "Edges",
status: "warning"
};
people = {
name: "People",
status: "critical"
};
colls = [
docs,
edges,
people
];
collCol = {
getList: function () {
return colls;
}
};
spyOn(shardsView, "render");
spyOn(shardsView, "unrender");
view = new window.ClusterCollectionView({
collection: collCol
});
view.render(db, server);
});
it("should not unrender the server view", function () {
expect(shardsView.render).not.toHaveBeenCalled();
expect(shardsView.unrender).toHaveBeenCalled();
});
it("should render the documents collection", function () {
checkButtonContent(docs, "success");
});
it("should render the edge collection", function () {
checkButtonContent(edges, "warning");
});
it("should render the people collection", function () {
checkButtonContent(people, "danger");
});
it("should offer an unrender function", function () {
shardsView.unrender.reset();
view.unrender();
expect($(div).html()).toEqual("");
expect(shardsView.unrender).toHaveBeenCalled();
});
describe("user actions", function () {
var info;
beforeEach(function () {
view = new window.ClusterCollectionView();
});
it("should be able to navigate to Documents", function () {
$("#Documents").click();
expect(shardsView.render).toHaveBeenCalledWith(db, "Documents", server);
});
it("should be able to navigate to Edges", function () {
$("#Edges").click();
expect(shardsView.render).toHaveBeenCalledWith(db, "Edges", server);
});
it("should be able to navigate to People", function () {
$("#People").click();
expect(shardsView.render).toHaveBeenCalledWith(db, "People", server);
});
});
});
});
describe("rendering", function() {
var docs, edges, people, colls, collCol,
checkButtonContent = function(col, cls) {
var btn = document.getElementById(col.name);
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("btn-server");
expect(btn).toBeOfClass("collection");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(col.name);
};
beforeEach(function() {
docs = {
name: "Documents",
status: "ok"
};
edges = {
name: "Edges",
status: "warning"
};
people = {
name: "People",
status: "critical"
};
colls = [
docs,
edges,
people
];
collCol = {
getList: function() {
return colls;
}
};
spyOn(shardsView, "render");
spyOn(shardsView, "unrender");
view = new window.ClusterCollectionView({
collection: collCol
});
view.render(db, server);
});
it("should not unrender the server view", function() {
expect(shardsView.render).not.toHaveBeenCalled();
expect(shardsView.unrender).toHaveBeenCalled();
});
it("should render the documents collection", function() {
checkButtonContent(docs, "success");
});
it("should render the edge collection", function() {
checkButtonContent(edges, "warning");
});
it("should render the people collection", function() {
checkButtonContent(people, "danger");
});
it("should offer an unrender function", function() {
shardsView.unrender.reset();
view.unrender();
expect($(div).html()).toEqual("");
expect(shardsView.unrender).toHaveBeenCalled();
});
describe("user actions", function() {
var info;
beforeEach(function() {
view = new window.ClusterCollectionView();
});
it("should be able to navigate to Documents", function() {
$("#Documents").click();
expect(shardsView.render).toHaveBeenCalledWith(db, "Documents", server);
});
it("should be able to navigate to Edges", function() {
$("#Edges").click();
expect(shardsView.render).toHaveBeenCalledWith(db, "Edges", server);
});
it("should be able to navigate to People", function() {
$("#People").click();
expect(shardsView.render).toHaveBeenCalledWith(db, "People", server);
});
});
});
});
}());

View File

@ -2,97 +2,97 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine, $, uiMatchers*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Coordinator View", function() {
var view, div;
describe("Cluster Coordinator View", function () {
var view, div;
beforeEach(function() {
div = document.createElement("div");
div.id = "clusterServers";
document.body.appendChild(div);
uiMatchers.define(this);
});
afterEach(function() {
document.body.removeChild(div);
});
describe("rendering", function() {
var charly, carlos, chantalle, coordinators,
coordCol,
getTile = function(name) {
return document.getElementById(name);
},
checkTile = function(c, cls) {
var tile = getTile(c.name),
inner = tile.children[0];
expect(tile).toBeOfClass("coordinator");
expect(tile).toBeOfClass("domino");
expect(inner).toBeOfClass("btn-" + cls);
expect(inner).toBeOfClass("domino-inner");
expect(inner.children[0]).toBeOfClass("domino-header");
expect($(inner.children[0]).text()).toEqual(c.name);
expect($(inner.children[1]).text()).toEqual(c.url);
};
beforeEach(function() {
charly = {
name: "Charly",
url: "tcp://192.168.0.1:1337",
status: "ok"
};
carlos = {
name: "Carlos",
url: "tcp://192.168.0.2:1337",
status: "critical"
};
chantalle = {
name: "Chantalle",
url: "tcp://192.168.0.5:1337",
status: "ok"
};
coordinators = [
charly,
carlos,
chantalle
];
coordCol = {
getList: function() {
return coordinators;
}
};
view = new window.ClusterCoordinatorView({
collection: coordCol
beforeEach(function () {
div = document.createElement("div");
div.id = "clusterServers";
document.body.appendChild(div);
uiMatchers.define(this);
});
view.render();
});
it("should render all coordiniators", function() {
expect($("> div.coordinator", $(div)).length).toEqual(3);
});
afterEach(function () {
document.body.removeChild(div);
});
it("should render charly", function() {
checkTile(charly, "success");
});
describe("rendering", function () {
it("should render carlos", function() {
checkTile(carlos, "danger");
});
var charly, carlos, chantalle, coordinators,
coordCol,
getTile = function (name) {
return document.getElementById(name);
},
checkTile = function (c, cls) {
var tile = getTile(c.name),
inner = tile.children[0];
expect(tile).toBeOfClass("coordinator");
expect(tile).toBeOfClass("domino");
expect(inner).toBeOfClass("btn-" + cls);
expect(inner).toBeOfClass("domino-inner");
expect(inner.children[0]).toBeOfClass("domino-header");
expect($(inner.children[0]).text()).toEqual(c.name);
expect($(inner.children[1]).text()).toEqual(c.url);
};
it("should render chantalle", function() {
checkTile(chantalle, "success");
});
beforeEach(function () {
charly = {
name: "Charly",
url: "tcp://192.168.0.1:1337",
status: "ok"
};
carlos = {
name: "Carlos",
url: "tcp://192.168.0.2:1337",
status: "critical"
};
chantalle = {
name: "Chantalle",
url: "tcp://192.168.0.5:1337",
status: "ok"
};
coordinators = [
charly,
carlos,
chantalle
];
coordCol = {
getList: function () {
return coordinators;
}
};
view = new window.ClusterCoordinatorView({
collection: coordCol
});
view.render();
});
it("should allow an unrender function", function() {
view.unrender();
expect($(div).html()).toEqual("");
});
it("should render all coordiniators", function () {
expect($("> div.coordinator", $(div)).length).toEqual(3);
});
it("should render charly", function () {
checkTile(charly, "success");
});
it("should render carlos", function () {
checkTile(carlos, "danger");
});
it("should render chantalle", function () {
checkTile(chantalle, "success");
});
it("should allow an unrender function", function () {
view.unrender();
expect($(div).html()).toEqual("");
});
});
});
});
}());

View File

@ -2,83 +2,84 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Dashboard View", function() {
var view, div, overview;
describe("Cluster Dashboard View", function () {
var view, div, overview;
beforeEach(function() {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
overview = {
render: function(){}
};
spyOn(window, "ClusterOverviewView").andReturn(overview);
});
afterEach(function() {
document.body.removeChild(div);
});
describe("initialisation", function() {
var servCol, coorCol;
beforeEach(function() {
servCol = {
__id: "servId"
};
coorCol = {
__id: "coorId"
};
spyOn(overview, "render");
spyOn(window, "ClusterServers").andReturn(servCol);
spyOn(window, "ClusterCoordinators").andReturn(coorCol);
view = new window.ClusterDashboardView();
});
it("should create the cluster server collection", function() {
expect(window.ClusterServers).toHaveBeenCalled();
});
it("should create the cluster coordinators collection", function() {
expect(window.ClusterCoordinators).toHaveBeenCalled();
});
describe("rendering", function() {
var info;
beforeEach(function() {
window.ClusterServers.reset();
window.ClusterCoordinators.reset();
beforeEach(function () {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
overview = {
render: function () {
}
};
spyOn(window, "ClusterOverviewView").andReturn(overview);
});
it("should create a Cluster Overview View", function() {
expect(window.ClusterOverviewView).not.toHaveBeenCalled();
expect(window.ClusterServers).not.toHaveBeenCalled();
expect(window.ClusterCoordinators).not.toHaveBeenCalled();
window.ClusterOverviewView.reset();
view.render();
expect(window.ClusterOverviewView).toHaveBeenCalled();
expect(window.ClusterServers).not.toHaveBeenCalled();
expect(window.ClusterCoordinators).not.toHaveBeenCalled();
window.ClusterOverviewView.reset();
view.render();
expect(window.ClusterOverviewView).toHaveBeenCalled();
expect(window.ClusterServers).not.toHaveBeenCalled();
expect(window.ClusterCoordinators).not.toHaveBeenCalled();
afterEach(function () {
document.body.removeChild(div);
});
it("should render the Cluster Overview", function() {
view.render();
expect(overview.render).toHaveBeenCalled();
describe("initialisation", function () {
var servCol, coorCol;
beforeEach(function () {
servCol = {
__id: "servId"
};
coorCol = {
__id: "coorId"
};
spyOn(overview, "render");
spyOn(window, "ClusterServers").andReturn(servCol);
spyOn(window, "ClusterCoordinators").andReturn(coorCol);
view = new window.ClusterDashboardView();
});
it("should create the cluster server collection", function () {
expect(window.ClusterServers).toHaveBeenCalled();
});
it("should create the cluster coordinators collection", function () {
expect(window.ClusterCoordinators).toHaveBeenCalled();
});
describe("rendering", function () {
var info;
beforeEach(function () {
window.ClusterServers.reset();
window.ClusterCoordinators.reset();
});
it("should create a Cluster Overview View", function () {
expect(window.ClusterOverviewView).not.toHaveBeenCalled();
expect(window.ClusterServers).not.toHaveBeenCalled();
expect(window.ClusterCoordinators).not.toHaveBeenCalled();
window.ClusterOverviewView.reset();
view.render();
expect(window.ClusterOverviewView).toHaveBeenCalled();
expect(window.ClusterServers).not.toHaveBeenCalled();
expect(window.ClusterCoordinators).not.toHaveBeenCalled();
window.ClusterOverviewView.reset();
view.render();
expect(window.ClusterOverviewView).toHaveBeenCalled();
expect(window.ClusterServers).not.toHaveBeenCalled();
expect(window.ClusterCoordinators).not.toHaveBeenCalled();
});
it("should render the Cluster Overview", function () {
view.render();
expect(overview.render).toHaveBeenCalled();
});
});
});
});
});
});
}());

View File

@ -2,140 +2,142 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine, $, uiMatchers*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Database View", function() {
var view, div, colView, colCol, server;
describe("Cluster Database View", function () {
var view, div, colView, colCol, server;
beforeEach(function() {
server = "pavel";
div = document.createElement("div");
div.id = "clusterDatabases";
document.body.appendChild(div);
colView = {
render: function() {},
unrender: function() {}
};
colCol = {
__id: "refId"
};
spyOn(window, "ClusterCollectionView").andReturn(colView);
spyOn(window, "ClusterCollections").andReturn(colCol);
uiMatchers.define(this);
beforeEach(function () {
server = "pavel";
div = document.createElement("div");
div.id = "clusterDatabases";
document.body.appendChild(div);
colView = {
render: function () {
},
unrender: function () {
}
};
colCol = {
__id: "refId"
};
spyOn(window, "ClusterCollectionView").andReturn(colView);
spyOn(window, "ClusterCollections").andReturn(colCol);
uiMatchers.define(this);
});
afterEach(function () {
document.body.removeChild(div);
});
describe("initialisation", function () {
it("should create a Cluster Collection View", function () {
view = new window.ClusterDatabaseView({
collection: {}
});
expect(window.ClusterCollections).toHaveBeenCalled();
expect(window.ClusterCollectionView).toHaveBeenCalledWith({
collection: colCol
});
});
});
describe("rendering", function () {
var db1, db2, db3, databases, dbCol,
checkButtonContent = function (db, cls) {
var btn = document.getElementById(db.name);
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("btn-server");
expect(btn).toBeOfClass("database");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(db.name);
};
beforeEach(function () {
spyOn(colView, "render");
spyOn(colView, "unrender");
db1 = {
name: "_system",
status: "ok"
};
db2 = {
name: "myDatabase",
status: "warning"
};
db3 = {
name: "otherDatabase",
status: "critical"
};
databases = [
db1,
db2,
db3
];
dbCol = {
getList: function () {
return databases;
}
};
view = new window.ClusterDatabaseView({
collection: dbCol
});
view.render(server);
});
it("should not render the Server view", function () {
expect(colView.render).not.toHaveBeenCalled();
expect(colView.unrender).toHaveBeenCalled();
});
it("should render the ok database", function () {
checkButtonContent(db1, "success");
});
it("should render the warning database", function () {
checkButtonContent(db2, "warning");
});
it("should render the error database", function () {
checkButtonContent(db3, "danger");
});
it("should offer an unrender function", function () {
colView.unrender.reset();
view.unrender();
expect($(div).html()).toEqual("");
expect(colView.unrender).toHaveBeenCalled();
});
describe("user actions", function () {
var db;
it("should be able to navigate to _system", function () {
db = "_system";
$("#" + db).click();
expect(colView.render).toHaveBeenCalledWith(db, server);
});
it("should be able to navigate to myDatabase", function () {
db = "myDatabase";
$("#" + db).click();
expect(colView.render).toHaveBeenCalledWith(db, server);
});
it("should be able to navigate to otherDatabase", function () {
db = "otherDatabase";
$("#" + db).click();
expect(colView.render).toHaveBeenCalledWith(db, server);
});
});
});
});
afterEach(function() {
document.body.removeChild(div);
});
describe("initialisation", function() {
it("should create a Cluster Collection View", function() {
view = new window.ClusterDatabaseView({
collection: {}
});
expect(window.ClusterCollections).toHaveBeenCalled();
expect(window.ClusterCollectionView).toHaveBeenCalledWith({
collection: colCol
});
});
});
describe("rendering", function() {
var db1, db2, db3, databases, dbCol,
checkButtonContent = function(db, cls) {
var btn = document.getElementById(db.name);
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("btn-server");
expect(btn).toBeOfClass("database");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(db.name);
};
beforeEach(function() {
spyOn(colView, "render");
spyOn(colView, "unrender");
db1 = {
name: "_system",
status: "ok"
};
db2 = {
name: "myDatabase",
status: "warning"
};
db3 = {
name: "otherDatabase",
status: "critical"
};
databases = [
db1,
db2,
db3
];
dbCol = {
getList: function() {
return databases;
}
};
view = new window.ClusterDatabaseView({
collection: dbCol
});
view.render(server);
});
it("should not render the Server view", function() {
expect(colView.render).not.toHaveBeenCalled();
expect(colView.unrender).toHaveBeenCalled();
});
it("should render the ok database", function() {
checkButtonContent(db1, "success");
});
it("should render the warning database", function() {
checkButtonContent(db2, "warning");
});
it("should render the error database", function() {
checkButtonContent(db3, "danger");
});
it("should offer an unrender function", function() {
colView.unrender.reset();
view.unrender();
expect($(div).html()).toEqual("");
expect(colView.unrender).toHaveBeenCalled();
});
describe("user actions", function() {
var db;
it("should be able to navigate to _system", function() {
db = "_system";
$("#" + db).click();
expect(colView.render).toHaveBeenCalledWith(db, server);
});
it("should be able to navigate to myDatabase", function() {
db = "myDatabase";
$("#" + db).click();
expect(colView.render).toHaveBeenCalledWith(db, server);
});
it("should be able to navigate to otherDatabase", function() {
db = "otherDatabase";
$("#" + db).click();
expect(colView.render).toHaveBeenCalledWith(db, server);
});
});
});
});
}());

View File

@ -2,372 +2,376 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine, $, _, uiMatchers*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Overview View", function() {
var view, div, serverView, coordinatorView,
clusterServers, serverStatus,
serverHaving, serverPlan,
clusterCoordinators, coordinatorStatus,
coordinatorHaving, coordinatorPlan;
describe("Cluster Overview View", function () {
var view, div, serverView, coordinatorView,
clusterServers, serverStatus,
serverHaving, serverPlan,
clusterCoordinators, coordinatorStatus,
coordinatorHaving, coordinatorPlan;
beforeEach(function() {
div = document.createElement("div");
div.id = "clusterOverview";
document.body.appendChild(div);
serverView = {
render: function() {},
unrender: function() {}
};
coordinatorView = {
render: function() {},
unrender: function() {}
};
serverStatus = "warning";
serverHaving = 3;
serverPlan = 3;
clusterServers = {
getOverview: function() {
return {
plan: serverPlan,
having: serverHaving,
status: serverStatus
};
}
};
coordinatorStatus = "critical";
coordinatorHaving = 2;
coordinatorPlan = 3;
clusterCoordinators = {
getOverview: function() {
return {
plan: coordinatorPlan,
having: coordinatorHaving,
status: coordinatorStatus
};
}
};
spyOn(window, "ClusterServerView").andReturn(serverView);
spyOn(window, "ClusterCoordinatorView").andReturn(coordinatorView);
uiMatchers.define(this);
});
afterEach(function() {
document.body.removeChild(div);
});
describe("initialisation", function() {
it("should create a Cluster Server View", function() {
view = new window.ClusterOverviewView({
dbservers: clusterServers,
coordinators: clusterCoordinators
beforeEach(function () {
div = document.createElement("div");
div.id = "clusterOverview";
document.body.appendChild(div);
serverView = {
render: function () {
},
unrender: function () {
}
};
coordinatorView = {
render: function () {
},
unrender: function () {
}
};
serverStatus = "warning";
serverHaving = 3;
serverPlan = 3;
clusterServers = {
getOverview: function () {
return {
plan: serverPlan,
having: serverHaving,
status: serverStatus
};
}
};
coordinatorStatus = "critical";
coordinatorHaving = 2;
coordinatorPlan = 3;
clusterCoordinators = {
getOverview: function () {
return {
plan: coordinatorPlan,
having: coordinatorHaving,
status: coordinatorStatus
};
}
};
spyOn(window, "ClusterServerView").andReturn(serverView);
spyOn(window, "ClusterCoordinatorView").andReturn(coordinatorView);
uiMatchers.define(this);
});
expect(window.ClusterServerView).toHaveBeenCalledWith({
collection: clusterServers
});
});
it("should create a Cluster Coordinator View", function() {
view = new window.ClusterOverviewView({
dbservers: clusterServers,
coordinators: clusterCoordinators
afterEach(function () {
document.body.removeChild(div);
});
expect(window.ClusterCoordinatorView).toHaveBeenCalledWith({
collection: clusterCoordinators
describe("initialisation", function () {
it("should create a Cluster Server View", function () {
view = new window.ClusterOverviewView({
dbservers: clusterServers,
coordinators: clusterCoordinators
});
expect(window.ClusterServerView).toHaveBeenCalledWith({
collection: clusterServers
});
});
it("should create a Cluster Coordinator View", function () {
view = new window.ClusterOverviewView({
dbservers: clusterServers,
coordinators: clusterCoordinators
});
expect(window.ClusterCoordinatorView).toHaveBeenCalledWith({
collection: clusterCoordinators
});
});
});
describe("rendering", function () {
var checkUserActions = function () {
describe("user actions", function () {
var info;
beforeEach(function () {
serverView.render.reset();
coordinatorView.render.reset();
view.render();
spyOn(view, "render");
});
it("should be able to navigate to db servers", function () {
$("#dbserver").click();
expect(serverView.render).toHaveBeenCalledWith();
expect(coordinatorView.unrender).toHaveBeenCalled();
expect(view.render).toHaveBeenCalledWith(true);
});
it("should be able to navigate to coordinators", function () {
$("#coordinator").click();
expect(coordinatorView.render).toHaveBeenCalledWith();
expect(serverView.unrender).toHaveBeenCalled();
expect(view.render).toHaveBeenCalledWith(true);
});
});
},
checkShowStatus = function (btn, status) {
var classNames = {
ok: "btn-success",
warning: "btn-warning",
critical: "btn-danger"
};
expect(btn).toBeOfClass(classNames[status]);
delete classNames[status];
_.each(classNames, function (v) {
expect(btn).toNotHaveClass(v);
});
};
beforeEach(function () {
spyOn(serverView, "render");
spyOn(serverView, "unrender");
spyOn(coordinatorView, "render");
spyOn(coordinatorView, "unrender");
view = new window.ClusterOverviewView({
dbservers: clusterServers,
coordinators: clusterCoordinators
});
});
describe("minified version", function () {
beforeEach(function () {
view.render(true);
});
it("should not render the Server view", function () {
expect(serverView.render).not.toHaveBeenCalled();
});
it("should not render the Coordinator view", function () {
expect(coordinatorView.render).not.toHaveBeenCalled();
});
it("should render in minified version", function () {
expect($(div).hasClass("clusterColumnMax")).toBeFalsy();
});
describe("dbservers", function () {
var getButton = function () {
return document.getElementById("dbserver");
};
it("should render the amounts", function () {
serverPlan = 5;
serverHaving = 4;
view.render(true);
var btn = getButton(),
span = btn.firstChild,
txt = $(span).text();
expect(btn).toBeDefined();
expect(span).toBeDefined();
expect(span).toBeOfClass("arangoicon");
expect(span).toBeOfClass("icon_arangodb_database1");
expect(span).toBeOfClass("cluster_icon_small");
expect(txt.trim()).toEqual("4/5");
});
it("should render the status ok", function () {
var status = "ok";
serverStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status warning", function () {
var status = "warning";
serverStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status critical", function () {
var status = "critical";
serverStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
});
describe("coordinators", function () {
var getButton = function () {
return document.getElementById("coordinator");
};
it("should render the amounts", function () {
coordinatorPlan = 5;
coordinatorHaving = 4;
view.render(true);
var btn = getButton(),
span = btn.firstChild,
txt = $(span).text();
expect(btn).toBeDefined();
expect(span).toBeDefined();
expect(span).toBeOfClass("arangoicon");
expect(span).toBeOfClass("icon_arangodb_compass");
expect(span).toBeOfClass("cluster_icon_small");
expect(txt.trim()).toEqual("4/5");
});
it("should render the status ok", function () {
var status = "ok";
coordinatorStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status warning", function () {
var status = "warning";
coordinatorStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status critical", function () {
var status = "critical";
coordinatorStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
});
checkUserActions();
});
describe("maximised version", function () {
beforeEach(function () {
view.render();
});
it("should not render the Server view", function () {
expect(serverView.render).not.toHaveBeenCalled();
});
it("should increase the size of the column to maximum", function () {
expect($(div).hasClass("clusterColumnMax")).toBeTruthy();
});
describe("dbservers", function () {
var getTile = function () {
return document.getElementById("dbserver");
};
it("should render the tile", function () {
serverPlan = 5;
serverHaving = 4;
view.render();
var tile = getTile(),
headers = $("> h4", $(tile)),
header = headers[0],
footer = headers[1],
icon = $("> div > span", $(tile))[0],
htxt = $(header).text(),
ftxt = $(footer).text();
expect(tile).toBeDefined();
expect(tile).toBeOfClass("tile");
expect(tile).toBeOfClass("tile-left");
expect(icon).toBeDefined();
expect(icon).toBeOfClass("arangoicon");
expect(icon).toBeOfClass("icon_arangodb_database1");
expect(icon).toBeOfClass("cluster_icon_large");
expect(htxt.trim()).toEqual("Data Servers");
expect(ftxt.trim()).toEqual("4/5");
});
it("should render the status ok", function () {
var status = "ok";
serverStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status warning", function () {
var status = "warning";
serverStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status critical", function () {
var status = "critical";
serverStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
});
describe("coordinators", function () {
var getTile = function () {
return document.getElementById("coordinator");
};
it("should render the tile", function () {
coordinatorPlan = 5;
coordinatorHaving = 4;
view.render();
var tile = getTile(),
headers = $("> h4", $(tile)),
header = headers[0],
footer = headers[1],
icon = $("> div > span", $(tile))[0],
htxt = $(header).text(),
ftxt = $(footer).text();
expect(tile).toBeDefined();
expect(tile).toBeOfClass("tile");
expect(tile).toBeOfClass("tile-right");
expect(icon).toBeDefined();
expect(icon).toBeOfClass("arangoicon");
expect(icon).toBeOfClass("icon_arangodb_compass");
expect(icon).toBeOfClass("cluster_icon_large");
expect(htxt.trim()).toEqual("Coordinators");
expect(ftxt.trim()).toEqual("4/5");
});
it("should render the status ok", function () {
var status = "ok";
coordinatorStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status warning", function () {
var status = "warning";
coordinatorStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status critical", function () {
var status = "critical";
coordinatorStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
});
checkUserActions();
});
});
});
});
describe("rendering", function() {
var checkUserActions = function() {
describe("user actions", function() {
var info;
beforeEach(function() {
serverView.render.reset();
coordinatorView.render.reset();
view.render();
spyOn(view, "render");
});
it("should be able to navigate to db servers", function() {
$("#dbserver").click();
expect(serverView.render).toHaveBeenCalledWith();
expect(coordinatorView.unrender).toHaveBeenCalled();
expect(view.render).toHaveBeenCalledWith(true);
});
it("should be able to navigate to coordinators", function() {
$("#coordinator").click();
expect(coordinatorView.render).toHaveBeenCalledWith();
expect(serverView.unrender).toHaveBeenCalled();
expect(view.render).toHaveBeenCalledWith(true);
});
});
},
checkShowStatus = function (btn, status) {
var classNames = {
ok: "btn-success",
warning: "btn-warning",
critical: "btn-danger"
};
expect(btn).toBeOfClass(classNames[status]);
delete classNames[status];
_.each(classNames, function(v) {
expect(btn).toNotHaveClass(v);
});
};
beforeEach(function() {
spyOn(serverView, "render");
spyOn(serverView, "unrender");
spyOn(coordinatorView, "render");
spyOn(coordinatorView, "unrender");
view = new window.ClusterOverviewView({
dbservers: clusterServers,
coordinators: clusterCoordinators
});
});
describe("minified version", function() {
beforeEach(function() {
view.render(true);
});
it("should not render the Server view", function() {
expect(serverView.render).not.toHaveBeenCalled();
});
it("should not render the Coordinator view", function() {
expect(coordinatorView.render).not.toHaveBeenCalled();
});
it("should render in minified version", function() {
expect($(div).hasClass("clusterColumnMax")).toBeFalsy();
});
describe("dbservers" , function() {
var getButton = function() {
return document.getElementById("dbserver");
};
it("should render the amounts", function() {
serverPlan = 5;
serverHaving = 4;
view.render(true);
var btn = getButton(),
span = btn.firstChild,
txt = $(span).text();
expect(btn).toBeDefined();
expect(span).toBeDefined();
expect(span).toBeOfClass("arangoicon");
expect(span).toBeOfClass("icon_arangodb_database1");
expect(span).toBeOfClass("cluster_icon_small");
expect(txt.trim()).toEqual("4/5");
});
it("should render the status ok", function() {
var status = "ok";
serverStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status warning", function() {
var status = "warning";
serverStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status critical", function() {
var status = "critical";
serverStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
});
describe("coordinators" , function() {
var getButton = function() {
return document.getElementById("coordinator");
};
it("should render the amounts", function() {
coordinatorPlan = 5;
coordinatorHaving = 4;
view.render(true);
var btn = getButton(),
span = btn.firstChild,
txt = $(span).text();
expect(btn).toBeDefined();
expect(span).toBeDefined();
expect(span).toBeOfClass("arangoicon");
expect(span).toBeOfClass("icon_arangodb_compass");
expect(span).toBeOfClass("cluster_icon_small");
expect(txt.trim()).toEqual("4/5");
});
it("should render the status ok", function() {
var status = "ok";
coordinatorStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status warning", function() {
var status = "warning";
coordinatorStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
it("should render the status critical", function() {
var status = "critical";
coordinatorStatus = status;
view.render(true);
checkShowStatus(getButton(), status);
});
});
checkUserActions();
});
describe("maximised version", function() {
beforeEach(function() {
view.render();
});
it("should not render the Server view", function() {
expect(serverView.render).not.toHaveBeenCalled();
});
it("should increase the size of the column to maximum", function() {
expect($(div).hasClass("clusterColumnMax")).toBeTruthy();
});
describe("dbservers" , function() {
var getTile = function() {
return document.getElementById("dbserver");
};
it("should render the tile", function() {
serverPlan = 5;
serverHaving = 4;
view.render();
var tile = getTile(),
headers = $("> h4", $(tile)),
header = headers[0],
footer = headers[1],
icon = $("> div > span", $(tile))[0],
htxt = $(header).text(),
ftxt = $(footer).text();
expect(tile).toBeDefined();
expect(tile).toBeOfClass("tile");
expect(tile).toBeOfClass("tile-left");
expect(icon).toBeDefined();
expect(icon).toBeOfClass("arangoicon");
expect(icon).toBeOfClass("icon_arangodb_database1");
expect(icon).toBeOfClass("cluster_icon_large");
expect(htxt.trim()).toEqual("Data Servers");
expect(ftxt.trim()).toEqual("4/5");
});
it("should render the status ok", function() {
var status = "ok";
serverStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status warning", function() {
var status = "warning";
serverStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status critical", function() {
var status = "critical";
serverStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
});
describe("coordinators" , function() {
var getTile = function() {
return document.getElementById("coordinator");
};
it("should render the tile", function() {
coordinatorPlan = 5;
coordinatorHaving = 4;
view.render();
var tile = getTile(),
headers = $("> h4", $(tile)),
header = headers[0],
footer = headers[1],
icon = $("> div > span", $(tile))[0],
htxt = $(header).text(),
ftxt = $(footer).text();
expect(tile).toBeDefined();
expect(tile).toBeOfClass("tile");
expect(tile).toBeOfClass("tile-right");
expect(icon).toBeDefined();
expect(icon).toBeOfClass("arangoicon");
expect(icon).toBeOfClass("icon_arangodb_compass");
expect(icon).toBeOfClass("cluster_icon_large");
expect(htxt.trim()).toEqual("Coordinators");
expect(ftxt.trim()).toEqual("4/5");
});
it("should render the status ok", function() {
var status = "ok";
coordinatorStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status warning", function() {
var status = "warning";
coordinatorStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
it("should render the status critical", function() {
var status = "critical";
coordinatorStatus = status;
view.render();
checkShowStatus(getTile(), status);
});
});
checkUserActions();
});
});
});
}());

View File

@ -2,280 +2,282 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine, $, _, uiMatchers*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Server View", function() {
var view, div, dbView, dbCol;
describe("Cluster Server View", function () {
var view, div, dbView, dbCol;
beforeEach(function() {
div = document.createElement("div");
div.id = "clusterServers";
document.body.appendChild(div);
dbView = {
render: function() {},
unrender: function() {}
};
dbCol = {
__id: "testId"
};
spyOn(window, "ClusterDatabaseView").andReturn(dbView);
spyOn(window, "ClusterDatabases").andReturn(dbCol);
uiMatchers.define(this);
});
afterEach(function() {
document.body.removeChild(div);
});
describe("initialisation", function() {
it("should create a Cluster Database View", function() {
view = new window.ClusterServerView();
expect(window.ClusterDatabaseView).toHaveBeenCalledWith({
collection: dbCol
beforeEach(function () {
div = document.createElement("div");
div.id = "clusterServers";
document.body.appendChild(div);
dbView = {
render: function () {
},
unrender: function () {
}
};
dbCol = {
__id: "testId"
};
spyOn(window, "ClusterDatabaseView").andReturn(dbView);
spyOn(window, "ClusterDatabases").andReturn(dbCol);
uiMatchers.define(this);
});
});
});
afterEach(function () {
document.body.removeChild(div);
});
describe("rendering", function() {
describe("initialisation", function () {
var okPair, noBkp, deadBkp, deadPrim, deadPair,
fakeServers, dbServers,
getTile = function(name) {
return document.getElementById(name);
},
checkUserActions = function() {
describe("user actions", function() {
var info;
it("should be able to navigate to each server", function() {
spyOn(view, "render");
_.each(fakeServers, function(o) {
dbView.render.reset();
view.render.reset();
var name = o.primary.name;
$(getTile(name)).click();
expect(dbView.render).toHaveBeenCalledWith(name);
expect(view.render).toHaveBeenCalledWith(true);
});
it("should create a Cluster Database View", function () {
view = new window.ClusterServerView();
expect(window.ClusterDatabaseView).toHaveBeenCalledWith({
collection: dbCol
});
});
});
},
checkDominoLayout = function(tile) {
var tileElements = tile.children,
upper = tileElements[0],
line = tileElements[1],
lower = tileElements[2];
expect(tile).toBeOfClass("domino");
expect(tile).toBeOfClass("server");
expect(upper).toBeOfClass("domino-upper");
expect(line).toBeOfClass("domino-line");
expect(lower).toBeOfClass("domino-lower");
expect(upper.children[0]).toBeOfClass("domino-header");
expect(lower.children[0]).toBeOfClass("domino-header");
};
beforeEach(function() {
spyOn(dbView, "render");
spyOn(dbView, "unrender");
okPair = {
primary: {
name: "Pavel",
address: "tcp://192.168.0.1:1337",
status: "ok"
},
secondary: {
name: "Sally",
address: "tcp://192.168.1.1:1337",
status: "ok"
}
};
noBkp = {
primary: {
name: "Pancho",
address: "tcp://192.168.0.2:1337",
status: "ok"
}
};
deadBkp = {
primary: {
name: "Pepe",
address: "tcp://192.168.0.3:1337",
status: "ok"
},
secondary: {
name: "Sam",
address: "tcp://192.168.1.3:1337",
status: "critical"
}
};
deadPrim = {
primary: {
name: "Pedro",
address: "tcp://192.168.0.4:1337",
status: "critical"
},
secondary: {
name: "Sabrina",
address: "tcp://192.168.1.4:1337",
status: "ok"
}
};
deadPair = {
primary: {
name: "Pablo",
address: "tcp://192.168.0.5:1337",
status: "critical"
},
secondary: {
name: "Sandy",
address: "tcp://192.168.1.5:1337",
status: "critical"
}
};
fakeServers = [
okPair,
noBkp,
deadBkp,
deadPrim
];
dbServers = {
getList: function() {
return fakeServers;
}
};
view = new window.ClusterServerView({
collection: dbServers
});
view.render();
});
it("should not render the Database view", function() {
expect(dbView.render).not.toHaveBeenCalled();
expect(dbView.unrender).toHaveBeenCalled();
});
it("should offer an unrender function", function() {
dbView.unrender.reset();
view.unrender();
expect($(div).html()).toEqual("");
expect(dbView.unrender).toHaveBeenCalled();
});
describe("minified version", function() {
var checkButtonContent = function(btn, pair, cls) {
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("server");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(pair.primary.name);
};
beforeEach(function() {
view.render(true);
});
it("should render all pairs", function() {
expect($("button", $(div)).length).toEqual(4);
});
it("should render the good pair", function() {
checkButtonContent(
document.getElementById(okPair.primary.name),
okPair,
"success"
);
});
it("should render the single primary", function() {
checkButtonContent(
document.getElementById(noBkp.primary.name),
noBkp,
"success"
);
});
it("should render the dead secondary", function() {
checkButtonContent(
document.getElementById(deadBkp.primary.name),
deadBkp,
"success"
);
});
it("should render the dead primary", function() {
checkButtonContent(
document.getElementById(deadPrim.primary.name),
deadPrim,
"danger"
);
});
checkUserActions();
});
describe("rendering", function () {
describe("maximised version", function() {
var okPair, noBkp, deadBkp, deadPrim, deadPair,
fakeServers, dbServers,
getTile = function (name) {
return document.getElementById(name);
},
var checkDominoContent = function(tile, pair, btn1, btn2) {
var upper = tile.children[0],
lower = tile.children[2];
expect(upper).toBeOfClass("btn-" + btn1);
expect($(upper.children[0]).text()).toEqual(pair.primary.name);
expect($(upper.children[1]).text()).toEqual(pair.primary.address);
expect(lower).toBeOfClass("btn-" + btn2);
if (pair.secondary) {
expect($(lower.children[0]).text()).toEqual(pair.secondary.name);
expect($(lower.children[1]).text()).toEqual(pair.secondary.address);
} else {
expect($(lower.children[0]).text()).toEqual("Not configured");
}
};
checkUserActions = function () {
describe("user actions", function () {
var info;
beforeEach(function() {
view.render();
});
it("should be able to navigate to each server", function () {
spyOn(view, "render");
_.each(fakeServers, function (o) {
dbView.render.reset();
view.render.reset();
var name = o.primary.name;
$(getTile(name)).click();
expect(dbView.render).toHaveBeenCalledWith(name);
expect(view.render).toHaveBeenCalledWith(true);
});
});
it("should render all pairs", function() {
expect($("> div.domino", $(div)).length).toEqual(4);
});
});
},
it("should render the good pair", function() {
var tile = getTile(okPair.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, okPair, "success", "success");
});
checkDominoLayout = function (tile) {
var tileElements = tile.children,
upper = tileElements[0],
line = tileElements[1],
lower = tileElements[2];
expect(tile).toBeOfClass("domino");
expect(tile).toBeOfClass("server");
expect(upper).toBeOfClass("domino-upper");
expect(line).toBeOfClass("domino-line");
expect(lower).toBeOfClass("domino-lower");
expect(upper.children[0]).toBeOfClass("domino-header");
expect(lower.children[0]).toBeOfClass("domino-header");
};
it("should render the single primary", function() {
var tile = getTile(noBkp.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, noBkp, "success", "inactive");
});
beforeEach(function () {
spyOn(dbView, "render");
spyOn(dbView, "unrender");
okPair = {
primary: {
name: "Pavel",
address: "tcp://192.168.0.1:1337",
status: "ok"
},
secondary: {
name: "Sally",
address: "tcp://192.168.1.1:1337",
status: "ok"
}
};
noBkp = {
primary: {
name: "Pancho",
address: "tcp://192.168.0.2:1337",
status: "ok"
}
};
deadBkp = {
primary: {
name: "Pepe",
address: "tcp://192.168.0.3:1337",
status: "ok"
},
secondary: {
name: "Sam",
address: "tcp://192.168.1.3:1337",
status: "critical"
}
};
deadPrim = {
primary: {
name: "Pedro",
address: "tcp://192.168.0.4:1337",
status: "critical"
},
secondary: {
name: "Sabrina",
address: "tcp://192.168.1.4:1337",
status: "ok"
}
};
deadPair = {
primary: {
name: "Pablo",
address: "tcp://192.168.0.5:1337",
status: "critical"
},
secondary: {
name: "Sandy",
address: "tcp://192.168.1.5:1337",
status: "critical"
}
};
fakeServers = [
okPair,
noBkp,
deadBkp,
deadPrim
];
dbServers = {
getList: function () {
return fakeServers;
}
};
view = new window.ClusterServerView({
collection: dbServers
});
view.render();
});
it("should render the dead secondary pair", function() {
var tile = getTile(deadBkp.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, deadBkp, "success", "danger");
});
it("should not render the Database view", function () {
expect(dbView.render).not.toHaveBeenCalled();
expect(dbView.unrender).toHaveBeenCalled();
});
it("should render the dead primary pair", function() {
var tile = getTile(deadPrim.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, deadPrim, "danger", "success");
});
it("should offer an unrender function", function () {
dbView.unrender.reset();
view.unrender();
expect($(div).html()).toEqual("");
expect(dbView.unrender).toHaveBeenCalled();
});
checkUserActions();
describe("minified version", function () {
});
var checkButtonContent = function (btn, pair, cls) {
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("server");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(pair.primary.name);
};
beforeEach(function () {
view.render(true);
});
it("should render all pairs", function () {
expect($("button", $(div)).length).toEqual(4);
});
it("should render the good pair", function () {
checkButtonContent(
document.getElementById(okPair.primary.name),
okPair,
"success"
);
});
it("should render the single primary", function () {
checkButtonContent(
document.getElementById(noBkp.primary.name),
noBkp,
"success"
);
});
it("should render the dead secondary", function () {
checkButtonContent(
document.getElementById(deadBkp.primary.name),
deadBkp,
"success"
);
});
it("should render the dead primary", function () {
checkButtonContent(
document.getElementById(deadPrim.primary.name),
deadPrim,
"danger"
);
});
checkUserActions();
});
describe("maximised version", function () {
var checkDominoContent = function (tile, pair, btn1, btn2) {
var upper = tile.children[0],
lower = tile.children[2];
expect(upper).toBeOfClass("btn-" + btn1);
expect($(upper.children[0]).text()).toEqual(pair.primary.name);
expect($(upper.children[1]).text()).toEqual(pair.primary.address);
expect(lower).toBeOfClass("btn-" + btn2);
if (pair.secondary) {
expect($(lower.children[0]).text()).toEqual(pair.secondary.name);
expect($(lower.children[1]).text()).toEqual(pair.secondary.address);
} else {
expect($(lower.children[0]).text()).toEqual("Not configured");
}
};
beforeEach(function () {
view.render();
});
it("should render all pairs", function () {
expect($("> div.domino", $(div)).length).toEqual(4);
});
it("should render the good pair", function () {
var tile = getTile(okPair.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, okPair, "success", "success");
});
it("should render the single primary", function () {
var tile = getTile(noBkp.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, noBkp, "success", "inactive");
});
it("should render the dead secondary pair", function () {
var tile = getTile(deadBkp.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, deadBkp, "success", "danger");
});
it("should render the dead primary pair", function () {
var tile = getTile(deadPrim.primary.name);
checkDominoLayout(tile);
checkDominoContent(tile, deadPrim, "danger", "success");
});
checkUserActions();
});
});
});
});
}());

View File

@ -2,87 +2,87 @@
/*global describe, beforeEach, afterEach, it, */
/*global spyOn, expect*/
/*global templateEngine, $, uiMatchers*/
(function() {
"use strict";
(function () {
"use strict";
describe("Cluster Shard View", function() {
var view, div;
describe("Cluster Shard View", function () {
var view, div;
beforeEach(function() {
div = document.createElement("div");
div.id = "clusterShards";
document.body.appendChild(div);
uiMatchers.define(this);
});
afterEach(function() {
document.body.removeChild(div);
});
describe("rendering", function() {
var s1, s2, s3, shards, shardCol,
checkButtonContent = function(sh, cls) {
var btn = document.getElementById(sh.id);
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("btn-server");
expect(btn).toBeOfClass("shard");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(sh.id);
};
beforeEach(function() {
s1 = {
id: "Shard 1",
status: "ok"
};
s2 = {
id: "Shard 2",
status: "warning"
};
s3 = {
id: "Shard 3",
status: "critical"
};
shards = [
s1,
s2,
s3
];
shardCol = {
getList: function() {
return shards;
}
};
view = new window.ClusterShardsView({
collection: shardCol
beforeEach(function () {
div = document.createElement("div");
div.id = "clusterShards";
document.body.appendChild(div);
uiMatchers.define(this);
});
view.render();
});
it("should render the first shard", function() {
checkButtonContent(s1, "success");
});
afterEach(function () {
document.body.removeChild(div);
});
it("should render the second shard", function() {
checkButtonContent(s2, "warning");
});
describe("rendering", function () {
it("should render the third shard", function() {
checkButtonContent(s3, "danger");
});
var s1, s2, s3, shards, shardCol,
checkButtonContent = function (sh, cls) {
var btn = document.getElementById(sh.id);
expect(btn).toBeOfClass("btn");
expect(btn).toBeOfClass("btn-server");
expect(btn).toBeOfClass("shard");
expect(btn).toBeOfClass("btn-" + cls);
expect($(btn).text()).toEqual(sh.id);
};
beforeEach(function () {
s1 = {
id: "Shard 1",
status: "ok"
};
s2 = {
id: "Shard 2",
status: "warning"
};
s3 = {
id: "Shard 3",
status: "critical"
};
shards = [
s1,
s2,
s3
];
shardCol = {
getList: function () {
return shards;
}
};
view = new window.ClusterShardsView({
collection: shardCol
});
view.render();
});
it("should render the first shard", function () {
checkButtonContent(s1, "success");
});
it("should render the second shard", function () {
checkButtonContent(s2, "warning");
});
it("should render the third shard", function () {
checkButtonContent(s3, "danger");
});
it("should offer an unrender function", function () {
view.unrender();
expect($(div).html()).toEqual("");
});
});
it("should offer an unrender function", function() {
view.unrender();
expect($(div).html()).toEqual("");
});
});
});
}());

View File

@ -14,7 +14,7 @@
sysCol;
beforeEach(function () {
isCoordinator = false;
isCoordinator = false;
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
@ -43,7 +43,8 @@
var cols = [edgeCol, docCol, sysCol];
spyOn($, "ajax").andCallFake(function (url) {
return {done:function() {}};
return {done: function () {
}};
});
myStore = new window.arangoCollections(cols);
spyOn(window, "isCoordinator").andReturn(isCoordinator);
@ -188,17 +189,17 @@
});
it("Check if Name Sort is active", function () {
var old = myView.collection.searchOptions,
wasRendered;
myView.render();
myView.collection.searchOptions = {sortBy : [1,2,3]};
var old = myView.collection.searchOptions,
wasRendered;
myView.render();
myView.collection.searchOptions = {sortBy: [1, 2, 3]};
spyOn(myView, 'render').andCallFake(function () {
wasRendered = true;
});
myView.sortName();
expect(wasRendered).toBeTruthy();
myView.collection.searchOptions = old;
spyOn(myView, 'render').andCallFake(function () {
wasRendered = true;
});
myView.sortName();
expect(wasRendered).toBeTruthy();
myView.collection.searchOptions = old;
});
it("Check if Type is inactive", function () {
@ -214,9 +215,9 @@
it("Check if Type is active", function () {
var old = myView.collection.searchOptions,
wasRendered;
wasRendered;
myView.render();
myView.collection.searchOptions = {sortBy : [1,2,3]};
myView.collection.searchOptions = {sortBy: [1, 2, 3]};
spyOn(myView, 'render').andCallFake(function () {
wasRendered = true;
@ -239,9 +240,9 @@
it("Check if sortOrder is active", function () {
var old = myView.collection.searchOptions,
wasRendered;
wasRendered;
myView.render();
myView.collection.searchOptions = {sortOrder : [1,2,3]};
myView.collection.searchOptions = {sortOrder: [1, 2, 3]};
spyOn(myView, 'render').andCallFake(function (request) {
wasRendered = true;
@ -271,7 +272,7 @@
it("Check if search needs to be executed (false)", function () {
myView.render();
var wasRendered = false,
old;
old;
spyOn(myView, 'render').andCallFake(function (request) {
wasRendered = true;
@ -338,8 +339,10 @@
it("test toggleView", function () {
myView.render();
var a = {
toggleClass : function() {},
slideToggle : function() {}
toggleClass: function () {
},
slideToggle: function () {
}
};
spyOn(window, "$").andReturn(a);
@ -354,13 +357,14 @@
it("test checkBoxes", function () {
myView.render();
var e = {
currentTarget : {
id : 1
}
},
a = {
click : function() {}
};
currentTarget: {
id: 1
}
},
a = {
click: function () {
}
};
spyOn(window, "$").andReturn(a);
@ -370,40 +374,49 @@
});
it(
"test set #collectionsToggle is deactivated when #collectionsDropdown2 is invisible",
function () {
var a = {
css : function() {
return 'none';
},
is : function(){return true;},
show : function(){},
append : function(){
return {
render : function() {
return {el: 1};
}
};
},
removeClass : function() {},
val : function(){},
focus : function(){},
html : function(){},
attr : function(){}
"test set #collectionsToggle is deactivated when " +
"#collectionsDropdown2 is invisible",
function () {
var a = {
css: function () {
return 'none';
},
is: function () {
return true;
},
show: function () {
},
append: function () {
return {
render: function () {
return {el: 1};
}
};
},
removeClass: function () {
},
val: function () {
},
focus: function () {
},
html: function () {
},
attr: function () {
}
};
spyOn(window, "CollectionListItemView").andReturn({
render : function() {
return {el: 1};
}
};
spyOn(window, "CollectionListItemView").andReturn({
render: function () {
return {el: 1};
}
});
spyOn(arangoHelper, "fixTooltips").andReturn();
spyOn(window, "$").andReturn(a);
spyOn(a, "removeClass");
myView.render();
expect(a.removeClass).toHaveBeenCalledWith('activated');
});
spyOn(arangoHelper, "fixTooltips").andReturn();
spyOn(window, "$").andReturn(a);
spyOn(a, "removeClass");
myView.render();
expect(a.removeClass).toHaveBeenCalledWith('activated');
});
});
it("test restrictToSearchPhrase", function () {

View File

@ -49,107 +49,107 @@
d3ChartDummy = {
x : function(a) {
a({label : 1});
x: function (a) {
a({label: 1});
return d3ChartDummy;
},
y : function(a) {
a({label : 1});
y: function (a) {
a({label: 1});
return d3ChartDummy;
},
width : function(a) {
width: function (a) {
return d3ChartDummy;
},
height : function(a) {
height: function (a) {
return d3ChartDummy;
},
margin : function(a) {
margin: function (a) {
return d3ChartDummy;
},
showValues : function(a) {
showValues: function (a) {
return d3ChartDummy;
},
showYAxis : function(a) {
showYAxis: function (a) {
return d3ChartDummy;
},
showXAxis : function(a) {
showXAxis: function (a) {
return d3ChartDummy;
},
transitionDuration : function(a) {
transitionDuration: function (a) {
return d3ChartDummy;
},
tooltips : function(a) {
tooltips: function (a) {
return d3ChartDummy;
},
showLegend : function(a) {
showLegend: function (a) {
return d3ChartDummy;
},
stacked : function(a) {
stacked: function (a) {
return d3ChartDummy;
},
showControls : function(a) {
showControls: function (a) {
return d3ChartDummy;
},
classed : function(a) {
classed: function (a) {
return d3ChartDummy;
},
yAxis : {
tickFormat : function(a) {
yAxis: {
tickFormat: function (a) {
a();
},
showMaxMin : function() {
showMaxMin: function () {
}
},
xAxis : {
tickFormat : function(a) {
xAxis: {
tickFormat: function (a) {
a();
},
showMaxMin : function() {
showMaxMin: function () {
}
},
datum : function(a) {
datum: function (a) {
return d3ChartDummy;
},
call : function(a) {
call: function (a) {
return d3ChartDummy;
},
data : function(a) {
data: function (a) {
return d3ChartDummy;
},
enter : function(a) {
enter: function (a) {
return d3ChartDummy;
},
append : function(a) {
append: function (a) {
return d3ChartDummy;
},
style : function(a) {
style: function (a) {
return d3ChartDummy;
},
attr : function(a) {
attr: function (a) {
return d3ChartDummy;
},
text : function(a) {
text: function (a) {
if (a instanceof Function) {
a();
}
return d3ChartDummy;
},
select : function (a) {
select: function (a) {
return d3ChartDummy;
},
remove : function (a) {
remove: function (a) {
return d3ChartDummy;
},
selectAll : function (a) {
selectAll: function (a) {
return d3ChartDummy;
},
on : function (a) {
on: function (a) {
return d3ChartDummy;
}
@ -769,9 +769,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 200});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 200});
view.history = {residentSizeChart : [
view.history = {residentSizeChart: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -793,7 +793,7 @@
]
}
], virtualSizeCurrent : [10, 20]};
], virtualSizeCurrent: [10, 20]};
view.prepareResidentSize(true);
expect(view.getCurrentSize).toHaveBeenCalledWith('#residentSizeChartContainer');
@ -813,9 +813,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 200});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 200});
view.history = {totalTimeDistribution : [
view.history = {totalTimeDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -837,7 +837,7 @@
]
}
], dataTransferDistribution : [
], dataTransferDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -883,9 +883,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 200});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 200});
view.history = {totalTimeDistribution : [
view.history = {totalTimeDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -907,7 +907,7 @@
]
}
], dataTransferDistribution : [
], dataTransferDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -952,9 +952,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 404});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 404});
view.history = {totalTimeDistribution : [
view.history = {totalTimeDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -976,7 +976,7 @@
]
}
], dataTransferDistribution : [
], dataTransferDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -1021,9 +1021,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 304});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 304});
view.history = {totalTimeDistribution : [
view.history = {totalTimeDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -1045,7 +1045,7 @@
]
}
], dataTransferDistribution : [
], dataTransferDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -1090,9 +1090,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 204});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 204});
view.history = {totalTimeDistribution : [
view.history = {totalTimeDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -1114,7 +1114,7 @@
]
}
], dataTransferDistribution : [
], dataTransferDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -1159,9 +1159,9 @@
spyOn(d3, "select").andReturn(d3ChartDummy);
spyOn(view, "getCurrentSize").andReturn({height : 190, width : 11});
spyOn(view, "getCurrentSize").andReturn({height: 190, width: 11});
view.history = {totalTimeDistribution : [
view.history = {totalTimeDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],
@ -1183,7 +1183,7 @@
]
}
], dataTransferDistribution : [
], dataTransferDistribution: [
{
"key": "",
"color": dyGraphConfigDummy.colors[1],

View File

@ -2,101 +2,101 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect, runs, waitsFor*/
/*global _, $, DBSelectionView*/
(function() {
"use strict";
(function () {
"use strict";
describe("DB Selection", function() {
var view,
list,
dbCollection,
fetched,
current,
div;
describe("DB Selection", function () {
beforeEach(function() {
dbCollection = new window.ArangoDatabase(
[],
{shouldFetchUser: true}
);
var view,
list,
dbCollection,
fetched,
current,
div;
beforeEach(function () {
dbCollection = new window.ArangoDatabase(
[],
{shouldFetchUser: true}
);
//dbCollection = new window.ArangoDatabase();
list = ["_system", "second", "first"];
current = new window.CurrentDatabase({
name: "first",
isSystem: false
});
_.each(list, function(n) {
dbCollection.add({name: n});
});
fetched = false;
spyOn(dbCollection, "fetch");
div = document.createElement("li");
div.id = "dbSelect";
document.body.appendChild(div);
view = new DBSelectionView(
{
collection: dbCollection,
current: current
}
);
//dbCollection = new window.ArangoDatabase();
list = ["_system", "second", "first"];
current = new window.CurrentDatabase({
name: "first",
isSystem: false
});
_.each(list, function (n) {
dbCollection.add({name: n});
});
fetched = false;
spyOn(dbCollection, "fetch");
div = document.createElement("li");
div.id = "dbSelect";
document.body.appendChild(div);
view = new DBSelectionView(
{
collection: dbCollection,
current: current
}
);
});
afterEach(function () {
document.body.removeChild(div);
});
it("should display all databases ordered", function () {
view.render($(div));
var dbList = $("#dbs_dropdown", $(div)),
childs;
expect(div.childElementCount).toEqual(2);
childs = $(dbList).children();
expect(childs.length).toEqual(4);
expect($("a", $(childs[1])).attr("id")).toEqual(list[0]);
expect($("a", $(childs[2])).attr("id")).toEqual(list[1]);
});
it("should select the current db", function () {
view.render($(div));
expect($($(div).children()[0]).text()).toEqual("DB: " + current.get("name") + " ");
});
it("should trigger fetch on collection", function () {
view.render($(div));
expect(dbCollection.fetch).toHaveBeenCalled();
});
/*
it("should trigger a database switch on click", function() {
view.render($(div));
spyOn(dbCollection, "createDatabaseURL").andReturn("switchURL");
spyOn(window.location, "replace");
$("#dbSelectionList").val("second").trigger("change");
expect(dbCollection.createDatabaseURL).toHaveBeenCalledWith("second");
expect(window.location.replace).toHaveBeenCalledWith("switchURL");
});
*/
it("should not render the selection if the list has only one element", function () {
//var oneCollection = new window.ArangoDatabase();
var oneCollection = new window.ArangoDatabase(
[],
{shouldFetchUser: true}
);
oneCollection.add(current);
spyOn(oneCollection, "fetch");
view = new DBSelectionView(
{
collection: oneCollection,
current: current
}
);
view.render($(div));
expect($(div).text().trim()).toEqual("DB: first");
});
});
afterEach(function() {
document.body.removeChild(div);
});
it("should display all databases ordered", function() {
view.render($(div));
var dbList = $("#dbs_dropdown", $(div)),
childs;
expect(div.childElementCount).toEqual(2);
childs = $(dbList).children();
expect(childs.length).toEqual(4);
expect($("a", $(childs[1])).attr("id")).toEqual(list[0]);
expect($("a", $(childs[2])).attr("id")).toEqual(list[1]);
});
it("should select the current db", function() {
view.render($(div));
expect($($(div).children()[0]).text()).toEqual("DB: " + current.get("name") + " ");
});
it("should trigger fetch on collection", function() {
view.render($(div));
expect(dbCollection.fetch).toHaveBeenCalled();
});
/*
it("should trigger a database switch on click", function() {
view.render($(div));
spyOn(dbCollection, "createDatabaseURL").andReturn("switchURL");
spyOn(window.location, "replace");
$("#dbSelectionList").val("second").trigger("change");
expect(dbCollection.createDatabaseURL).toHaveBeenCalledWith("second");
expect(window.location.replace).toHaveBeenCalledWith("switchURL");
});
*/
it("should not render the selection if the list has only one element", function() {
//var oneCollection = new window.ArangoDatabase();
var oneCollection = new window.ArangoDatabase(
[],
{shouldFetchUser: true}
);
oneCollection.add(current);
spyOn(oneCollection, "fetch");
view = new DBSelectionView(
{
collection: oneCollection,
current: current
}
);
view.render($(div));
expect($(div).text().trim()).toEqual("DB: first");
});
});
}());

View File

@ -2,140 +2,140 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global arangoHelper*/
(function() {
"use strict";
(function () {
"use strict";
describe("The document view", function() {
describe("The document view", function () {
var model, view, div;
var model, view, div;
beforeEach(function() {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
beforeEach(function () {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
model = new window.arangoDocument({
_key: "123",
_id: "v/123",
_rev: "123",
name: "alice"
});
model = new window.arangoDocument({
_key: "123",
_id: "v/123",
_rev: "123",
name: "alice"
});
view = new window.DocumentView({
collection: new window.arangoDocument()
});
view.collection.add(model);
view.render();
});
afterEach(function () {
document.body.removeChild(div);
});
it("assert the basics", function () {
expect(view.colid).toEqual(0);
expect(view.colid).toEqual(0);
expect(view.events).toEqual({
"click #saveDocumentButton": "saveDocument"
});
});
it("should copy a model into editor", function () {
spyOn(view.editor, "set");
view.fillEditor();
expect(view.editor.set).toHaveBeenCalled();
});
it("should save type document", function () {
view.type = 'document';
spyOn(view.collection, "saveDocument").andReturn(true);
view.saveDocument();
expect(view.collection.saveDocument).toHaveBeenCalled();
});
it("should save type edge", function () {
view.type = 'edge';
spyOn(view.collection, "saveEdge").andReturn(true);
view.saveDocument();
expect(view.collection.saveEdge).toHaveBeenCalled();
});
it("should save type edge and return error", function () {
view.type = 'edge';
spyOn(view.collection, "saveEdge").andReturn(false);
spyOn(arangoHelper, "arangoError");
view.saveDocument();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
it("should save type document and return error", function () {
view.type = 'document';
spyOn(view.collection, "saveDocument").andReturn(false);
spyOn(arangoHelper, "arangoError");
view.saveDocument();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
it("check document view type check positive", function () {
view.collection.add(model);
spyOn(view, "fillEditor");
spyOn(view.collection, "getEdge").andReturn(true);
spyOn(view.collection, "getDocument").andReturn(true);
var result = view.typeCheck('edge');
expect(result).toEqual(true);
expect(view.collection.getEdge).toHaveBeenCalled();
result = view.typeCheck('document');
expect(view.collection.getDocument).toHaveBeenCalled();
expect(result).toEqual(true);
});
it("check document view type check negative", function () {
view.collection.add(model);
spyOn(view, "fillEditor");
var result = view.typeCheck('easddge');
expect(result).not.toEqual(true);
result = view.typeCheck(false);
expect(result).not.toEqual(true);
result = view.typeCheck(123);
expect(result).not.toEqual(true);
});
it("should remove readonly keys", function () {
var object = {
hello: 123,
wrong: true,
_key: "123",
_rev: "adasda",
_id: "paosdjfp1321"
},
shouldObject = {
hello: 123,
wrong: true
},
result = view.removeReadonlyKeys(object);
expect(result).toEqual(shouldObject);
});
it("should modify the breadcrumb", function () {
var bar = document.createElement("div"),
emptyBar = document.createElement("div");
bar.id = 'transparentHeader';
view.breadcrumb();
expect(emptyBar).not.toBe(bar);
});
it("escaped", function () {
expect(view.escaped('&<>"\'')).toEqual("&amp;&lt;&gt;&quot;&#39;");
});
view = new window.DocumentView({
collection: new window.arangoDocument()
});
view.collection.add(model);
view.render();
});
afterEach(function() {
document.body.removeChild(div);
});
it("assert the basics", function () {
expect(view.colid).toEqual(0);
expect(view.colid).toEqual(0);
expect(view.events).toEqual({
"click #saveDocumentButton" : "saveDocument"
});
});
it("should copy a model into editor", function () {
spyOn(view.editor, "set");
view.fillEditor();
expect(view.editor.set).toHaveBeenCalled();
});
it("should save type document", function () {
view.type = 'document';
spyOn(view.collection, "saveDocument").andReturn(true);
view.saveDocument();
expect(view.collection.saveDocument).toHaveBeenCalled();
});
it("should save type edge", function () {
view.type = 'edge';
spyOn(view.collection, "saveEdge").andReturn(true);
view.saveDocument();
expect(view.collection.saveEdge).toHaveBeenCalled();
});
it("should save type edge and return error", function () {
view.type = 'edge';
spyOn(view.collection, "saveEdge").andReturn(false);
spyOn(arangoHelper, "arangoError");
view.saveDocument();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
it("should save type document and return error", function () {
view.type = 'document';
spyOn(view.collection, "saveDocument").andReturn(false);
spyOn(arangoHelper, "arangoError");
view.saveDocument();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
it("check document view type check positive", function() {
view.collection.add(model);
spyOn(view, "fillEditor");
spyOn(view.collection, "getEdge").andReturn(true);
spyOn(view.collection, "getDocument").andReturn(true);
var result = view.typeCheck('edge');
expect(result).toEqual(true);
expect(view.collection.getEdge).toHaveBeenCalled();
result = view.typeCheck('document');
expect(view.collection.getDocument).toHaveBeenCalled();
expect(result).toEqual(true);
});
it("check document view type check negative", function() {
view.collection.add(model);
spyOn(view, "fillEditor");
var result = view.typeCheck('easddge');
expect(result).not.toEqual(true);
result = view.typeCheck(false);
expect(result).not.toEqual(true);
result = view.typeCheck(123);
expect(result).not.toEqual(true);
});
it("should remove readonly keys", function() {
var object = {
hello: 123,
wrong: true,
_key: "123",
_rev: "adasda",
_id: "paosdjfp1321"
},
shouldObject = {
hello: 123,
wrong: true
},
result = view.removeReadonlyKeys(object);
expect(result).toEqual(shouldObject);
});
it("should modify the breadcrumb", function () {
var bar = document.createElement("div"),
emptyBar = document.createElement("div");
bar.id = 'transparentHeader';
view.breadcrumb();
expect(emptyBar).not.toBe(bar);
});
it("escaped", function () {
expect(view.escaped('&<>"\'')).toEqual("&amp;&lt;&gt;&quot;&#39;");
});
});
}());

View File

@ -9,16 +9,16 @@
var view, jQueryDummy;
beforeEach(function () {
window.App = {
navigate: function() {
throw "This should be a spy";
}
};
view = new window.DocumentsView();
window.App = {
navigate: function () {
throw "This should be a spy";
}
};
view = new window.DocumentsView();
});
afterEach(function() {
delete window.App;
afterEach(function () {
delete window.App;
});
it("assert the basics", function () {
@ -243,7 +243,7 @@
};
spyOn(arangoDocStoreDummy, "getDocuments");
spyOn(window, "arangoDocuments").andReturn(arangoDocStoreDummy);
view.collection = new window.arangoDocuments({collectionID : view.colid});
view.collection = new window.arangoDocuments({collectionID: view.colid});
view.resetView();
expect(window.$).toHaveBeenCalledWith("input");
expect(window.$).toHaveBeenCalledWith("select");
@ -624,9 +624,8 @@
{1: "blub"}
];
expect(view.getFilterContent()).toEqual([
{ attribute : 'name0', operator : 'operator0', value :
{ jsonval : 1 } },
{ attribute : 'name1', operator : 'operator1', value : 'stringval' }
{ attribute: 'name0', operator: 'operator0', value: { jsonval: 1 } },
{ attribute: 'name1', operator: 'operator1', value: 'stringval' }
]);
expect(window.$).toHaveBeenCalledWith("#attribute_value0");
expect(window.$).toHaveBeenCalledWith("#attribute_value1");
@ -654,23 +653,22 @@
spyOn(window, "$").andReturn(jQueryDummy);
spyOn(view, "getFilterContent").andReturn(
[
{ attribute : 'name0', operator : 'operator0', value :
{ jsonval : 1 } },
{ attribute : 'name1', operator : 'operator1', value : 'stringval' }
{ attribute: 'name0', operator: 'operator0', value: { jsonval: 1 } },
{ attribute: 'name1', operator: 'operator1', value: 'stringval' }
]
);
var arangoDocStoreDummy = {
setToFirst: function () {
},
addFilter : function () {
setToFirst: function () {
},
addFilter: function () {
},
getDocuments : function () {
},
getDocuments: function () {
}
};
}
};
spyOn(arangoDocStoreDummy, "setToFirst");
spyOn(arangoDocStoreDummy, "addFilter");
spyOn(arangoDocStoreDummy, "getDocuments");
@ -683,7 +681,7 @@
expect(view.addDocumentSwitch).toEqual(false);
expect(view.clearTable).toHaveBeenCalled();
expect(arangoDocStoreDummy.addFilter).toHaveBeenCalledWith(
"name0", "operator0", { jsonval : 1 }
"name0", "operator0", { jsonval: 1 }
);
expect(arangoDocStoreDummy.addFilter).toHaveBeenCalledWith(
"name1", "operator1", "stringval"
@ -714,22 +712,22 @@
expect(window.$).toHaveBeenCalledWith("#filterHeader");
expect(jQueryDummy.append).toHaveBeenCalledWith(
' <div class="queryline querylineAdd">' +
'<input id="attribute_name' + num +
'" type="text" placeholder="Attribute name">' +
'<select name="operator" id="operator' +
num + '" class="filterSelect">' +
' <option value="==">==</option>' +
' <option value="!=">!=</option>' +
' <option value="&lt;">&lt;</option>' +
' <option value="&lt;=">&lt;=</option>' +
' <option value="&gt;=">&gt;=</option>' +
' <option value="&gt;">&gt;</option>' +
'</select>' +
'<input id="attribute_value' + num +
'" type="text" placeholder="Attribute value" ' +
'class="filterValue">' +
' <a class="removeFilterItem" id="removeFilter' + num + '">' +
'<i class="icon icon-minus arangoicon"></i></a></div>');
'<input id="attribute_name' + num +
'" type="text" placeholder="Attribute name">' +
'<select name="operator" id="operator' +
num + '" class="filterSelect">' +
' <option value="==">==</option>' +
' <option value="!=">!=</option>' +
' <option value="&lt;">&lt;</option>' +
' <option value="&lt;=">&lt;=</option>' +
' <option value="&gt;=">&gt;=</option>' +
' <option value="&gt;">&gt;</option>' +
'</select>' +
'<input id="attribute_value' + num +
'" type="text" placeholder="Attribute value" ' +
'class="filterValue">' +
' <a class="removeFilterItem" id="removeFilter' + num + '">' +
'<i class="icon icon-minus arangoicon"></i></a></div>');
expect(view.filters[num]).toEqual(true);
});
@ -1155,7 +1153,7 @@
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID : "collection"
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteDocument").andReturn(false);
@ -1208,7 +1206,7 @@
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID : "collection"
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteEdge").andReturn(false);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
@ -1281,7 +1279,7 @@
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID : "collection"
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteDocument").andReturn(true);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
@ -1366,7 +1364,7 @@
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID : "collection"
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteEdge").andReturn(true);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
@ -1471,7 +1469,7 @@
view.alreadyClicked = false;
view.colid = "coll";
view.collection = {
collectionID : "coll"
collectionID: "coll"
};
expect(view.clicked({currentTarget: {firstChild: "blub"}})).toEqual(undefined);
expect(view.addDocument).not.toHaveBeenCalled();
@ -1540,23 +1538,23 @@
totalPages: 1,
currentPage: 1,
documentsCount: 0,
size : function () {
size: function () {
return arangoDocsStoreDummy.models.length;
},
getLastPageNumber : function () {
getLastPageNumber: function () {
return arangoDocsStoreDummy.totalPages;
},
getPage : function () {
getPage: function () {
return arangoDocsStoreDummy.currentPage;
},
getTotal : function () {
getTotal: function () {
return arangoDocsStoreDummy.documentsCount;
}
};
spyOn(view, "clearTable");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
view.collection= new window.arangoDocuments();
view.collection = new window.arangoDocuments();
//$(self.table).dataTable().fnAddData(
view.drawTable();
expect(window.$).toHaveBeenCalledWith(".dataTables_empty");
@ -1617,10 +1615,10 @@
totalPages: 1,
currentPage: 2,
documentsCount: 3,
size : function () {
size: function () {
return arangoDocsStoreDummy.models.length;
},
each : function (cb) {
each: function (cb) {
arangoDocsStoreDummy.models.forEach(cb);
}
@ -1674,8 +1672,8 @@
};
spyOn(window, "arangoCollections").andReturn(arangoCollectionsDummy);
view.collectionsStore = new window.arangoCollections();
view.collection = {collectionID : "1"};
view.collectionsStore = new window.arangoCollections();
view.collection = {collectionID: "1"};
spyOn(view, "getIndex");
spyOn(view, "initTable");
spyOn(view, "breadcrumb");
@ -1806,30 +1804,30 @@
getFilteredDocuments: function () {
},
getPage : function () {
getPage: function () {
},
getLastPageNumber : function () {
getLastPageNumber: function () {
},
setPage : function () {
setPage: function () {
},
getDocuments : function () {
getDocuments: function () {
},
size : function () {
size: function () {
},
models : [],
each : function (cb) {
models: [],
each: function (cb) {
arangoDocsStoreDummy.models.forEach(cb);
}
};
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
spyOn(arangoDocsStoreDummy, "getFilteredDocuments");
spyOn(arangoHelper, "fixTooltips");
view.collection= new window.arangoDocuments();
view.collection = new window.arangoDocuments();
spyOn(view, "getFilterContent").andReturn(
@ -1840,7 +1838,7 @@
);
spyOn(view, "clearTable");
spyOn(view,"rerender");
spyOn(view, "rerender");
view.colid = 1;
view.documentsCount = 11;
view.renderPagination(3, true);
@ -1878,23 +1876,23 @@
getFilteredDocuments: function () {
},
getPage : function () {
getPage: function () {
},
getLastPageNumber : function () {
getLastPageNumber: function () {
},
setPage : function () {
setPage: function () {
},
getDocuments : function () {
getDocuments: function () {
},
size : function () {
size: function () {
},
models : [],
each : function (cb) {
models: [],
each: function (cb) {
arangoDocsStoreDummy.models.forEach(cb);
}
};
@ -1912,7 +1910,7 @@
);
spyOn(view, "clearTable");
spyOn(view,"rerender");
spyOn(view, "rerender");
view.colid = 1;
view.documentsCount = 0;
view.pageid = "1";
@ -1950,50 +1948,50 @@
it("cutByResolution with string longer than 1024", function () {
var string = "12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890",
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890",
resultString = "12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"123456789012345678901234...";
resultString = "12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"123456789012345678901234...";
expect(view.cutByResolution(string)).toEqual(view.escaped(resultString));
@ -2712,8 +2710,8 @@
};
list.forEach(callBackWraper);
};
view.collection = {
collectionID : "coll"
view.collection = {
collectionID: "coll"
};
view.getIndex();
@ -2780,8 +2778,8 @@
list.forEach(callBackWraper);
};
view.collection = {
collectionID : "coll"
view.collection = {
collectionID: "coll"
};
view.getIndex();
@ -2798,7 +2796,8 @@
spyOn(view, "drawTable");
spyOn(view, "renderPagination");
view.collection = {
getDocuments : function () {}
getDocuments: function () {
}
};
spyOn(view.collection, "getDocuments");
@ -2826,8 +2825,10 @@
it("setCollectionId", function () {
view.collection = {
setCollection : function () {},
getDocuments : function () {}
setCollection: function () {
},
getDocuments: function () {
}
};
var arangoCollectionsDummy = {
@ -2852,13 +2853,15 @@
it("renderPaginationElements", function () {
view.collection = {
getTotal: function() {return 5;}
getTotal: function () {
return 5;
}
};
spyOn(view.collection, "getTotal").andCallThrough();
jQueryDummy = {
length : 45,
html : function () {
length: 45,
html: function () {
}
};
@ -2880,13 +2883,15 @@
it("renderPaginationElements with total = 0", function () {
view.collection = {
getTotal : function () {return 5;}
getTotal: function () {
return 5;
}
};
spyOn(view.collection, "getTotal").andCallThrough();
jQueryDummy = {
length : 0,
append : function () {
length: 0,
append: function () {
}
};
@ -2913,7 +2918,7 @@
it("firstPage and lastPage", function () {
spyOn(view, "jumpTo");
view.collection = {
getLastPageNumber : function () {
getLastPageNumber: function () {
return 3;
}
};
@ -2925,8 +2930,6 @@
});
});
}());

View File

@ -2,356 +2,362 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $, _*/
(function() {
"use strict";
(function () {
"use strict";
describe("The view to edit one entry", function() {
var ViewClass, tr, key, val;
describe("The view to edit one entry", function () {
beforeEach(function() {
ViewClass = window.EditListEntryView;
tr = document.createElement("tr");
document.body.appendChild(tr);
var ViewClass, tr, key, val;
beforeEach(function () {
ViewClass = window.EditListEntryView;
tr = document.createElement("tr");
document.body.appendChild(tr);
});
afterEach(function () {
document.body.removeChild(tr);
});
describe("user input", function () {
it("should be able to remove the row", function () {
key = "my_key";
val = "val";
var view = new ViewClass({
key: key,
value: val,
el: tr
});
$(".deleteAttribute").click();
expect(tr.parentElement).toEqual(null);
// Re add it for cleanup function
document.body.appendChild(tr);
});
});
describe("for system attributes", function () {
it("should not offer edit options", function () {
key = "_id";
val = "v/123";
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).text()).toEqual(key);
expect($(".key", tr).is("input")).toBeFalsy();
expect($(".key", tr).is("textarea")).toBeFalsy();
expect($(".val", tr).text()).toEqual(JSON.stringify(val));
expect($(".val", tr).is("input")).toBeFalsy();
expect($(".val", tr).is("textarea")).toBeFalsy();
});
});
describe("for booleans", function () {
it("should be able to display true", function () {
key = "myKey";
val = true;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display false", function () {
key = "myKey";
val = false;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store true", function () {
key = "myKey";
val = JSON.stringify(true);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(true);
});
it("should be able to store false", function () {
key = "myKey";
val = JSON.stringify(false);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(false);
});
});
describe("for numbers", function () {
it("should be able to display an integer", function () {
key = "myKey";
val = 123;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display a float", function () {
key = "myKey";
val = 12.345;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store an integer", function () {
key = "myKey";
val = JSON.stringify(123);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(123);
});
it("should be able to store a float", function () {
key = "myKey";
val = JSON.stringify(10.234);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(10.234);
});
});
describe("for strings", function () {
it("should be able to display a simple string", function () {
key = "myKey";
val = "string";
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display a string with quotation marks", function () {
key = "myKey";
val = 'my "internal" string';
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store a simple string", function () {
key = "myKey";
val = "string";
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
it("should be able to store a float", function () {
key = "myKey";
val = 'my "internal" string';
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
});
describe("for array", function () {
it("should be able to display an array", function () {
key = "myKey";
val = [1, "string", true];
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display an array of arrays", function () {
key = "myKey";
val = [
[1, 2, 3],
["string"]
];
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store an array", function () {
key = "myKey";
val = [1, "string", true];
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '[1, "string", true]';
$(".val", tr).val(valString);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
it("should be able to store an array of arrays", function () {
key = "myKey";
val = [
[1, 2, 3],
["string"]
];
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '[[1, 2, 3], ["string"]]';
$(".val", tr).val(valString);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
});
describe("for array", function () {
it("should be able to display an object", function () {
key = "myKey";
val = {
a: 1,
b: "string",
c: true
};
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display nested objects", function () {
key = "myKey";
val = {
a: {
c: "my",
d: "way"
},
b: true
};
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store an object", function () {
key = "myKey";
val = {
a: 1,
b: "string",
c: true
};
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '{a: 1, b: "string", c: true}',
valStr = JSON.stringify(val),
resStr;
$(".val", tr).val(valString);
resStr = JSON.stringify(view.getValue());
expect(view.getKey()).toEqual(key);
expect(valStr).toEqual(resStr);
});
it("should be able to store nested objects", function () {
key = "myKey";
val = {
a: {
c: "my",
d: "way"
},
b: true
};
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '{a: {c: "my", d: "way"}, b: true}';
$(".val", tr).val(valString);
expect(view.getKey()).toEqual(key);
expect(_.isEqual(view.getValue(), val)).toBeTruthy();
});
});
});
afterEach(function() {
document.body.removeChild(tr);
});
describe("user input", function() {
it("should be able to remove the row", function() {
key = "my_key";
val = "val";
var view = new ViewClass({
key: key,
value: val,
el: tr
});
$(".deleteAttribute").click();
expect(tr.parentElement).toEqual(null);
// Re add it for cleanup function
document.body.appendChild(tr);
});
});
describe("for system attributes", function() {
it("should not offer edit options", function() {
key = "_id";
val = "v/123";
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).text()).toEqual(key);
expect($(".key", tr).is("input")).toBeFalsy();
expect($(".key", tr).is("textarea")).toBeFalsy();
expect($(".val", tr).text()).toEqual(JSON.stringify(val));
expect($(".val", tr).is("input")).toBeFalsy();
expect($(".val", tr).is("textarea")).toBeFalsy();
});
});
describe("for booleans", function() {
it("should be able to display true", function() {
key = "myKey";
val = true;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display false", function() {
key = "myKey";
val = false;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store true", function() {
key = "myKey";
val = JSON.stringify(true);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(true);
});
it("should be able to store false", function() {
key = "myKey";
val = JSON.stringify(false);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(false);
});
});
describe("for numbers", function() {
it("should be able to display an integer", function() {
key = "myKey";
val = 123;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display a float", function() {
key = "myKey";
val = 12.345;
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store an integer", function() {
key = "myKey";
val = JSON.stringify(123);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(123);
});
it("should be able to store a float", function() {
key = "myKey";
val = JSON.stringify(10.234);
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(10.234);
});
});
describe("for strings", function() {
it("should be able to display a simple string", function() {
key = "myKey";
val = "string";
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display a string with quotation marks", function() {
key = "myKey";
val = 'my "internal" string';
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store a simple string", function() {
key = "myKey";
val = "string";
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
it("should be able to store a float", function() {
key = "myKey";
val = 'my "internal" string';
var view = new ViewClass({
key: key,
value: "",
el: tr
});
$(".val", tr).val(val);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
});
describe("for array", function() {
it("should be able to display an array", function() {
key = "myKey";
val = [1, "string", true];
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display an array of arrays", function() {
key = "myKey";
val = [[1, 2, 3], ["string"]];
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store an array", function() {
key = "myKey";
val = [1, "string", true];
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '[1, "string", true]';
$(".val", tr).val(valString);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
it("should be able to store an array of arrays", function() {
key = "myKey";
val = [[1, 2, 3], ["string"]];
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '[[1, 2, 3], ["string"]]';
$(".val", tr).val(valString);
expect(view.getKey()).toEqual(key);
expect(view.getValue()).toEqual(val);
});
});
describe("for array", function() {
it("should be able to display an object", function() {
key = "myKey";
val = {
a: 1,
b: "string",
c: true
};
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to display nested objects", function() {
key = "myKey";
val = {
a: {
c: "my",
d: "way"
},
b: true
};
var view = new ViewClass({
key: key,
value: val,
el: tr
});
expect($(".key", tr).val()).toEqual(key);
expect($(".val", tr).val()).toEqual(JSON.stringify(val));
});
it("should be able to store an object", function() {
key = "myKey";
val = {
a: 1,
b: "string",
c: true
};
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '{a: 1, b: "string", c: true}',
valStr = JSON.stringify(val),
resStr;
$(".val", tr).val(valString);
resStr = JSON.stringify(view.getValue());
expect(view.getKey()).toEqual(key);
expect(valStr).toEqual(resStr);
});
it("should be able to store nested objects", function() {
key = "myKey";
val = {
a: {
c: "my",
d: "way"
},
b: true
};
var view = new ViewClass({
key: key,
value: "",
el: tr
}),
valString = '{a: {c: "my", d: "way"}, b: true}';
$(".val", tr).val(valString);
expect(view.getKey()).toEqual(key);
expect(_.isEqual(view.getValue(), val)).toBeTruthy();
});
});
});
}());

View File

@ -3,121 +3,121 @@
/*global runs, waitsFor, jasmine*/
/*global $, arangoHelper */
(function() {
"use strict";
describe("Foxx Edit View", function() {
var view,
model,
div;
(function () {
"use strict";
beforeEach(function() {
div = document.createElement("div");
div.id = "modalPlaceholder";
document.body.appendChild(div);
model = new window.Foxx({
_key: "1234",
_id: "aal/1234",
title: "TestFoxx",
version: 1.2,
mount: "/testfoxx",
description: "Test application",
git: "gitpath",
app: "app:TestFoxx:1.2",
isSystem: false,
options: {
collectionPrefix: "testfoxx"
},
development: false
});
view = new window.foxxEditView({model: model});
view.render();
});
describe("Foxx Edit View", function () {
var view,
model,
div;
afterEach(function() {
document.body.removeChild(div);
});
it("should be able to switch mount point", function() {
var calledBack,
newMount;
runs(function() {
newMount = "/newMount";
spyOn($, "ajax").andCallFake(function(url, options) {
calledBack = true;
beforeEach(function () {
div = document.createElement("div");
div.id = "modalPlaceholder";
document.body.appendChild(div);
model = new window.Foxx({
_key: "1234",
_id: "aal/1234",
title: "TestFoxx",
version: 1.2,
mount: "/testfoxx",
description: "Test application",
git: "gitpath",
app: "app:TestFoxx:1.2",
isSystem: false,
options: {
collectionPrefix: "testfoxx"
},
development: false
});
view = new window.foxxEditView({model: model});
view.render();
});
$("#change-mount-point").val(newMount);
$("#change").click();
});
waitsFor(function() {
return calledBack;
}, 1000);
runs(function() {
expect($.ajax).toHaveBeenCalledWith(
"foxx/move/" + model.get("_key"),{
dataType: "json",
data: JSON.stringify({
mount: newMount,
app: model.get("app"),
prefix: model.get("options").collectionPrefix
}),
async: false,
type: "PUT",
error: jasmine.any(Function)
});
});
});
it("should not hide the modal view if mountpoint change has failed", function() {
var calledBack,
newMount,
resText;
runs(function() {
newMount = "/newMount";
resText = "Mount-Point already in use";
spyOn($, "ajax").andCallFake(function(url, options) {
expect(options.error).toEqual(jasmine.any(Function));
options.error(
{
status: 409,
statusText: "Conflict",
responseText: resText
}
);
calledBack = true;
afterEach(function () {
document.body.removeChild(div);
});
spyOn(view, "hideModal");
spyOn(arangoHelper, "arangoError");
$("#change-mount-point").val(newMount);
$("#change").click();
});
waitsFor(function() {
return calledBack;
}, 1000);
it("should be able to switch mount point", function () {
var calledBack,
newMount;
runs(function() {
expect(view.hideModal).not.toHaveBeenCalled();
expect(arangoHelper.arangoError).toHaveBeenCalledWith(resText);
});
runs(function () {
newMount = "/newMount";
spyOn($, "ajax").andCallFake(function (url, options) {
calledBack = true;
});
$("#change-mount-point").val(newMount);
$("#change").click();
});
waitsFor(function () {
return calledBack;
}, 1000);
runs(function () {
expect($.ajax).toHaveBeenCalledWith(
"foxx/move/" + model.get("_key"), {
dataType: "json",
data: JSON.stringify({
mount: newMount,
app: model.get("app"),
prefix: model.get("options").collectionPrefix
}),
async: false,
type: "PUT",
error: jasmine.any(Function)
});
});
});
it("should not hide the modal view if mountpoint change has failed", function () {
var calledBack,
newMount,
resText;
runs(function () {
newMount = "/newMount";
resText = "Mount-Point already in use";
spyOn($, "ajax").andCallFake(function (url, options) {
expect(options.error).toEqual(jasmine.any(Function));
options.error(
{
status: 409,
statusText: "Conflict",
responseText: resText
}
);
calledBack = true;
});
spyOn(view, "hideModal");
spyOn(arangoHelper, "arangoError");
$("#change-mount-point").val(newMount);
$("#change").click();
});
waitsFor(function () {
return calledBack;
}, 1000);
runs(function () {
expect(view.hideModal).not.toHaveBeenCalled();
expect(arangoHelper.arangoError).toHaveBeenCalledWith(resText);
});
});
it("should not trigger a remount if mountpoint has not been changed", function () {
spyOn(window, "alert");
$("#change").click();
expect(window.alert).not.toHaveBeenCalled();
});
it("should prevent an illegal mountpoint", function () {
spyOn(arangoHelper, "arangoError");
$("#change-mount-point").val("illegal");
$("#change").click();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
});
it("should not trigger a remount if mountpoint has not been changed", function() {
spyOn(window, "alert");
$("#change").click();
expect(window.alert).not.toHaveBeenCalled();
});
it("should prevent an illegal mountpoint", function() {
spyOn(arangoHelper, "arangoError");
$("#change-mount-point").val("illegal");
$("#change").click();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
});
}());

View File

@ -3,120 +3,120 @@
/*global spyOn, runs, expect, waitsFor*/
/*global GraphManagementView, _, jasmine, $*/
(function() {
"use strict";
(function () {
"use strict";
describe("Graph Management View", function() {
var view,
div,
modalDiv,
graphs,
collections,
v1, v2, e1, e2, sys1, cols;
beforeEach(function() {
modalDiv = document.createElement("div");
modalDiv.id = "modalPlaceholder";
document.body.appendChild(modalDiv);
window.modalView = new window.ModalView();
collections = new window.arangoCollections(cols);
graphs = new window.GraphCollection();
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
view = new window.GraphManagementView({
collection: graphs
});
});
describe("Graph Management View", function () {
afterEach(function() {
document.body.removeChild(div);
document.body.removeChild(modalDiv);
});
var view,
div,
modalDiv,
graphs,
collections,
v1, v2, e1, e2, sys1, cols;
it("should fetch the graphs on render", function () {
spyOn(graphs, "fetch");
view.render();
expect(graphs.fetch).toHaveBeenCalledWith({async: false});
});
describe("after rendering", function () {
var g1, g2, g3;
beforeEach(function() {
g1 = {
_id: "_graphs/x1",
_key: "x1",
_rev: "123",
vertices: "v1",
edges: "e2"
};
g2 = {
_id: "_graphs/c2",
_key: "c2",
_rev: "321",
vertices: "v2",
edges: "e1"
};
g3 = {
_id: "_graphs/g3",
_key: "g3",
_rev: "111",
vertices: "v3",
edges: "e3"
};
spyOn(graphs, "fetch");
graphs.add(g1);
graphs.add(g2);
graphs.add(g3);
view.render();
});
it("should create a sorted list of all graphs", function() {
var list = $("div.tile h5.collectionName", "#graphManagementThumbnailsIn");
expect(list.length).toEqual(3);
// Order would be g2, g3, g1
expect($(list[0]).html()).toEqual(g2._key);
expect($(list[1]).html()).toEqual(g3._key);
expect($(list[2]).html()).toEqual(g1._key);
});
describe("creating a new graph", function() {
it("should create a new graph", function() {
runs(function() {
$("#createGraph").click();
});
waitsFor(function() {
return $("#modal-dialog").css("display") === "block";
});
runs (function() {
$("#createNewGraphName").val("newGraph");
$("#newGraphVertices").val("newVertices");
$("#newGraphEdges").val("newEdges");
spyOn($, "ajax").andCallFake(function(opts) {
expect(opts.type).toEqual("POST");
expect(opts.url).toEqual("/_api/graph");
expect(opts.data).toEqual(JSON.stringify({
_key: "newGraph",
vertices: "newVertices",
edges: "newEdges",
_id: "",
_rev: ""
}));
beforeEach(function () {
modalDiv = document.createElement("div");
modalDiv.id = "modalPlaceholder";
document.body.appendChild(modalDiv);
window.modalView = new window.ModalView();
collections = new window.arangoCollections(cols);
graphs = new window.GraphCollection();
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
view = new window.GraphManagementView({
collection: graphs
});
$("#modalButton1").click();
expect($.ajax).toHaveBeenCalled();
});
});
});
afterEach(function () {
document.body.removeChild(div);
document.body.removeChild(modalDiv);
});
it("should fetch the graphs on render", function () {
spyOn(graphs, "fetch");
view.render();
expect(graphs.fetch).toHaveBeenCalledWith({async: false});
});
describe("after rendering", function () {
var g1, g2, g3;
beforeEach(function () {
g1 = {
_id: "_graphs/x1",
_key: "x1",
_rev: "123",
vertices: "v1",
edges: "e2"
};
g2 = {
_id: "_graphs/c2",
_key: "c2",
_rev: "321",
vertices: "v2",
edges: "e1"
};
g3 = {
_id: "_graphs/g3",
_key: "g3",
_rev: "111",
vertices: "v3",
edges: "e3"
};
spyOn(graphs, "fetch");
graphs.add(g1);
graphs.add(g2);
graphs.add(g3);
view.render();
});
it("should create a sorted list of all graphs", function () {
var list = $("div.tile h5.collectionName", "#graphManagementThumbnailsIn");
expect(list.length).toEqual(3);
// Order would be g2, g3, g1
expect($(list[0]).html()).toEqual(g2._key);
expect($(list[1]).html()).toEqual(g3._key);
expect($(list[2]).html()).toEqual(g1._key);
});
describe("creating a new graph", function () {
it("should create a new graph", function () {
runs(function () {
$("#createGraph").click();
});
waitsFor(function () {
return $("#modal-dialog").css("display") === "block";
});
runs(function () {
$("#createNewGraphName").val("newGraph");
$("#newGraphVertices").val("newVertices");
$("#newGraphEdges").val("newEdges");
spyOn($, "ajax").andCallFake(function (opts) {
expect(opts.type).toEqual("POST");
expect(opts.url).toEqual("/_api/graph");
expect(opts.data).toEqual(JSON.stringify({
_key: "newGraph",
vertices: "newVertices",
edges: "newEdges",
_id: "",
_rev: ""
}));
});
$("#modalButton1").click();
expect($.ajax).toHaveBeenCalled();
});
});
});
});
});
});
}());

View File

@ -2,228 +2,229 @@
/*global describe, beforeEach, afterEach, it, jasmine*/
/*global spyOn, runs, expect, waitsFor*/
/*global templateEngine, GraphView, _, $*/
(function() {
"use strict";
(function () {
"use strict";
describe("Graph View", function() {
var view,
div;
beforeEach(function() {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
});
describe("Graph View", function () {
afterEach(function() {
document.body.removeChild(div);
});
var view,
div;
it("should render the correct new lines", function () {
spyOn(templateEngine, "createTemplate");
view = new GraphView();
expect(templateEngine.createTemplate).toHaveBeenCalledWith("graphViewGroupByEntry.ejs");
});
describe("after view creation", function() {
var graphs, g1, g2, v1, v2, e1, e2,
myStore, sys1, cols, fakeStartNode;
beforeEach(function() {
var createCol = function(name, type, isSystem) {
return new window.arangoCollectionModel({
id: name,
type: type,
isSystem: isSystem || false,
name: name,
status: "loaded"
});
};
v1 = createCol("z1", "document");
v2 = createCol("a2", "document");
e1 = createCol("y1", "edge");
e2 = createCol("b2", "edge");
sys1 = createCol("_sys1", "document (system)", true);
cols = [sys1, v1, v2, e1, e2];
myStore = new window.arangoCollections(cols);
g1 = {
_id: "_graphs/g1",
_key: "x1",
_rev: "123",
vertices: v1.get("name"),
edges: e2.get("name")
};
g2 = {
_id: "_graphs/g2",
_key: "c2",
_rev: "321",
vertices: v2.get("name"),
edges: e1.get("name")
};
graphs = new window.GraphCollection();
graphs.add(g1);
graphs.add(g2);
spyOn(graphs, "fetch");
spyOn(window, "GraphCollection").andCallFake(function() {
return graphs;
beforeEach(function () {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
});
view = new GraphView({
collection: myStore,
graphs: graphs
afterEach(function () {
document.body.removeChild(div);
});
fakeStartNode = "vertices/123";
spyOn($, "ajax").andCallFake(function(opts) {
if (opts.url === "/_api/simple/any"
&& _.isFunction(opts.success)) {
opts.success({
document: {
_id: fakeStartNode
}
it("should render the correct new lines", function () {
spyOn(templateEngine, "createTemplate");
view = new GraphView();
expect(templateEngine.createTemplate).toHaveBeenCalledWith("graphViewGroupByEntry.ejs");
});
describe("after view creation", function () {
var graphs, g1, g2, v1, v2, e1, e2,
myStore, sys1, cols, fakeStartNode;
beforeEach(function () {
var createCol = function (name, type, isSystem) {
return new window.arangoCollectionModel({
id: name,
type: type,
isSystem: isSystem || false,
name: name,
status: "loaded"
});
};
v1 = createCol("z1", "document");
v2 = createCol("a2", "document");
e1 = createCol("y1", "edge");
e2 = createCol("b2", "edge");
sys1 = createCol("_sys1", "document (system)", true);
cols = [sys1, v1, v2, e1, e2];
myStore = new window.arangoCollections(cols);
g1 = {
_id: "_graphs/g1",
_key: "x1",
_rev: "123",
vertices: v1.get("name"),
edges: e2.get("name")
};
g2 = {
_id: "_graphs/g2",
_key: "c2",
_rev: "321",
vertices: v2.get("name"),
edges: e1.get("name")
};
graphs = new window.GraphCollection();
graphs.add(g1);
graphs.add(g2);
spyOn(graphs, "fetch");
spyOn(window, "GraphCollection").andCallFake(function () {
return graphs;
});
view = new GraphView({
collection: myStore,
graphs: graphs
});
fakeStartNode = "vertices/123";
spyOn($, "ajax").andCallFake(function (opts) {
if (opts.url === "/_api/simple/any"
&& _.isFunction(opts.success)) {
opts.success({
document: {
_id: fakeStartNode
}
});
return;
}
throw "Test not implemented";
});
view.render();
});
return;
}
throw "Test not implemented";
});
view.render();
});
it("should render all vertex collections in correct order", function () {
var list = document.getElementById("nodeCollection"),
childs = list.children;
// v2 should appear before v1
expect(childs[0].value).toEqual(v2.get("name"));
expect(childs[1].value).toEqual(v1.get("name"));
expect(childs.length).toEqual(2);
});
it("should render all vertex collections in correct order", function () {
var list = document.getElementById("nodeCollection"),
childs = list.children;
// v2 should appear before v1
expect(childs[0].value).toEqual(v2.get("name"));
expect(childs[1].value).toEqual(v1.get("name"));
expect(childs.length).toEqual(2);
});
it("should render all edge collections in correct order", function () {
var list = document.getElementById("edgeCollection"),
childs = list.children;
// e2 should appear before e1
expect(childs[0].value).toEqual(e2.get("name"));
expect(childs[1].value).toEqual(e1.get("name"));
expect(childs.length).toEqual(2);
});
it("should render all edge collections in correct order", function () {
var list = document.getElementById("edgeCollection"),
childs = list.children;
// e2 should appear before e1
expect(childs[0].value).toEqual(e2.get("name"));
expect(childs[1].value).toEqual(e1.get("name"));
expect(childs.length).toEqual(2);
});
it("should render all edge collections in correct order", function () {
var list = document.getElementById("graphSelected"),
childs = list.children;
// g2 should appear before g1
expect(childs[0].value).toEqual(g2._key);
expect(childs[1].value).toEqual(g1._key);
expect(childs.length).toEqual(2);
});
it("should render all edge collections in correct order", function () {
var list = document.getElementById("graphSelected"),
childs = list.children;
// g2 should appear before g1
expect(childs[0].value).toEqual(g2._key);
expect(childs[1].value).toEqual(g1._key);
expect(childs.length).toEqual(2);
});
describe("Basic options", function () {
describe("Basic options", function () {
var defaultGVConfig,
defaultAdapterConfig;
var defaultGVConfig,
defaultAdapterConfig;
beforeEach(function () {
defaultGVConfig = {
nodeShaper: {
label: ["_key"],
color: {
type: "attribute",
key: ["_key"]
}
}
};
defaultAdapterConfig = {
type: "arango",
nodeCollection: undefined,
edgeCollection: undefined,
graph: undefined,
undirected: true,
baseUrl: "/_db/_system/"
};
});
it("should load a graph with specific vertices and edges", function () {
$("#nodeCollection").val(v2.get("name"));
$("#edgeCollection").val(e2.get("name"));
$("#useCollections").prop("checked", true);
$("#randomStart").prop("checked", false);
spyOn(window, "GraphViewerUI");
$("#createViewer").click();
// Once load graphs, but never load random node
expect($.ajax).toHaveBeenCalledWith({
cache: false,
type: 'PUT',
url: '/_api/simple/any',
contentType: "application/json",
data: JSON.stringify({collection: v2.get("name")}),
success: jasmine.any(Function)
});
defaultAdapterConfig.nodeCollection = v2.get("name");
defaultAdapterConfig.edgeCollection = e2.get("name");
expect(window.GraphViewerUI).toHaveBeenCalledWith(
$("#content")[0],
defaultAdapterConfig,
$("#content").width() - 75,
680,
defaultGVConfig,
fakeStartNode
);
});
it("should load a graph by name", function () {
$("#graphSelected").val(g2._key);
$("#useGraphs").prop("checked", true);
$("#randomStart").prop("checked", false);
spyOn(window, "GraphViewerUI");
$("#createViewer").click();
// Once load graphs, but never load random node
expect($.ajax).toHaveBeenCalledWith({
cache: false,
type: 'PUT',
url: '/_api/simple/any',
contentType: "application/json",
data: JSON.stringify({collection: g2.vertices}),
success: jasmine.any(Function)
});
defaultAdapterConfig.graph = g2._key;
defaultAdapterConfig.nodeCollection = g2.vertices;
defaultAdapterConfig.edgeCollection = g2.edges;
expect(window.GraphViewerUI).toHaveBeenCalledWith(
$("#content")[0],
defaultAdapterConfig,
$("#content").width() - 75,
680,
defaultGVConfig,
fakeStartNode
);
});
});
describe("Advanced options", function () {
});
describe("Graph Management", function () {
it("should navigate to the management view", function () {
//Simulate the router locally
window.App = {
navigate: function () {
throw "This should be a spy";
}
};
spyOn(window.App, "navigate");
$("#manageGraphs").click();
expect(window.App.navigate).toHaveBeenCalledWith(
"graphManagement", {trigger: true});
delete window.App;
});
});
beforeEach(function() {
defaultGVConfig = {
nodeShaper: {
label: ["_key"],
color: {
type: "attribute",
key: ["_key"]
}
}
};
defaultAdapterConfig = {
type: "arango",
nodeCollection: undefined,
edgeCollection: undefined,
graph: undefined,
undirected: true,
baseUrl: "/_db/_system/"
};
});
it("should load a graph with specific vertices and edges", function() {
$("#nodeCollection").val(v2.get("name"));
$("#edgeCollection").val(e2.get("name"));
$("#useCollections").prop("checked", true);
$("#randomStart").prop("checked", false);
spyOn(window, "GraphViewerUI");
$("#createViewer").click();
// Once load graphs, but never load random node
expect($.ajax).toHaveBeenCalledWith({
cache: false,
type: 'PUT',
url: '/_api/simple/any',
contentType: "application/json",
data: JSON.stringify({collection: v2.get("name")}),
success: jasmine.any(Function)
});
defaultAdapterConfig.nodeCollection = v2.get("name");
defaultAdapterConfig.edgeCollection = e2.get("name");
expect(window.GraphViewerUI).toHaveBeenCalledWith(
$("#content")[0],
defaultAdapterConfig,
$("#content").width() - 75,
680,
defaultGVConfig,
fakeStartNode
);
});
it("should load a graph by name", function() {
$("#graphSelected").val(g2._key);
$("#useGraphs").prop("checked", true);
$("#randomStart").prop("checked", false);
spyOn(window, "GraphViewerUI");
$("#createViewer").click();
// Once load graphs, but never load random node
expect($.ajax).toHaveBeenCalledWith({
cache: false,
type: 'PUT',
url: '/_api/simple/any',
contentType: "application/json",
data: JSON.stringify({collection: g2.vertices}),
success: jasmine.any(Function)
});
defaultAdapterConfig.graph = g2._key;
defaultAdapterConfig.nodeCollection = g2.vertices;
defaultAdapterConfig.edgeCollection = g2.edges;
expect(window.GraphViewerUI).toHaveBeenCalledWith(
$("#content")[0],
defaultAdapterConfig,
$("#content").width() - 75,
680,
defaultGVConfig,
fakeStartNode
);
});
});
describe("Advanced options", function () {
});
describe("Graph Management", function () {
it("should navigate to the management view", function () {
//Simulate the router locally
window.App = {
navigate: function() {
throw "This should be a spy";
}
};
spyOn(window.App, "navigate");
$("#manageGraphs").click();
expect(window.App.navigate).toHaveBeenCalledWith("graphManagement", {trigger: true});
delete window.App;
});
});
});
});
}());

View File

@ -0,0 +1,269 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect, jasmine*/
/*global window, document, hljs, $*/
(function () {
"use strict";
describe("The loginView", function () {
var view;
beforeEach(function () {
window.App = {
navigate: function () {
throw "This should be a spy";
}
};
view = new window.loginView();
expect(view.events).toEqual({
"click #submitLogin": "login",
"keydown #loginUsername": "checkKey",
"keydown #loginPassword": "checkKey"
});
});
afterEach(function () {
delete window.App;
});
it("should render", function () {
view.template = {
render: function () {
}
};
var collectionDummy = {
add: function () {
}
}, jqueryDummy = {
html: function () {
},
hide: function () {
},
focus: function () {
},
val: function () {
}
};
view.collection = collectionDummy;
spyOn(view.template, "render").andReturn(1);
spyOn(collectionDummy, "add");
spyOn(jqueryDummy, "html");
spyOn(jqueryDummy, "hide");
spyOn(jqueryDummy, "focus");
spyOn(jqueryDummy, "val");
spyOn(view, "addDummyUser").andCallThrough();
spyOn(window, "$").andReturn(jqueryDummy);
view.render();
expect(view.collection.add).toHaveBeenCalledWith({
"userName": "admin",
"sessionId": "abc123",
"password": "admin",
"userId": 1
});
expect(window.$).toHaveBeenCalledWith(".header");
expect(window.$).toHaveBeenCalledWith(".footer");
expect(window.$).toHaveBeenCalledWith('#loginUsername');
expect(window.$).toHaveBeenCalledWith('#loginPassword');
expect(jqueryDummy.html).toHaveBeenCalledWith(1);
expect(jqueryDummy.hide).toHaveBeenCalled();
expect(jqueryDummy.focus).toHaveBeenCalled();
expect(jqueryDummy.val).toHaveBeenCalledWith('admin');
expect(view.addDummyUser).toHaveBeenCalled();
expect(view.template.render).toHaveBeenCalledWith({});
});
it("should checkKey", function () {
spyOn(view, "login");
view.checkKey({keyCode: 13});
expect(view.login).toHaveBeenCalled();
});
it("should checkKey with invalid key", function () {
spyOn(view, "login");
view.checkKey({keyCode: 12});
expect(view.login).not.toHaveBeenCalled();
});
it("should login", function () {
var collectionDummy = {
login: function () {
},
loadUserSettings: function () {
}
}, jqueryDummy = {
show: function () {
},
text: function () {
},
val: function () {
}
};
view.collection = collectionDummy;
spyOn(collectionDummy, "login").andReturn(true);
spyOn(collectionDummy, "loadUserSettings");
spyOn(jqueryDummy, "show");
spyOn(jqueryDummy, "text");
spyOn(jqueryDummy, "val").andReturn("someData");
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(window.App, "navigate");
view.login();
expect(view.collection.login).toHaveBeenCalledWith("someData", "someData");
expect(view.collection.loadUserSettings).toHaveBeenCalled();
expect(window.$).toHaveBeenCalledWith(".header");
expect(window.$).toHaveBeenCalledWith(".footer");
expect(window.$).toHaveBeenCalledWith('#loginUsername');
expect(window.$).toHaveBeenCalledWith('#loginPassword');
expect(window.$).toHaveBeenCalledWith('#currentUser');
expect(window.App.navigate).toHaveBeenCalledWith("/", {trigger: true});
expect(jqueryDummy.show).toHaveBeenCalled();
expect(jqueryDummy.text).toHaveBeenCalledWith("someData");
expect(jqueryDummy.val).toHaveBeenCalled();
});
it("should login but fail", function () {
var collectionDummy = {
login: function () {
},
loadUserSettings: function () {
}
}, jqueryDummy = {
show: function () {
},
text: function () {
},
val: function () {
}
};
view.collection = collectionDummy;
spyOn(collectionDummy, "login").andReturn(false);
spyOn(collectionDummy, "loadUserSettings");
spyOn(jqueryDummy, "show");
spyOn(jqueryDummy, "text");
spyOn(jqueryDummy, "val").andReturn("someData");
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(window.App, "navigate");
view.login();
expect(view.collection.login).toHaveBeenCalledWith("someData", "someData");
expect(view.collection.loadUserSettings).not.toHaveBeenCalled();
expect(window.$).toHaveBeenCalledWith('#loginUsername');
expect(window.$).toHaveBeenCalledWith('#loginPassword');
expect(window.App.navigate).not.toHaveBeenCalled();
expect(jqueryDummy.show).not.toHaveBeenCalled();
expect(jqueryDummy.text).not.toHaveBeenCalled();
expect(jqueryDummy.val).toHaveBeenCalled();
});
it("should not login due to mnissing data", function () {
var collectionDummy = {
login: function () {
},
loadUserSettings: function () {
}
}, jqueryDummy = {
show: function () {
},
text: function () {
},
val: function () {
}
};
view.collection = collectionDummy;
spyOn(collectionDummy, "login").andReturn(false);
spyOn(collectionDummy, "loadUserSettings");
spyOn(jqueryDummy, "show");
spyOn(jqueryDummy, "text");
spyOn(jqueryDummy, "val").andReturn("");
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(window.App, "navigate");
view.login();
expect(view.collection.login).not.toHaveBeenCalled();
expect(view.collection.loadUserSettings).not.toHaveBeenCalled();
expect(window.$).toHaveBeenCalledWith('#loginUsername');
expect(window.$).toHaveBeenCalledWith('#loginPassword');
expect(window.App.navigate).not.toHaveBeenCalled();
expect(jqueryDummy.show).not.toHaveBeenCalled();
expect(jqueryDummy.text).not.toHaveBeenCalled();
expect(jqueryDummy.val).toHaveBeenCalled();
});
});
}());

File diff suppressed because it is too large Load Diff

View File

@ -2,287 +2,293 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect, jasmine*/
/*global $*/
(function() {
"use strict";
(function () {
"use strict";
describe("The navigation bar", function() {
describe("The navigation bar", function () {
var div, view, currentDBFake, curName, isSystem,
DBSelectionViewDummy, StatisticBarViewDummy, UserBarViewDummy,
NotificationViewDummy, UserCollectionDummy, oldRouter;
var div, view, currentDBFake, curName, isSystem,
DBSelectionViewDummy, StatisticBarViewDummy, UserBarViewDummy,
NotificationViewDummy, UserCollectionDummy, oldRouter;
beforeEach(function() {
curName = "_system";
isSystem = true;
window.App = {
navigate: function() {
throw "This should be a spy";
}
};
spyOn(window.App, "navigate");
beforeEach(function () {
curName = "_system";
isSystem = true;
window.App = {
navigate: function () {
throw "This should be a spy";
}
};
spyOn(window.App, "navigate");
window.currentDB = window.currentDB || {
get: function() {}
};
window.currentDB = window.currentDB || {
get: function () {
}
};
DBSelectionViewDummy = {
id : "DBSelectionViewDummy",
render : function(){}
};
DBSelectionViewDummy = {
id: "DBSelectionViewDummy",
render: function () {
}
};
UserBarViewDummy = {
id : "UserBarViewDummy",
render : function(){}
};
UserBarViewDummy = {
id: "UserBarViewDummy",
render: function () {
}
};
StatisticBarViewDummy = {
id : "StatisticBarViewDummy",
render : function(){}
};
StatisticBarViewDummy = {
id: "StatisticBarViewDummy",
render: function () {
}
};
NotificationViewDummy = {
id : "NotificationViewDummy",
render : function(){}
};
NotificationViewDummy = {
id: "NotificationViewDummy",
render: function () {
}
};
UserCollectionDummy = {
id : "UserCollectionDummy",
whoAmI : function () {return "root";}
};
UserCollectionDummy = {
id: "UserCollectionDummy",
whoAmI: function () {
return "root";
}
};
spyOn(window, "UserBarView").andReturn(UserBarViewDummy);
spyOn(window, "StatisticBarView").andReturn(StatisticBarViewDummy);
spyOn(window, "DBSelectionView").andReturn(DBSelectionViewDummy);
spyOn(window, "NotificationView").andReturn(NotificationViewDummy);
spyOn(window.currentDB, "get").andCallFake(function(key) {
if (key === "name") {
return curName;
}
if (key === "isSystem") {
return isSystem;
}
expect(true).toBeFalsy();
});
div = document.createElement("div");
div.id = "navigationBar";
document.body.appendChild(div);
});
afterEach(function() {
document.body.removeChild(div);
delete window.App;
});
describe("in any database", function() {
beforeEach(function() {
view = new window.NavigationView(
{userCollection : UserCollectionDummy, currentDB : window.currentDB}
);
view.render();
});
it("should offer a collections tab", function() {
var tab = $("#collections", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("collections", {trigger: true});
});
it("should offer a applications tab", function() {
var tab = $("#applications", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("applications", {trigger: true});
});
it("should offer a graph tab", function() {
var tab = $("#graph", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("graph", {trigger: true});
});
it("should offer an aql editor tab", function() {
var tab = $("#query", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("query", {trigger: true});
});
it("should offer an api tab", function() {
var tab = $("#api", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("api", {trigger: true});
});
it("should offer a graph tab", function() {
var tab = $("#graph", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("graph", {trigger: true});
});
it("should handle selected database render", function() {
spyOn(view.dbSelectionView, "render");
view.handleSelectDatabase();
expect(view.dbSelectionView.render).toHaveBeenCalled();
});
it("should navigate to the selected value from options div", function() {
var toNavigate = "#collections";
$("#arangoCollectionSelect").val(toNavigate);
view.navigateBySelect();
expect(window.App.navigate).toHaveBeenCalledWith(toNavigate, {trigger: true});
});
it("should navigate automatic to the selected value from options div", function() {
spyOn($.fn, "change").andCallFake(function(a){
a();
spyOn(window, "UserBarView").andReturn(UserBarViewDummy);
spyOn(window, "StatisticBarView").andReturn(StatisticBarViewDummy);
spyOn(window, "DBSelectionView").andReturn(DBSelectionViewDummy);
spyOn(window, "NotificationView").andReturn(NotificationViewDummy);
spyOn(window.currentDB, "get").andCallFake(function (key) {
if (key === "name") {
return curName;
}
if (key === "isSystem") {
return isSystem;
}
expect(true).toBeFalsy();
});
div = document.createElement("div");
div.id = "navigationBar";
document.body.appendChild(div);
});
spyOn(view, "navigateBySelect");
view.handleSelectNavigation();
expect($.fn.change).toHaveBeenCalledWith(jasmine.any(Function));
expect(view.navigateBySelect).toHaveBeenCalled();
});
it("should render selectMenuItems correctly", function() {
var entry = "tools-menu",
toBeActiveClass = $('.' + entry),
toBeFalseClass1 = $('.' + "graphviewer-menu"),
toBeFalseClass2 = $('.' + "databases-menu"),
toBeFalseClass3 = $('.' + "query-menu"),
toBeFalseClass4 = $('.' + "collections-menu"),
toBeFalseClass5 = $('.' + "applications-menu");
view.selectMenuItem(entry);
expect(toBeActiveClass.hasClass("active")).toBeTruthy();
expect(toBeFalseClass1.hasClass("active")).toBeFalsy();
expect(toBeFalseClass2.hasClass("active")).toBeFalsy();
expect(toBeFalseClass3.hasClass("active")).toBeFalsy();
expect(toBeFalseClass4.hasClass("active")).toBeFalsy();
expect(toBeFalseClass5.hasClass("active")).toBeFalsy();
});
afterEach(function () {
document.body.removeChild(div);
delete window.App;
});
it("should show dropdown for menu item: links", function() {
var e = {
target: {
id: "links"
}
};
spyOn($.fn, "show");
view.showDropdown(e);
expect($.fn.show).toHaveBeenCalledWith(200);
});
describe("in any database", function () {
it("should show dropdown for menu item: tools", function() {
var e = {
target: {
id: "tools"
}
};
spyOn($.fn, "show");
view.showDropdown(e);
expect($.fn.show).toHaveBeenCalledWith(200);
});
beforeEach(function () {
view = new window.NavigationView(
{userCollection: UserCollectionDummy, currentDB: window.currentDB}
);
view.render();
});
it("should show dropdown for menu item: dbselection", function() {
var e = {
target: {
id: "dbselection"
}
};
spyOn($.fn, "show");
view.showDropdown(e);
expect($.fn.show).toHaveBeenCalledWith(200);
});
it("should offer a collections tab", function () {
var tab = $("#collections", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("collections", {trigger: true});
});
it("should hide dropdown for menu item: linkDropdown", function() {
spyOn($.fn, "hide");
$('#linkDropdown').mouseenter().mouseleave();
expect($.fn.hide).toHaveBeenCalled();
});
it("should offer a applications tab", function () {
var tab = $("#applications", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("applications", {trigger: true});
});
it("should hide dropdown for menu item: toolsDropdown", function() {
spyOn($.fn, "hide");
$('#toolsDropdown').mouseenter().mouseleave();
expect($.fn.hide).toHaveBeenCalled();
});
it("should offer a graph tab", function () {
var tab = $("#graph", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("graph", {trigger: true});
});
it("should hide dropdown for menu item: dbSelect", function() {
spyOn($.fn, "hide");
$('#dbSelect').mouseenter().mouseleave();
expect($.fn.hide).toHaveBeenCalled();
});
it("should offer an aql editor tab", function () {
var tab = $("#query", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("query", {trigger: true});
});
it("should navigateByTab: tools", function() {
spyOn($.fn, "slideToggle");
$('#tools').click();
expect($.fn.slideToggle).toHaveBeenCalled();
});
it("should offer an api tab", function () {
var tab = $("#api", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("api", {trigger: true});
});
it("should navigateByTab: links", function() {
spyOn($.fn, "slideToggle");
$('#links').click();
expect($.fn.slideToggle).toHaveBeenCalled();
});
it("should navigateByTab: dbSelection", function() {
$('#tools').attr("id", "dbselection");
spyOn($.fn, "slideToggle");
$('#dbselection').click();
expect($.fn.slideToggle).toHaveBeenCalled();
$('#dbselection').attr("id", "tools");
});
it("should offer a graph tab", function () {
var tab = $("#graph", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("graph", {trigger: true});
});
it("should navigateByTab: blank", function() {
$('#tools').attr("id", "");
$('#links').attr("id", "");
spyOn($.fn, "attr");
$('.tab').click();
expect($.fn.attr).toHaveBeenCalled();
});
it("should handle selected database render", function () {
spyOn(view.dbSelectionView, "render");
view.handleSelectDatabase();
expect(view.dbSelectionView.render).toHaveBeenCalled();
});
it("should navigate to the selected value from options div", function () {
var toNavigate = "#collections";
$("#arangoCollectionSelect").val(toNavigate);
view.navigateBySelect();
expect(window.App.navigate).toHaveBeenCalledWith(toNavigate, {trigger: true});
});
it("should navigate automatic to the selected value from options div", function () {
spyOn($.fn, "change").andCallFake(function (a) {
a();
});
spyOn(view, "navigateBySelect");
view.handleSelectNavigation();
expect($.fn.change).toHaveBeenCalledWith(jasmine.any(Function));
expect(view.navigateBySelect).toHaveBeenCalled();
});
it("should render selectMenuItems correctly", function () {
var entry = "tools-menu",
toBeActiveClass = $('.' + entry),
toBeFalseClass1 = $('.' + "graphviewer-menu"),
toBeFalseClass2 = $('.' + "databases-menu"),
toBeFalseClass3 = $('.' + "query-menu"),
toBeFalseClass4 = $('.' + "collections-menu"),
toBeFalseClass5 = $('.' + "applications-menu");
view.selectMenuItem(entry);
expect(toBeActiveClass.hasClass("active")).toBeTruthy();
expect(toBeFalseClass1.hasClass("active")).toBeFalsy();
expect(toBeFalseClass2.hasClass("active")).toBeFalsy();
expect(toBeFalseClass3.hasClass("active")).toBeFalsy();
expect(toBeFalseClass4.hasClass("active")).toBeFalsy();
expect(toBeFalseClass5.hasClass("active")).toBeFalsy();
});
it("should show dropdown for menu item: links", function () {
var e = {
target: {
id: "links"
}
};
spyOn($.fn, "show");
view.showDropdown(e);
expect($.fn.show).toHaveBeenCalledWith(200);
});
it("should show dropdown for menu item: tools", function () {
var e = {
target: {
id: "tools"
}
};
spyOn($.fn, "show");
view.showDropdown(e);
expect($.fn.show).toHaveBeenCalledWith(200);
});
it("should show dropdown for menu item: dbselection", function () {
var e = {
target: {
id: "dbselection"
}
};
spyOn($.fn, "show");
view.showDropdown(e);
expect($.fn.show).toHaveBeenCalledWith(200);
});
it("should hide dropdown for menu item: linkDropdown", function () {
spyOn($.fn, "hide");
$('#linkDropdown').mouseenter().mouseleave();
expect($.fn.hide).toHaveBeenCalled();
});
it("should hide dropdown for menu item: toolsDropdown", function () {
spyOn($.fn, "hide");
$('#toolsDropdown').mouseenter().mouseleave();
expect($.fn.hide).toHaveBeenCalled();
});
it("should hide dropdown for menu item: dbSelect", function () {
spyOn($.fn, "hide");
$('#dbSelect').mouseenter().mouseleave();
expect($.fn.hide).toHaveBeenCalled();
});
it("should navigateByTab: tools", function () {
spyOn($.fn, "slideToggle");
$('#tools').click();
expect($.fn.slideToggle).toHaveBeenCalled();
});
it("should navigateByTab: links", function () {
spyOn($.fn, "slideToggle");
$('#links').click();
expect($.fn.slideToggle).toHaveBeenCalled();
});
it("should navigateByTab: dbSelection", function () {
$('#tools').attr("id", "dbselection");
spyOn($.fn, "slideToggle");
$('#dbselection').click();
expect($.fn.slideToggle).toHaveBeenCalled();
$('#dbselection').attr("id", "tools");
});
it("should navigateByTab: blank", function () {
$('#tools').attr("id", "");
$('#links').attr("id", "");
spyOn($.fn, "attr");
$('.tab').click();
expect($.fn.attr).toHaveBeenCalled();
});
});
describe("in _system database", function () {
beforeEach(function () {
view = new window.NavigationView(
{userCollection: UserCollectionDummy, currentDB: window.currentDB}
);
view.render();
});
it("should offer a logs tab", function () {
var tab = $("#logs", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("logs", {trigger: true});
});
});
describe("in a not _system database", function () {
beforeEach(function () {
curName = "firstDB";
isSystem = false;
view = new window.NavigationView(
{userCollection: UserCollectionDummy, currentDB: window.currentDB}
);
view.render();
});
it("should not offer a logs tab", function () {
var tab = $("#logs", $(div));
expect(tab.length).toEqual(0);
});
});
});
describe("in _system database", function() {
beforeEach(function() {
view = new window.NavigationView(
{userCollection : UserCollectionDummy, currentDB : window.currentDB}
);
view.render();
});
it("should offer a logs tab", function() {
var tab = $("#logs", $(div));
expect(tab.length).toEqual(1);
tab.click();
expect(window.App.navigate).toHaveBeenCalledWith("logs", {trigger: true});
});
});
describe("in a not _system database", function() {
beforeEach(function() {
curName = "firstDB";
isSystem = false;
view = new window.NavigationView(
{userCollection : UserCollectionDummy, currentDB : window.currentDB}
);
view.render();
});
it("should not offer a logs tab", function() {
var tab = $("#logs", $(div));
expect(tab.length).toEqual(0);
});
});
});
}());

View File

@ -2,131 +2,131 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $*/
(function() {
"use strict";
(function () {
"use strict";
describe("The new logs view", function() {
describe("The new logs view", function () {
var view, allLogs, debugLogs, infoLogs, warnLogs, errLogs, div, fakeCall;
var view, allLogs, debugLogs, infoLogs, warnLogs, errLogs, div, fakeCall;
beforeEach(function() {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
allLogs = new window.ArangoLogs(
{upto: true, loglevel: 4}
);
debugLogs = new window.ArangoLogs(
{loglevel: 4}
);
infoLogs = new window.ArangoLogs(
{loglevel: 3}
);
warnLogs = new window.ArangoLogs(
{loglevel: 2}
);
errLogs = new window.ArangoLogs(
{loglevel: 1}
);
beforeEach(function () {
div = document.createElement("div");
div.id = "content";
document.body.appendChild(div);
allLogs = new window.ArangoLogs(
{upto: true, loglevel: 4}
);
debugLogs = new window.ArangoLogs(
{loglevel: 4}
);
infoLogs = new window.ArangoLogs(
{loglevel: 3}
);
warnLogs = new window.ArangoLogs(
{loglevel: 2}
);
errLogs = new window.ArangoLogs(
{loglevel: 1}
);
fakeCall = function() {
return;
};
fakeCall = function () {
return;
};
spyOn(allLogs, "fetch").andCallFake(function(options) {
return fakeCall(options);
});
spyOn(allLogs, "fetch").andCallFake(function (options) {
return fakeCall(options);
});
view = new window.LogsView({
logall: allLogs,
logdebug: debugLogs,
loginfo: infoLogs,
logwarning: warnLogs,
logerror: errLogs
});
view = new window.LogsView({
logall: allLogs,
logdebug: debugLogs,
loginfo: infoLogs,
logwarning: warnLogs,
logerror: errLogs
});
expect(allLogs.fetch).toHaveBeenCalled();
view.render();
});
afterEach(function () {
document.body.removeChild(div);
});
it("assert basics", function () {
expect(view.currentLoglevel).toEqual("logall");
expect(view.id).toEqual("#logContent");
expect(view.events).toEqual({
"click #arangoLogTabbar button": "setActiveLoglevel",
"click #logTable_first": "firstPage",
"click #logTable_last": "lastPage"
});
expect(view.tabbarElements).toEqual({
id: "arangoLogTabbar",
titles: [
["Debug", "logdebug"],
["Warning", "logwarning"],
["Error", "logerror"],
["Info", "loginfo"],
["All", "logall"]
]
});
expect(view.tableDescription).toEqual({
id: "arangoLogTable",
titles: ["Loglevel", "Date", "Message"],
rows: []
});
});
it("check set not same active log level function", function () {
var button = {
currentTarget: {
id: "logdebug"
}
};
spyOn(view, "convertModelToJSON");
view.setActiveLoglevel(button);
expect(view.convertModelToJSON).toHaveBeenCalled();
expect(view.currentLoglevel).toBe(button.currentTarget.id);
});
it("check set same active log level function", function () {
var button = {
currentTarget: {
id: "logall"
}
};
spyOn(view, "convertModelToJSON");
view.setActiveLoglevel(button);
expect(view.convertModelToJSON).not.toHaveBeenCalled();
expect(view.currentLoglevel).toBe(button.currentTarget.id);
});
it("check set active log level to loginfo", function () {
allLogs.fetch.reset();
spyOn(infoLogs, "fetch");
$("#loginfo").click();
expect(infoLogs.fetch).toHaveBeenCalled();
expect(allLogs.fetch).not.toHaveBeenCalled();
});
it("check set checkModelToJSON function", function () {
spyOn(view, "render");
fakeCall = function (options) {
return options.success();
};
view.convertModelToJSON();
expect(view.render).toHaveBeenCalled();
});
it("check rerender function", function () {
spyOn(view, "convertModelToJSON");
view.rerender();
expect(view.convertModelToJSON).toHaveBeenCalled();
});
expect(allLogs.fetch).toHaveBeenCalled();
view.render();
});
afterEach(function() {
document.body.removeChild(div);
});
it("assert basics", function () {
expect(view.currentLoglevel).toEqual("logall");
expect(view.id).toEqual("#logContent");
expect(view.events).toEqual({
"click #arangoLogTabbar button" : "setActiveLoglevel",
"click #logTable_first" : "firstPage",
"click #logTable_last" : "lastPage"
});
expect(view.tabbarElements).toEqual({
id: "arangoLogTabbar",
titles: [
["Debug", "logdebug"],
["Warning", "logwarning"],
["Error", "logerror"],
["Info", "loginfo"],
["All", "logall"]
]
});
expect(view.tableDescription).toEqual({
id: "arangoLogTable",
titles: ["Loglevel", "Date", "Message"],
rows: []
});
});
it("check set not same active log level function", function () {
var button = {
currentTarget: {
id: "logdebug"
}
};
spyOn(view, "convertModelToJSON");
view.setActiveLoglevel(button);
expect(view.convertModelToJSON).toHaveBeenCalled();
expect(view.currentLoglevel).toBe(button.currentTarget.id);
});
it("check set same active log level function", function () {
var button = {
currentTarget: {
id: "logall"
}
};
spyOn(view, "convertModelToJSON");
view.setActiveLoglevel(button);
expect(view.convertModelToJSON).not.toHaveBeenCalled();
expect(view.currentLoglevel).toBe(button.currentTarget.id);
});
it("check set active log level to loginfo", function () {
allLogs.fetch.reset();
spyOn(infoLogs, "fetch");
$("#loginfo").click();
expect(infoLogs.fetch).toHaveBeenCalled();
expect(allLogs.fetch).not.toHaveBeenCalled();
});
it("check set checkModelToJSON function", function() {
spyOn(view, "render");
fakeCall = function(options) {
return options.success();
};
view.convertModelToJSON();
expect(view.render).toHaveBeenCalled();
});
it("check rerender function", function() {
spyOn(view, "convertModelToJSON");
view.rerender();
expect(view.convertModelToJSON).toHaveBeenCalled();
});
});
}());

View File

@ -2,179 +2,178 @@
/*global describe, beforeEach, afterEach, it, spyOn, expect*/
/*global $*/
(function() {
"use strict";
(function () {
"use strict";
describe("The notification view", function() {
describe("The notification view", function () {
var view, div, div2, fakeNotification, dummyCollection, jQueryDummy;
var view, div, div2, fakeNotification, dummyCollection, jQueryDummy;
beforeEach(function() {
div = document.createElement("div");
div.id = "navigationBar";
div2 = document.createElement("div");
div2.id = "notificationBar";
document.body.appendChild(div);
document.body.appendChild(div2);
beforeEach(function () {
div = document.createElement("div");
div.id = "navigationBar";
div2 = document.createElement("div");
div2.id = "notificationBar";
document.body.appendChild(div);
document.body.appendChild(div2);
dummyCollection = new window.NotificationCollection();
dummyCollection = new window.NotificationCollection();
fakeNotification = {
title: "Hallo",
date: 1398239658,
content: "",
priority: "",
tags: "",
seen: false
};
fakeNotification = {
title: "Hallo",
date: 1398239658,
content: "",
priority: "",
tags: "",
seen: false
};
view = new window.NotificationView({
collection: dummyCollection
});
view.render();
});
afterEach(function () {
document.body.removeChild(div);
document.body.removeChild(div2);
});
it("assert basics", function () {
expect(view.events).toEqual({
"click .navlogo #stat_hd": "toggleNotification",
"click .notificationItem .fa": "removeNotification",
"click #removeAllNotifications": "removeAllNotifications"
});
});
it("toggleNotification should run function", function () {
jQueryDummy = {
toggle: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "toggle");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.toggleNotification();
expect(jQueryDummy.toggle).not.toHaveBeenCalled();
});
it("toggleNotification should run function", function () {
view.collection.add(fakeNotification);
jQueryDummy = {
toggle: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "toggle");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.toggleNotification();
expect(jQueryDummy.toggle).toHaveBeenCalled();
});
it("toggleNotification should run function", function () {
spyOn(view.collection, "reset");
view.removeAllNotifications();
expect(view.collection.reset).toHaveBeenCalled();
expect($('#notification_menu').is(":visible")).toBeFalsy();
});
it("renderNotifications function with collection length 0", function () {
jQueryDummy = {
html: function () {
throw "Should be a spy";
},
text: function () {
throw "Should be a spy";
},
removeClass: function () {
throw "Should be a spy";
},
hide: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "html");
spyOn(jQueryDummy, "text");
spyOn(jQueryDummy, "removeClass");
spyOn(jQueryDummy, "hide");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.renderNotifications();
expect(jQueryDummy.text).toHaveBeenCalled();
expect(jQueryDummy.removeClass).toHaveBeenCalled();
expect(jQueryDummy.hide).toHaveBeenCalled();
expect(jQueryDummy.html).toHaveBeenCalled();
});
it("renderNotifications function with collection length > 0", function () {
view.collection.add(fakeNotification);
jQueryDummy = {
html: function () {
throw "Should be a spy";
},
text: function () {
throw "Should be a spy";
},
addClass: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "html");
spyOn(jQueryDummy, "text");
spyOn(jQueryDummy, "addClass");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.renderNotifications();
expect(jQueryDummy.text).toHaveBeenCalled();
expect(jQueryDummy.addClass).toHaveBeenCalled();
expect(jQueryDummy.html).toHaveBeenCalled();
});
it("remove a single notification", function () {
view.render();
view.collection.add(fakeNotification);
view.collection.add(fakeNotification);
view.collection.add(fakeNotification);
var firstModel = view.collection.first(),
getDummy = {
destroy: function () {
throw "Should be a spy";
}
};
spyOn(getDummy, "destroy");
spyOn(view.collection, "get").andReturn(
getDummy
);
$('#stat_hd').click();
$('#' + firstModel.cid).click();
expect(getDummy.destroy).toHaveBeenCalled();
});
view = new window.NotificationView({
collection: dummyCollection
});
view.render();
});
afterEach(function() {
document.body.removeChild(div);
document.body.removeChild(div2);
});
it("assert basics", function () {
expect(view.events).toEqual({
"click .navlogo #stat_hd" : "toggleNotification",
"click .notificationItem .fa" : "removeNotification",
"click #removeAllNotifications" : "removeAllNotifications"
});
});
it("toggleNotification should run function", function () {
jQueryDummy = {
toggle: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "toggle");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.toggleNotification();
expect(jQueryDummy.toggle).not.toHaveBeenCalled();
});
it("toggleNotification should run function", function () {
view.collection.add(fakeNotification);
jQueryDummy = {
toggle: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "toggle");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.toggleNotification();
expect(jQueryDummy.toggle).toHaveBeenCalled();
});
it("toggleNotification should run function", function () {
spyOn(view.collection, "reset");
view.removeAllNotifications();
expect(view.collection.reset).toHaveBeenCalled();
expect($('#notification_menu').is(":visible")).toBeFalsy();
});
it("renderNotifications function with collection length 0", function () {
jQueryDummy = {
html: function () {
throw "Should be a spy";
},
text: function () {
throw "Should be a spy";
},
removeClass: function() {
throw "Should be a spy";
},
hide: function () {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "html");
spyOn(jQueryDummy, "text");
spyOn(jQueryDummy, "removeClass");
spyOn(jQueryDummy, "hide");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.renderNotifications();
expect(jQueryDummy.text).toHaveBeenCalled();
expect(jQueryDummy.removeClass).toHaveBeenCalled();
expect(jQueryDummy.hide).toHaveBeenCalled();
expect(jQueryDummy.html).toHaveBeenCalled();
});
it("renderNotifications function with collection length > 0", function () {
view.collection.add(fakeNotification);
jQueryDummy = {
html: function () {
throw "Should be a spy";
},
text: function () {
throw "Should be a spy";
},
addClass: function() {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "html");
spyOn(jQueryDummy, "text");
spyOn(jQueryDummy, "addClass");
spyOn(window, "$").andReturn(
jQueryDummy
);
view.renderNotifications();
expect(jQueryDummy.text).toHaveBeenCalled();
expect(jQueryDummy.addClass).toHaveBeenCalled();
expect(jQueryDummy.html).toHaveBeenCalled();
});
it("remove a single notification", function () {
view.render();
view.collection.add(fakeNotification);
view.collection.add(fakeNotification);
view.collection.add(fakeNotification);
var firstModel = view.collection.first(),
getDummy = {
destroy: function() {
throw "Should be a spy";
}
};
spyOn(getDummy, "destroy");
spyOn(view.collection, "get").andReturn(
getDummy
);
$('#stat_hd').click();
$('#'+firstModel.cid).click();
expect(getDummy.destroy).toHaveBeenCalled();
});
});
}());

View File

@ -0,0 +1,188 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect, jasmine*/
/*global window, document, hljs, $*/
(function () {
"use strict";
describe("The StatisticBarView", function () {
var view;
beforeEach(function () {
window.App = {
navigate: function () {
throw "This should be a spy";
}
};
view = new window.StatisticBarView(
{
currentDB: {
get: function () {
return true;
}
}
});
expect(view.events).toEqual({
"change #arangoCollectionSelect": "navigateBySelect",
"click .tab": "navigateByTab"
});
});
afterEach(function () {
delete window.App;
});
it("should render", function () {
view.template = {
render: function () {
}
};
spyOn(view.template, "render").andReturn(1);
spyOn($.fn, "html");
spyOn($.fn, "find").andCallThrough();
spyOn($.fn, "attr").andCallThrough();
spyOn($.fn, "each").andCallFake(function (a) {
a();
});
spyOn($, "get").andCallFake(function (a, b, c) {
b();
});
view.render();
expect($.fn.html).toHaveBeenCalledWith(1);
expect($.fn.find).toHaveBeenCalledWith('svg');
expect($.fn.attr).toHaveBeenCalledWith('id');
expect($.fn.attr).toHaveBeenCalledWith('class');
expect($.fn.attr).toHaveBeenCalledWith('src');
expect(view.template.render).toHaveBeenCalledWith({
isSystem: true
});
});
it("should navigateBySelect", function () {
var jquerDummy = {
find: function () {
return jquerDummy;
},
val: function () {
return "bla";
}
};
spyOn(jquerDummy, "find").andCallThrough();
spyOn(jquerDummy, "val").andCallThrough();
spyOn(window, "$").andReturn(jquerDummy);
spyOn(window.App, "navigate");
view.navigateBySelect();
expect(window.$).toHaveBeenCalledWith("#arangoCollectionSelect");
expect(jquerDummy.find).toHaveBeenCalledWith("option:selected");
expect(jquerDummy.val).toHaveBeenCalled();
expect(window.App.navigate).toHaveBeenCalledWith("bla", {trigger: true});
});
it("should navigateByTab", function () {
var p = {
srcElement: {id: "bla"},
preventDefault: function () {
}
};
spyOn(window.App, "navigate");
spyOn(p, "preventDefault");
view.navigateByTab(p);
expect(p.preventDefault).toHaveBeenCalled();
expect(window.App.navigate).toHaveBeenCalledWith("bla", {trigger: true});
});
it("should navigateByTab to links", function () {
var p = {
srcElement: {id: "links"},
preventDefault: function () {
}
};
spyOn(window.App, "navigate");
spyOn(p, "preventDefault");
view.navigateByTab(p);
expect(p.preventDefault).toHaveBeenCalled();
expect(window.App.navigate).not.toHaveBeenCalled();
});
it("should navigateByTab to tools", function () {
var p = {
srcElement: {id: "tools"},
preventDefault: function () {
}
};
spyOn(p, "preventDefault");
view.navigateByTab(p);
expect(p.preventDefault).toHaveBeenCalled();
});
it("should handleSelectNavigation", function () {
var jQueryDummy = {
change: function () {
},
find: function () {
return jQueryDummy;
},
val: function () {
}
};
spyOn(window, "$").andReturn(jQueryDummy);
spyOn(window.App, "navigate");
spyOn(jQueryDummy, "val").andReturn("bla");
spyOn(jQueryDummy, "find").andCallThrough();
spyOn(jQueryDummy, "change").andCallFake(function (a) {
a();
});
view.handleSelectNavigation();
expect(window.$).toHaveBeenCalledWith("#arangoCollectionSelect");
expect(jQueryDummy.find).toHaveBeenCalledWith("option:selected");
expect(jQueryDummy.change).toHaveBeenCalled();
expect(jQueryDummy.val).toHaveBeenCalled();
expect(window.App.navigate).toHaveBeenCalledWith("bla", {trigger: true});
});
it("should selectMenuItem", function () {
var jQueryDummy = {
removeClass: function () {
},
addClass: function () {
}
};
spyOn(window, "$").andReturn(jQueryDummy);
spyOn(jQueryDummy, "removeClass");
spyOn(jQueryDummy, "addClass");
view.selectMenuItem("mm");
expect(window.$).toHaveBeenCalledWith('.navlist li');
expect(window.$).toHaveBeenCalledWith(".mm");
expect(jQueryDummy.removeClass).toHaveBeenCalledWith('active');
expect(jQueryDummy.addClass).toHaveBeenCalledWith('active');
});
});
}());

View File

@ -0,0 +1,315 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect, jasmine*/
/*global window, document, hljs, $*/
(function () {
"use strict";
describe("The loginView", function () {
var view, collectionDummy;
beforeEach(function () {
window.App = {
navigate: function () {
throw "This should be a spy";
}
};
collectionDummy = {
fetch: function () {
},
bind: function () {
},
whoAmI: function () {
},
logout: function () {
},
findWhere : function () {
}
};
spyOn(collectionDummy, "fetch");
spyOn(collectionDummy, "bind");
view = new window.UserBarView({userCollection: collectionDummy});
expect(collectionDummy.fetch).toHaveBeenCalledWith({async: false});
expect(collectionDummy.bind).toHaveBeenCalled();
expect(view.events).toEqual({
"change #userBarSelect": "navigateBySelect",
"click .tab": "navigateByTab",
"mouseenter .dropdown": "showDropdown",
"mouseleave .dropdown": "hideDropdown",
"click #userLogout": "userLogout"
});
});
afterEach(function () {
delete window.App;
});
it("should navigateBySelect", function () {
var jquerDummy = {
find: function () {
return jquerDummy;
},
val: function () {
return "bla";
}
};
spyOn(jquerDummy, "find").andCallThrough();
spyOn(jquerDummy, "val").andCallThrough();
spyOn(window, "$").andReturn(jquerDummy);
spyOn(window.App, "navigate");
view.navigateBySelect();
expect(window.$).toHaveBeenCalledWith("#arangoCollectionSelect");
expect(jquerDummy.find).toHaveBeenCalledWith("option:selected");
expect(jquerDummy.val).toHaveBeenCalled();
expect(window.App.navigate).toHaveBeenCalledWith("bla", {trigger: true});
});
it("should navigateByTab", function () {
var p = {
srcElement: {id: "bla"},
preventDefault: function () {
}
},jqueryDummy = {
closest : function () {
return jqueryDummy;
},
attr : function () {
},
slideToggle : function () {
}
};
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(jqueryDummy, "closest").andCallThrough();
spyOn(jqueryDummy, "attr").andReturn("bla");
spyOn(window.App, "navigate");
spyOn(p, "preventDefault");
view.navigateByTab(p);
expect (window.$).toHaveBeenCalledWith({id: "bla"});
expect (jqueryDummy.closest).toHaveBeenCalledWith("a");
expect (jqueryDummy.attr).toHaveBeenCalledWith("id");
expect(p.preventDefault).toHaveBeenCalled();
expect(window.App.navigate).toHaveBeenCalledWith("bla", {trigger: true});
});
it("should navigateByTab to links", function () {
var p = {
srcElement: {id: "user"},
preventDefault: function () {
}
},jqueryDummy = {
closest : function () {
return jqueryDummy;
},
attr : function () {
},
slideToggle : function () {
}
};
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(jqueryDummy, "closest").andCallThrough();
spyOn(jqueryDummy, "attr").andReturn("user");
spyOn(jqueryDummy, "slideToggle");
spyOn(window.App, "navigate");
spyOn(p, "preventDefault");
view.navigateByTab(p);
expect (window.$).toHaveBeenCalledWith({id: "user"});
expect (jqueryDummy.closest).toHaveBeenCalledWith("a");
expect (jqueryDummy.slideToggle).toHaveBeenCalledWith(200);
expect (jqueryDummy.attr).toHaveBeenCalledWith("id");
expect(p.preventDefault).toHaveBeenCalled();
expect(window.App.navigate).not.toHaveBeenCalled();
});
it("should navigateByTab to links", function () {
var p = {
srcElement: {id: "user"}
},jqueryDummy = {
show : function () {
}
};
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(jqueryDummy, "show");
view.showDropdown(p);
expect (window.$).toHaveBeenCalledWith("#user_dropdown");
expect (jqueryDummy.show).toHaveBeenCalledWith(200);
});
it("should hideDropdown", function () {
var jqueryDummy = {
hide : function () {
}
};
spyOn(window, "$").andReturn(jqueryDummy);
spyOn(jqueryDummy, "hide");
view.hideDropdown();
expect (window.$).toHaveBeenCalledWith("#user_dropdown");
expect (jqueryDummy.hide).toHaveBeenCalled();
});
it("should userLogout", function () {
spyOn(collectionDummy, "whoAmI");
spyOn(collectionDummy, "logout");
view.userLogout();
expect (collectionDummy.whoAmI).toHaveBeenCalled();
expect (collectionDummy.logout).toHaveBeenCalled();
});
it("should render", function () {
view.template = {
render: function () {
}
};
var userDummy = {
set : function () {
},
get : function () {
}
};
spyOn(collectionDummy, "whoAmI").andReturn("userName");
spyOn(collectionDummy, "findWhere").andReturn(userDummy);
spyOn(userDummy, "set");
spyOn(userDummy, "get").andCallFake(function (a) {
if (a === "active") {
return true;
}
return {
img : undefined,
name : undefined
};
});
spyOn(view.template, "render").andReturn(1);
view.render();
expect (userDummy.set).toHaveBeenCalledWith({loggedIn : true});
expect (userDummy.get).toHaveBeenCalledWith("extra");
expect (userDummy.get).toHaveBeenCalledWith("active");
expect (collectionDummy.whoAmI).toHaveBeenCalled();
expect (collectionDummy.findWhere).toHaveBeenCalledWith({user: "userName"});
expect(view.template.render).toHaveBeenCalledWith({
img : "img/arangodblogoAvatar_24.png",
name : "",
username : "userName",
active : true
});
});
it("should render with image", function () {
view.template = {
render: function () {
}
};
var userDummy = {
set : function () {
},
get : function () {
}
};
spyOn(collectionDummy, "whoAmI").andReturn("userName");
spyOn(collectionDummy, "findWhere").andReturn(userDummy);
spyOn(userDummy, "set");
spyOn(userDummy, "get").andCallFake(function (a) {
if (a === "active") {
return true;
}
return {
img : "bla",
name : "name"
};
});
spyOn(view.template, "render").andReturn(1);
view.render();
expect (userDummy.set).toHaveBeenCalledWith({loggedIn : true});
expect (userDummy.get).toHaveBeenCalledWith("extra");
expect (userDummy.get).toHaveBeenCalledWith("active");
expect (collectionDummy.whoAmI).toHaveBeenCalled();
expect (collectionDummy.findWhere).toHaveBeenCalledWith({user: "userName"});
expect(view.template.render).toHaveBeenCalledWith({
img : "https://s.gravatar.com/avatar/bla?s=24",
name : "name",
username : "userName",
active : true
});
});
});
}());

View File

@ -114,6 +114,17 @@ function getAuthorization (dispatcher) {
return getAuthorizationHeader(dispatcher.username, dispatcher.passwd);
}
function endpointToURL (endpoint) {
if (endpoint.substr(0,6) === "ssl://") {
return "https://" + endpoint.substr(6);
}
var pos = endpoint.indexOf("://");
if (pos === -1) {
return "http://" + endpoint;
}
return "http" + endpoint.substr(pos);
}
PortFinder.prototype.next = function () {
while (true) { // will be left by return when port is found
if (this.pos < this.list.length) {
@ -135,7 +146,7 @@ PortFinder.prototype.next = function () {
available = testPort("tcp://0.0.0.0:"+this.port);
}
else {
var url = "http" + this.dispatcher.endpoint.substr(3) +
var url = endpointToURL(this.dispatcher.endpoint) +
"/_admin/clusterCheckPort?port="+this.port;
var hdrs = {};
if (this.dispatcher.username !== undefined &&
@ -183,17 +194,6 @@ function getAddrPort (endpoint) {
return endpoint;
}
function endpointToURL (endpoint) {
if (endpoint.substr(0,6) === "ssl://") {
return "https://" + endpoint.substr(6);
}
var pos = endpoint.indexOf("://");
if (pos === -1) {
return "http://" + endpoint;
}
return "http" + endpoint.substr(pos);
}
function getAddr (endpoint) {
var addrPort = getAddrPort(endpoint);
var pos = addrPort.indexOf(":");

View File

@ -341,7 +341,10 @@
// set up the collection _graphs
addTask("setupGraphs", "setup _graphs collection", function () {
return createSystemCollection("_graphs", { waitForSync : true });
return createSystemCollection("_graphs", {
waitForSync : true,
journalSize: 1024 * 1024
});
});
////////////////////////////////////////////////////////////////////////////////
@ -413,7 +416,9 @@
// create the _modules collection
addTask("createModules", "setup _modules collection", function () {
return createSystemCollection("_modules");
return createSystemCollection("_modules", {
journalSize: 1024 * 1024
});
});
////////////////////////////////////////////////////////////////////////////////
@ -423,7 +428,9 @@
// create the _routing collection
addTask("createRouting", "setup _routing collection", function () {
// needs to be big enough for assets
return createSystemCollection("_routing", { journalSize: 32 * 1024 * 1024 });
return createSystemCollection("_routing", {
journalSize: 32 * 1024 * 1024
});
});
////////////////////////////////////////////////////////////////////////////////
@ -434,7 +441,9 @@
addTask("createKickstarterConfiguration",
"setup _cluster_kickstarter_plans collection", function () {
//TODO add check if this is the main dispatcher
return createSystemCollection("_cluster_kickstarter_plans");
return createSystemCollection("_cluster_kickstarter_plans", {
journalSize: 4 * 1024 * 1024
});
});
////////////////////////////////////////////////////////////////////////////////
@ -557,7 +566,9 @@
// set up the collection _aqlfunctions
addTask("setupAqlFunctions", "setup _aqlfunctions collection", function () {
return createSystemCollection("_aqlfunctions");
return createSystemCollection("_aqlfunctions", {
journalSize: 4 * 1024 * 1024
});
});
////////////////////////////////////////////////////////////////////////////////
@ -663,7 +674,10 @@
// create the _statistics collection
addTask("createConfiguration", "setup _configuration collection", function () {
var name = "_configuration";
var result = createSystemCollection(name, { waitForSync: true });
var result = createSystemCollection(name, {
waitForSync: true,
journalSize: 1024 * 1024
});
return result;
});

View File

@ -350,7 +350,7 @@ bool Endpoint::setTimeout (TRI_socket_t s, double timeout) {
// shut up Valgrind
memset(&tv, 0, sizeof(tv));
tv.tv_sec = (long) timeout;
tv.tv_usec = ((suseconds_t) (timeout * 1000000.0)) % 1000000;
tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0);
// conversion to (const char*) ensures windows does not complain
if (TRI_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char*)(&tv), sizeof(tv)) != 0) {

View File

@ -174,7 +174,7 @@ bool ClientConnection::prepare (const double timeout, const bool isWrite) const
assert(TRI_isvalidsocket(_socket));
tv.tv_sec = (long) timeout;
tv.tv_usec = ((long) (timeout * 1000000.0)) % 1000000;
tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0);
FD_ZERO(&fdset);
FD_SET(TRI_get_fd_or_handle_of_socket(_socket), &fdset);
@ -205,6 +205,10 @@ bool ClientConnection::prepare (const double timeout, const bool isWrite) const
}
}
if (res < 0) {
TRI_set_errno(errno);
}
return false;
}
@ -229,6 +233,11 @@ bool ClientConnection::writeClientConnection (void* buffer, size_t length, size_
if (status < 0) {
TRI_set_errno(errno);
_isConnected = false;
return false;
}
else if (status == 0) {
_isConnected = false;
return false;
}

View File

@ -207,7 +207,7 @@ bool SslClientConnection::prepare (const double timeout, const bool isWrite) con
fd_set fdset;
tv.tv_sec = (long) timeout;
tv.tv_usec = ((long) (timeout * 1000000.0)) % 1000000;
tv.tv_usec = (long) ((timeout - (double) tv.tv_sec) * 1000000.0);
FD_ZERO(&fdset);
FD_SET(TRI_get_fd_or_handle_of_socket(_socket), &fdset);

View File

@ -48,7 +48,7 @@ using namespace triagens::basics;
static int FillShapeValueJson (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Value> const& json,
v8::Handle<v8::Value> const json,
set<int>& seenHashes,
vector< v8::Handle<v8::Object> >& seenObjects,
bool create,
@ -102,7 +102,7 @@ static int FillShapeValueNull (TRI_shaper_t* shaper,
static int FillShapeValueBoolean (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Boolean> const& json) {
v8::Handle<v8::Boolean> const json) {
TRI_shape_boolean_t* ptr;
dst->_type = TRI_SHAPE_BOOLEAN;
@ -126,7 +126,7 @@ static int FillShapeValueBoolean (TRI_shaper_t* shaper,
static int FillShapeValueBoolean (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::BooleanObject> const& json) {
v8::Handle<v8::BooleanObject> const json) {
TRI_shape_boolean_t* ptr;
dst->_type = TRI_SHAPE_BOOLEAN;
@ -150,7 +150,7 @@ static int FillShapeValueBoolean (TRI_shaper_t* shaper,
static int FillShapeValueNumber (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Number> const& json) {
v8::Handle<v8::Number> const json) {
TRI_shape_number_t* ptr;
dst->_type = TRI_SHAPE_NUMBER;
@ -174,7 +174,7 @@ static int FillShapeValueNumber (TRI_shaper_t* shaper,
static int FillShapeValueNumber (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::NumberObject> const& json) {
v8::Handle<v8::NumberObject> const json) {
TRI_shape_number_t* ptr;
dst->_type = TRI_SHAPE_NUMBER;
@ -198,7 +198,7 @@ static int FillShapeValueNumber (TRI_shaper_t* shaper,
static int FillShapeValueString (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::String> const& json) {
v8::Handle<v8::String> const json) {
char* ptr;
TRI_Utf8ValueNFC str(TRI_UNKNOWN_MEM_ZONE, json);
@ -259,7 +259,7 @@ static int FillShapeValueString (TRI_shaper_t* shaper,
static int FillShapeValueList (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Array> const& json,
v8::Handle<v8::Array> const json,
set<int>& seenHashes,
vector< v8::Handle<v8::Object> >& seenObjects,
bool create,
@ -577,7 +577,7 @@ static int FillShapeValueList (TRI_shaper_t* shaper,
static int FillShapeValueArray (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Object> const& json,
v8::Handle<v8::Object> const json,
set<int>& seenHashes,
vector< v8::Handle<v8::Object> >& seenObjects,
bool create,
@ -827,7 +827,7 @@ static int FillShapeValueArray (TRI_shaper_t* shaper,
static int FillShapeValueJson (TRI_shaper_t* shaper,
TRI_shape_value_t* dst,
v8::Handle<v8::Value> const& json,
v8::Handle<v8::Value> const json,
set<int>& seenHashes,
vector< v8::Handle<v8::Object> >& seenObjects,
bool create,
@ -1452,7 +1452,7 @@ v8::Handle<v8::Value> TRI_JsonShapeData (TRI_shaper_t* shaper,
/// @brief converts a V8 object to a TRI_shaped_json_t
////////////////////////////////////////////////////////////////////////////////
TRI_shaped_json_t* TRI_ShapedJsonV8Object (v8::Handle<v8::Value> const& object,
TRI_shaped_json_t* TRI_ShapedJsonV8Object (v8::Handle<v8::Value> const object,
TRI_shaper_t* shaper,
bool create,
bool isLocked) {
@ -1489,7 +1489,7 @@ TRI_shaped_json_t* TRI_ShapedJsonV8Object (v8::Handle<v8::Value> const& object,
/// @brief converts a V8 object to a TRI_shaped_json_t in place
////////////////////////////////////////////////////////////////////////////////
int TRI_FillShapedJsonV8Object (v8::Handle<v8::Value> const& object,
int TRI_FillShapedJsonV8Object (v8::Handle<v8::Value> const object,
TRI_shaped_json_t* result,
TRI_shaper_t* shaper,
bool create,
@ -1518,7 +1518,7 @@ int TRI_FillShapedJsonV8Object (v8::Handle<v8::Value> const& object,
/// @brief convert a V8 value to a json_t value
////////////////////////////////////////////////////////////////////////////////
static TRI_json_t* ObjectToJson (v8::Handle<v8::Value> const& parameter,
static TRI_json_t* ObjectToJson (v8::Handle<v8::Value> const parameter,
set<int>& seenHashes,
vector<v8::Handle<v8::Object> >& seenObjects) {
if (parameter->IsBoolean()) {
@ -1629,7 +1629,7 @@ static TRI_json_t* ObjectToJson (v8::Handle<v8::Value> const& parameter,
/// @brief convert a V8 value to a json_t value
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_ObjectToJson (v8::Handle<v8::Value> const& parameter) {
TRI_json_t* TRI_ObjectToJson (v8::Handle<v8::Value> const parameter) {
set<int> seenHashes;
vector< v8::Handle<v8::Object> > seenObjects;
@ -1640,7 +1640,7 @@ TRI_json_t* TRI_ObjectToJson (v8::Handle<v8::Value> const& parameter) {
/// @brief converts an V8 object to a string
////////////////////////////////////////////////////////////////////////////////
string TRI_ObjectToString (v8::Handle<v8::Value> const& value) {
string TRI_ObjectToString (v8::Handle<v8::Value> const value) {
TRI_Utf8ValueNFC utf8Value(TRI_UNKNOWN_MEM_ZONE, value);
if (*utf8Value == 0) {
@ -1655,7 +1655,7 @@ string TRI_ObjectToString (v8::Handle<v8::Value> const& value) {
/// @brief converts an V8 object to a character
////////////////////////////////////////////////////////////////////////////////
char TRI_ObjectToCharacter (v8::Handle<v8::Value> const& value, bool& error) {
char TRI_ObjectToCharacter (v8::Handle<v8::Value> const value, bool& error) {
error = false;
if (! value->IsString() && ! value->IsStringObject()) {
@ -1677,7 +1677,7 @@ char TRI_ObjectToCharacter (v8::Handle<v8::Value> const& value, bool& error) {
/// @brief converts an V8 object to an int64_t
////////////////////////////////////////////////////////////////////////////////
int64_t TRI_ObjectToInt64 (v8::Handle<v8::Value> const& value) {
int64_t TRI_ObjectToInt64 (v8::Handle<v8::Value> const value) {
if (value->IsNumber()) {
return (int64_t) value->ToNumber()->Value();
}
@ -1694,7 +1694,7 @@ int64_t TRI_ObjectToInt64 (v8::Handle<v8::Value> const& value) {
/// @brief converts an V8 object to a uint64_t
////////////////////////////////////////////////////////////////////////////////
uint64_t TRI_ObjectToUInt64 (v8::Handle<v8::Value> const& value,
uint64_t TRI_ObjectToUInt64 (v8::Handle<v8::Value> const value,
const bool allowStringConversion) {
if (value->IsNumber()) {
return (uint64_t) value->ToNumber()->Value();
@ -1717,7 +1717,7 @@ uint64_t TRI_ObjectToUInt64 (v8::Handle<v8::Value> const& value,
/// @brief converts an V8 object to a double
////////////////////////////////////////////////////////////////////////////////
double TRI_ObjectToDouble (v8::Handle<v8::Value> const& value) {
double TRI_ObjectToDouble (v8::Handle<v8::Value> const value) {
if (value->IsNumber()) {
return value->ToNumber()->Value();
}
@ -1734,7 +1734,7 @@ double TRI_ObjectToDouble (v8::Handle<v8::Value> const& value) {
/// @brief converts an V8 object to a double with error handling
////////////////////////////////////////////////////////////////////////////////
double TRI_ObjectToDouble (v8::Handle<v8::Value> const& value, bool& error) {
double TRI_ObjectToDouble (v8::Handle<v8::Value> const value, bool& error) {
error = false;
if (value->IsNumber()) {
@ -1755,7 +1755,7 @@ double TRI_ObjectToDouble (v8::Handle<v8::Value> const& value, bool& error) {
/// @brief converts an V8 object to a boolean
////////////////////////////////////////////////////////////////////////////////
bool TRI_ObjectToBoolean (v8::Handle<v8::Value> const& value) {
bool TRI_ObjectToBoolean (v8::Handle<v8::Value> const value) {
if (value->IsBoolean()) {
return value->ToBoolean()->Value();
}

View File

@ -66,7 +66,7 @@ v8::Handle<v8::Value> TRI_JsonShapeData (TRI_shaper_t*,
/// @brief converts an V8 object to a TRI_shaped_json_t
////////////////////////////////////////////////////////////////////////////////
TRI_shaped_json_t* TRI_ShapedJsonV8Object (v8::Handle<v8::Value> const&,
TRI_shaped_json_t* TRI_ShapedJsonV8Object (v8::Handle<v8::Value> const,
TRI_shaper_t*,
bool,
bool);
@ -75,7 +75,7 @@ TRI_shaped_json_t* TRI_ShapedJsonV8Object (v8::Handle<v8::Value> const&,
/// @brief converts a V8 object to a TRI_shaped_json_t in place
////////////////////////////////////////////////////////////////////////////////
int TRI_FillShapedJsonV8Object (v8::Handle<v8::Value> const&,
int TRI_FillShapedJsonV8Object (v8::Handle<v8::Value> const,
TRI_shaped_json_t*,
TRI_shaper_t*,
bool,
@ -85,52 +85,52 @@ int TRI_FillShapedJsonV8Object (v8::Handle<v8::Value> const&,
/// @brief convert a V8 value to a json_t value
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_ObjectToJson (v8::Handle<v8::Value> const&);
TRI_json_t* TRI_ObjectToJson (v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts an V8 object to a string
////////////////////////////////////////////////////////////////////////////////
std::string TRI_ObjectToString (v8::Handle<v8::Value> const&);
std::string TRI_ObjectToString (v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts an V8 object to a character
////////////////////////////////////////////////////////////////////////////////
char TRI_ObjectToCharacter (v8::Handle<v8::Value> const&,
char TRI_ObjectToCharacter (v8::Handle<v8::Value> const,
bool& error);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts an V8 object to an int64_t
////////////////////////////////////////////////////////////////////////////////
int64_t TRI_ObjectToInt64 (v8::Handle<v8::Value> const&);
int64_t TRI_ObjectToInt64 (v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts an V8 object to a uint64_t
////////////////////////////////////////////////////////////////////////////////
uint64_t TRI_ObjectToUInt64 (v8::Handle<v8::Value> const&,
uint64_t TRI_ObjectToUInt64 (v8::Handle<v8::Value> const,
const bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts a V8 object to a double
////////////////////////////////////////////////////////////////////////////////
double TRI_ObjectToDouble (v8::Handle<v8::Value> const&);
double TRI_ObjectToDouble (v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts a V8 object to a double with error handling
////////////////////////////////////////////////////////////////////////////////
double TRI_ObjectToDouble (v8::Handle<v8::Value> const&,
double TRI_ObjectToDouble (v8::Handle<v8::Value> const,
bool& error);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts a V8 object to a boolean
////////////////////////////////////////////////////////////////////////////////
bool TRI_ObjectToBoolean (v8::Handle<v8::Value> const&);
bool TRI_ObjectToBoolean (v8::Handle<v8::Value> const);
// -----------------------------------------------------------------------------
// --SECTION-- GENERAL

View File

@ -3057,8 +3057,8 @@ bool TRI_ParseJavaScriptFile (char const* filename) {
////////////////////////////////////////////////////////////////////////////////
v8::Handle<v8::Value> TRI_ExecuteJavaScriptString (v8::Handle<v8::Context> context,
v8::Handle<v8::String> const& source,
v8::Handle<v8::Value> const& name,
v8::Handle<v8::String> const source,
v8::Handle<v8::Value> const name,
bool printResult) {
v8::HandleScope scope;

View File

@ -153,8 +153,8 @@ bool TRI_ParseJavaScriptFile (char const*);
////////////////////////////////////////////////////////////////////////////////
v8::Handle<v8::Value> TRI_ExecuteJavaScriptString (v8::Handle<v8::Context> context,
v8::Handle<v8::String> const& source,
v8::Handle<v8::Value> const& name,
v8::Handle<v8::String> const source,
v8::Handle<v8::Value> const name,
bool printResult);
////////////////////////////////////////////////////////////////////////////////