Prechádzať zdrojové kódy

Add StateDB#changed test.

Afshin Darian 7 rokov pred
rodič
commit
ddb4ace56d

+ 1 - 1
packages/apputils-extension/src/index.ts

@@ -265,7 +265,7 @@ const state: JupyterLabPlugin<IStateDB> = {
           state.toJSON()
             .then(data => workspaces.save(id, { data, metadata }))
             .catch(reason => {
-              console.warn('Saving workspace failed.', reason);
+              console.warn(`Saving workspace (${id}) failed.`, reason);
             });
         }, 2000);
       }

+ 27 - 0
test/src/coreutils/statedb.spec.ts

@@ -25,6 +25,33 @@ describe('StateDB', () => {
 
   });
 
+  describe('#changed', () => {
+
+    it('should emit changes when the database is updated', done => {
+      let namespace = 'test-namespace';
+      let db = new StateDB({ namespace });
+      let changes: StateDB.Change[] = [
+        { id: 'foo', type: 'save' },
+        { id: 'foo', type: 'remove' },
+        { id: 'bar', type: 'save' },
+        { id: 'bar', type: 'remove' }
+      ];
+      let recorded: StateDB.Change[] = [];
+
+      db.changed.connect((sender, change) => { recorded.push(change); });
+
+      db.save('foo', 0)
+        .then(() => db.remove('foo'))
+        .then(() => db.save('bar', 1))
+        .then(() => db.remove('bar'))
+        .then(() => { expect(recorded).to.eql(changes); })
+        .then(() => db.clear())
+        .then(done)
+        .catch(done);
+    });
+
+  });
+
   describe('#maxLength', () => {
 
     it('should enforce the maximum length of a stored item', done => {