Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
171 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
describe('Delete database tests', function () { | ||
it('should delete database', function (done) { | ||
var dbName = 'dbName' + Math.random(); | ||
|
||
openBaseConnection(dbName, function (conn) { | ||
conn.close(); | ||
|
||
sklad.deleteDatabase(dbName, function (err) { | ||
expect(err).toBeFalsy(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should produce DOMError.InvalidStateError if database is blocked', function (done) { | ||
var dbName = 'dbName' + Math.random(); | ||
|
||
openBaseConnection(dbName, function (conn) { | ||
sklad.deleteDatabase(dbName, function (err) { | ||
expect(err.name).toBe('InvalidStateError'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
describe('API interface tests', function () { | ||
var dbName = 'dbName' + Math.random(); | ||
var conn; | ||
|
||
it('global variables should exist', function () { | ||
expect(window.indexedDB).toBeDefined(); | ||
expect(window.IDBTransaction).toBeDefined(); | ||
expect(window.IDBKeyRange).toBeDefined(); | ||
expect(window.IDBCursor).toBeDefined(); | ||
expect(typeof window.sklad).toBe('object'); | ||
expect(typeof window.sklad.open).toBe('function'); | ||
expect(typeof window.sklad.deleteDatabase).toBe('function'); | ||
expect(typeof window.sklad.keyValue).toBe('function'); | ||
|
||
expect(window.sklad.ASC).toBeDefined(); | ||
expect(window.sklad.ASC_UNIQUE).toBeDefined(); | ||
expect(window.sklad.DESC).toBeDefined(); | ||
expect(window.sklad.DESC_UNIQUE).toBeDefined(); | ||
}); | ||
|
||
it('should contain all needed methods in connection', function (done) { | ||
sklad.open(dbName, function (err, connection) { | ||
expect(err).toBeFalsy(); | ||
|
||
expect(typeof connection.insert).toBe('function'); | ||
expect(typeof connection.upsert).toBe('function'); | ||
expect(typeof connection.delete).toBe('function'); | ||
expect(typeof connection.clear).toBe('function'); | ||
expect(typeof connection.get).toBe('function'); | ||
expect(typeof connection.count).toBe('function'); | ||
expect(typeof connection.close).toBe('function'); | ||
|
||
expect(connection.database instanceof window.IDBDatabase).toBe(true); | ||
expect(Object.getOwnPropertyDescriptor(connection, 'database')).toEqual({ | ||
value: connection.database, | ||
enumerable: false, | ||
configurable: true, | ||
writable: false | ||
}); | ||
|
||
// close existing connection | ||
conn = connection; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should run migration code if database upgrades', function (done) { | ||
var migrationsRun = []; | ||
|
||
sklad.open(dbName, { | ||
version: 2, | ||
migration: { | ||
'1': function (database) { | ||
// this migration part shoud not run at all | ||
// because previous spec has already created 1st version of databse | ||
migrationsRun.push('current database version migration'); | ||
}, | ||
'2': function (database) { | ||
migrationsRun.push('new database version migration'); | ||
expect(database instanceof window.IDBDatabase).toBe(true); | ||
|
||
var objStore = database.createObjectStore('some_object_store', {keyPath: 'date'}); | ||
expect(objStore instanceof window.IDBObjectStore).toBe(true); | ||
} | ||
} | ||
}, function (err, connection) { | ||
expect(err).toBeFalsy(); | ||
|
||
expect(migrationsRun).not.toContain('current database version migration'); | ||
expect(migrationsRun).toContain('new database version migration'); | ||
|
||
// close existing connection | ||
conn = connection; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
if (conn) { | ||
// otherwise 'blocked' event will be caught | ||
// FIXME: handle it | ||
conn.close(); | ||
conn = null; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ describe('Database block tests', function () { | |
done(); | ||
}); | ||
}); | ||
}); | ||
}); |