Explorar o código

Add restore test.

Afshin Darian %!s(int64=8) %!d(string=hai) anos
pai
achega
7c764e263b
Modificáronse 1 ficheiros con 36 adicións e 0 borrados
  1. 36 0
      test/src/instancerestorer/instancerestorer.spec.ts

+ 36 - 0
test/src/instancerestorer/instancerestorer.spec.ts

@@ -19,6 +19,10 @@ import {
   IInstanceRestorer, InstanceRestorer
 } from '../../../lib/instancerestorer/instancerestorer';
 
+import {
+  InstanceTracker
+} from '../../../lib/common/instancetracker';
+
 import {
   StateDB
 } from '../../../lib/statedb/statedb';
@@ -140,6 +144,38 @@ describe('instancerestorer/instancerestorer', () => {
 
     });
 
+    describe('#restore()', () => {
+
+      it('should restore the widgets in a tracker', done => {
+        let tracker = new InstanceTracker<Widget>({ namespace: 'foo-widget' });
+        let registry = new CommandRegistry();
+        let state = new StateDB({ namespace: NAMESPACE });
+        let ready = new utils.PromiseDelegate<void>();
+        let restorer = new InstanceRestorer({
+          first: ready.promise, registry, state
+        });
+        let called = false;
+        let key = `${tracker.namespace}:${tracker.namespace}`;
+
+        registry.addCommand(tracker.namespace, {
+          execute: () => { called = true; }
+        });
+        state.save(key, { data: null }).then(() => {
+          return restorer.restore(tracker, {
+            args: () => null,
+            name: () => tracker.namespace,
+            command: tracker.namespace
+          });
+        }).catch(done);
+        ready.resolve(void 0);
+        restorer.restored.then(() => { expect(called).to.be(true); })
+          .then(() => state.remove(key))
+          .then(() => { done(); })
+          .catch(done);
+      });
+
+    });
+
   });
 
 });