Skip to content

Commit

Permalink
test(unit): renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
falsandtru committed May 28, 2017
1 parent a3b4bb9 commit 0ae574c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
70 changes: 35 additions & 35 deletions src/layer/domain/indexeddb/service/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,60 +43,60 @@ describe('Unit: layers/domain/indexeddb/service/channel', function () {

it('link', () => {
const chan = new StoreChannel('test', () => new Value(0, ''));
const dao = chan.link('a');
const link = chan.link('a');

assert(dao === chan.link('a'));
assert(dao.__id === 0);
assert(dao.__key === 'a');
assert(dao.__date === 0);
assert(dao.n === 0);
assert(dao.s === '');
assert(link === chan.link('a'));
assert(link.__id === 0);
assert(link.__key === 'a');
assert(link.__date === 0);
assert(link.n === 0);
assert(link.s === '');

chan.destroy();
});

it('send', done => {
const chan = new StoreChannel('test', () => new Value(0, ''));
const dao = chan.link('a');
const link = chan.link('a');

dao.__event.once(['send', 'n'], ev => {
link.__event.once(['send', 'n'], ev => {
assert.deepEqual(ev, {
type: 'send',
attr: 'n',
newValue: 1,
oldValue: 0
});
chan.events.save.once(['a', 'n', 'put'], () => {
assert(dao.__id === 1);
assert(dao.__key === 'a');
assert(dao.__date > 0);
assert(link.__id === 1);
assert(link.__key === 'a');
assert(link.__date > 0);
chan.destroy();
done();
});
});

assert(dao.n === 0);
dao.n = 1;
assert(dao.__id === 0);
assert(dao.__key === 'a');
assert(dao.__date > 0);
assert(dao.n === 1);
assert(dao.s === '');
assert(link.n === 0);
link.n = 1;
assert(link.__id === 0);
assert(link.__key === 'a');
assert(link.__date > 0);
assert(link.n === 1);
assert(link.s === '');
});

it('recv', done => {
const chan = new StoreChannel('test', () => new Value(0, ''));
const dao = chan.link('a');
const link = chan.link('a');

assert(dao.n === 0);
assert(link.n === 0);
listen('test')(db => {
db.transaction('data', 'readwrite').objectStore('data').put(adjust(new StoreChannel.Record('a', { n: 1 }))).onsuccess = () => {
chan['schema'].data.fetch('a');
dao.__event.once(['recv', 'n'], () => {
assert(dao.__id === 1);
assert(dao.__key === 'a');
assert(dao.__date > 0);
assert(dao.n === 1);
link.__event.once(['recv', 'n'], () => {
assert(link.__id === 1);
assert(link.__key === 'a');
assert(link.__date > 0);
assert(link.n === 1);
chan.destroy();
done();
});
Expand All @@ -106,20 +106,20 @@ describe('Unit: layers/domain/indexeddb/service/channel', function () {

it('migrate', (done) => {
let chan = new StoreChannel('test', () => new Value(0, ''));
const dao = chan.link('a');
dao.n = 1;
const link = chan.link('a');
link.n = 1;
chan.events.save.once(['a', 'n', 'put'], () => {
chan.close();
chan = new StoreChannel('test', () => new Value(0, ''), dao => {
assert(dao.__id === 1);
assert(dao.n === 1);
dao.n = 2;
chan = new StoreChannel('test', () => new Value(0, ''), link => {
assert(link.__id === 1);
assert(link.n === 1);
link.n = 2;
});
const dao = chan.link('a');
const link = chan.link('a');
chan.events.load.once(['a', 'n', 'put'], () => {
assert(dao.n === 2);
assert(link.n === 2);
chan.events.save.once(['a', 'n', 'put'], () => {
assert(dao.__id === 2);
assert(link.__id === 2);
chan.destroy();
done();
});
Expand Down
28 changes: 14 additions & 14 deletions src/layer/domain/webstorage/service/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ describe('Unit: layers/domain/webstorage/service/channel', () => {
it('make/destroy', () => {
assert(sessionStorage.getItem('test') === null);
const chan = new StorageChannel('test', sessionStorage, factory);
const dao = chan.link();
assert(dao.n === 0);
const link = chan.link();
assert(link.n === 0);
assert(sessionStorage.getItem('test') === null);
dao.n = 1;
assert(dao.n === 1);
link.n = 1;
assert(link.n === 1);
assert(sessionStorage.getItem('test') === '{\"n\":1}');
chan.destroy();
assert(dao.n === 1);
assert(link.n === 1);
assert(sessionStorage.getItem('test') === null);
});

Expand All @@ -53,13 +53,13 @@ describe('Unit: layers/domain/webstorage/service/channel', () => {

it('update', () => {
const chan = new StorageChannel('test', sessionStorage, factory);
const dao = chan.link();
assert(dao.n === 0);
dao.n = 1;
assert(dao.n === 1);
const link = chan.link();
assert(link.n === 0);
link.n = 1;
assert(link.n === 1);
assert(JSON.parse(sessionStorage.getItem('test')!).n === 1);
dao.n = 0;
assert(dao.n === 0);
link.n = 0;
assert(link.n === 0);
assert(JSON.parse(sessionStorage.getItem('test')!).n === 0);
chan.destroy();
});
Expand All @@ -70,12 +70,12 @@ describe('Unit: layers/domain/webstorage/service/channel', () => {
if (v.n % 2) return;
v.n += 1;
});
const dao = chan.link();
assert(dao.n === 1);
const link = chan.link();
assert(link.n === 1);
assert(JSON.parse(sessionStorage.getItem('test')!).n === 1);
sessionStorage.setItem('test', JSON.stringify({ n: 2 }));
eventstream_.emit(['session', chan.name], <StorageEvent>{ newValue: '{"n": 2}' })
assert(dao.n === 3);
assert(link.n === 3);
assert(JSON.parse(sessionStorage.getItem('test')!).n === 3);
chan.destroy();
});
Expand Down

0 comments on commit 0ae574c

Please sign in to comment.