Browse Source

Merge pull request #2546 from afshin/settings

Settings system tests.
Steven Silvester 7 years ago
parent
commit
a36f26c00a
3 changed files with 104 additions and 8 deletions
  1. 8 8
      test/src/apputils/vdom.spec.ts
  2. 95 0
      test/src/coreutils/settingregistry.spec.ts
  3. 1 0
      test/src/index.ts

+ 8 - 8
test/src/apputils/vdom.spec.ts

@@ -5,17 +5,17 @@ import {
   expect
 } from 'chai';
 
+import {
+  VDomModel, VDomRenderer
+} from '@jupyterlab/apputils';
+
 import {
   h, VirtualNode
 } from '@phosphor/virtualdom';
 
 import {
   Widget
-} from '@phosphor/widgets'
-
-import {
-  VDomModel, VDomRenderer
-} from '@jupyterlab/apputils';
+} from '@phosphor/widgets';
 
 
 class TestModel extends VDomModel {
@@ -39,7 +39,7 @@ class TestWidget extends VDomRenderer<TestModel> {
 
 class TestWidgetNoModel extends VDomRenderer<null> {
   protected render(): VirtualNode {
-    return h.span("No model!");
+    return h.span('No model!');
   }
 }
 
@@ -136,9 +136,9 @@ describe('@jupyterlab/domutils', () => {
           expect(span.textContent).to.equal('No model!');
           done();
         });
-      })
+      });
 
-    })
+    });
 
   });
 

+ 95 - 0
test/src/coreutils/settingregistry.spec.ts

@@ -0,0 +1,95 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import expect = require('expect.js');
+
+import {
+  IDataConnector, ISettingRegistry, SettingRegistry, StateDB
+} from '@jupyterlab/coreutils';
+
+import {
+  JSONObject
+} from '@phosphor/coreutils';
+
+
+export
+class TestConnector extends StateDB implements IDataConnector<ISettingRegistry.IPlugin, JSONObject> {
+  /**
+   * Create a new setting client data connector.
+   */
+  constructor() {
+    super({ namespace: 'setting-registry-tests' });
+  }
+
+  /**
+   * Retrieve a saved bundle from the data connector.
+   */
+  fetch(id: string): Promise<ISettingRegistry.IPlugin | null> {
+    return super.fetch(id).then(user => {
+      const schema = schemas[id] || { };
+      const result = { data: { composite: { }, user }, id, schema };
+
+      return result;
+    });
+  }
+
+  /**
+   * Remove a value from the data connector.
+   */
+  remove(id: string): Promise<void> {
+    return super.remove(id);
+  }
+
+  /**
+   * Save the user setting data in the data connector.
+   */
+  save(id: string, user: JSONObject): Promise<void> {
+    return super.save(id, user);
+  }
+}
+
+
+const connector = new TestConnector();
+
+const registry = new SettingRegistry({ connector });
+
+const schemas: { [key: string]: ISettingRegistry.ISchema } = { };
+
+
+describe('@jupyterlab/coreutils', () => {
+
+  describe('SettingRegistry', () => {
+
+    describe('#constructor()', () => {
+
+      it('should create a new setting registry', () => {
+        expect(registry).to.be.a(SettingRegistry);
+      });
+
+    });
+
+    describe('#pluginChanged', () => {
+
+      it('should emit when a plugin changes', done => {
+        const id = 'foo';
+        const key = 'bar';
+        const value = 'baz';
+
+        schemas[id] = { type: 'object' };
+
+        connector.clear()
+          .then(() => registry.load(id))
+          .then(() => registry.set(id, key, value))
+          .catch(reason => { done(JSON.stringify(reason)); });
+
+        registry.pluginChanged.connect((sender: any, plugin: string) => {
+          expect(id).to.be(plugin);
+          done();
+        });
+     });
+
+    });
+
+  });
+
+});

+ 1 - 0
test/src/index.ts

@@ -46,6 +46,7 @@ import './coreutils/observablestring.spec';
 import './coreutils/observablelist.spec';
 import './coreutils/pageconfig.spec';
 import './coreutils/path.spec';
+import './coreutils/settingregistry.spec';
 import './coreutils/time.spec';
 import './coreutils/undoablelist.spec';
 import './coreutils/url.spec';