Browse Source

Merge pull request #2524 from lucbouchard1/pageconfig-set

Add setOption method to pageconfig module
Brian E. Granger 7 years ago
parent
commit
28a2130534
2 changed files with 35 additions and 0 deletions
  1. 15 0
      packages/coreutils/src/pageconfig.ts
  2. 20 0
      test/src/coreutils/pageconfig.spec.ts

+ 15 - 0
packages/coreutils/src/pageconfig.ts

@@ -82,6 +82,21 @@ namespace PageConfig {
     }
     return configData[name] || '';
   }
+  
+  /**
+   * Set global configuration data for the Jupyter application.
+   *
+   * @param name - The name of the configuration option.
+   * @param value - The value to set the option to.
+   *
+   * @returns The last config value or an empty string if it doesn't exist.
+   */
+  export
+  function setOption(name: string, value: string): string {
+    let last = getOption(name);
+    configData[name] = value;
+    return last;
+  }
 
   /**
    * Get the base url for a Jupyter application.

+ 20 - 0
test/src/coreutils/pageconfig.spec.ts

@@ -26,6 +26,26 @@ describe('@jupyterlab/coreutils', () => {
 
     });
 
+    describe('#setOption()', () => {
+
+      it('should get last option value and set it to the passed value', () => {
+        expect(PageConfig.setOption('foo', 'bar1')).to.equal('bar');
+      });
+
+      it('should get a known option', () => {
+        expect(PageConfig.getOption('foo')).to.equal('bar1');
+      });
+
+      it('should add a new option', () => {
+        expect(PageConfig.setOption('bar', 'foo')).to.equal('');
+      });
+
+      it('should get a known option', () => {
+        expect(PageConfig.getOption('bar')).to.equal('foo');
+      });
+
+    });
+
     describe('#getBaseUrl()', () => {
 
       it('should get the base url of the page', () => {