Переглянути джерело

Toolbar tests, work in progress.

Afshin Darian 8 роки тому
батько
коміт
a283ea9093
2 змінених файлів з 45 додано та 2 видалено
  1. 13 1
      src/csvwidget/toolbar.ts
  2. 32 1
      test/src/csvwidget/toolbar.spec.ts

+ 13 - 1
src/csvwidget/toolbar.ts

@@ -18,6 +18,18 @@ import {
 } from 'phosphor/lib/ui/widget';
 
 
+/**
+ * The supported parsing delimiters.
+ */
+export
+const DELIMITERS = [',', ';', '\t'];
+
+/**
+ * The labels for each delimiter as they appear in the dropdown menu.
+ */
+export
+const LABELS = [',', ';', '\\t'];
+
 /**
  * The class name added to a csv toolbar widget.
  */
@@ -136,7 +148,7 @@ namespace Private {
     let select = document.createElement('select');
     select.className = CSV_TOOLBAR_DROPDOWN_CLASS;
     label.textContent = 'Delimiter: ';
-    each(zip([',', ';', '\t'], [',', ';', '\\t']), ([delimiter, label]) => {
+    each(zip(DELIMITERS, LABELS), ([delimiter, label]) => {
       let option = document.createElement('option');
       option.value = delimiter;
       option.textContent = label;

+ 32 - 1
test/src/csvwidget/toolbar.spec.ts

@@ -4,7 +4,15 @@
 import expect = require('expect.js');
 
 import {
-  CSVToolbar
+  Widget
+} from 'phosphor/lib/ui/widget';
+
+import {
+  simulate
+} from 'simulate-event';
+
+import {
+  CSVToolbar, DELIMITERS
 } from '../../../lib/csvwidget/toolbar';
 
 
@@ -20,6 +28,29 @@ describe('csvwidget/table', () => {
         expect(toolbar.node.classList).to.contain('jp-CSVToolbar');
       });
 
+      it('should allow pre-selecting the delimiter', () => {
+        let wanted = DELIMITERS[DELIMITERS.length - 1];
+        let toolbar = new CSVToolbar({ selected: wanted });
+        expect(toolbar.selectNode.value).to.be(wanted);
+      });
+
+    });
+
+    describe('#delimiterChanged', () => {
+
+      it('should emit a value when the dropdown value changes', () => {
+        let toolbar = new CSVToolbar();
+        let delimiter = '';
+        let index = DELIMITERS.length - 1;
+        let wanted = DELIMITERS[index];
+        toolbar.delimiterChanged.connect((s, value) => { delimiter = value; });
+        Widget.attach(toolbar, document.body);
+        toolbar.selectNode.selectedIndex = index;
+        simulate(toolbar.selectNode, 'change');
+        expect(delimiter).to.be(wanted);
+        toolbar.dispose();
+      });
+
     });
 
   });