Просмотр исходного кода

Add more command linker tests.

Afshin Darian 8 лет назад
Родитель
Сommit
9e075b8542
1 измененных файлов с 91 добавлено и 4 удалено
  1. 91 4
      test/src/commandlinker/commandlinker.spec.ts

+ 91 - 4
test/src/commandlinker/commandlinker.spec.ts

@@ -7,6 +7,10 @@ import {
   CommandRegistry
 } from 'phosphor/lib/ui/commandregistry';
 
+import {
+  simulate
+} from 'simulate-event';
+
 import {
   CommandLinker
 } from '../../../lib/commandlinker/commandlinker';
@@ -18,11 +22,94 @@ describe('commandlinker/commandlinker', () => {
 
     describe('#constructor()', () => {
 
-      it('should create a completer handler', () => {
-        let linker = new CommandLinker({
-          commands: new CommandRegistry()
-        });
+      it('should create a command linker', () => {
+        let linker = new CommandLinker({ commands: new CommandRegistry() });
         expect(linker).to.be.a(CommandLinker);
+        linker.dispose();
+      });
+
+    });
+
+    describe('#isDisposed', () => {
+
+      it('should test whether a command linker has been disposed', () => {
+        let linker = new CommandLinker({ commands: new CommandRegistry() });
+        expect(linker.isDisposed).to.be(false);
+        linker.dispose();
+        expect(linker.isDisposed).to.be(true);
+      });
+
+    });
+
+    describe('#connectNode()', () => {
+
+      it('should connect a node to a command', () => {
+        let called = false;
+        let command = 'commandlinker:connect-node';
+        let commands =new CommandRegistry();
+        let linker = new CommandLinker({ commands });
+        let node = document.createElement('div');
+        let disposable = commands.addCommand(command, {
+          execute: () => { called = true; }
+        });
+
+        document.body.appendChild(node);
+        linker.connectNode(node, command, null);
+
+        expect(called).to.be(false);
+        simulate(node, 'click');
+        expect(called).to.be(true);
+
+        document.body.removeChild(node);
+        linker.dispose();
+        disposable.dispose();
+      });
+
+    });
+
+    describe('#disconnectNode()', () => {
+
+      it('should disconnect a node from a command', () => {
+        let called = false;
+        let command = 'commandlinker:disconnect-node';
+        let commands =new CommandRegistry();
+        let linker = new CommandLinker({ commands });
+        let node = document.createElement('div');
+        let disposable = commands.addCommand(command, {
+          execute: () => { called = true; }
+        });
+
+        document.body.appendChild(node);
+        linker.connectNode(node, command, null);
+
+        // Make sure connection is working.
+        expect(called).to.be(false);
+        simulate(node, 'click');
+        expect(called).to.be(true);
+
+        // Reset flag.
+        called = false;
+
+        // Make sure disconnection is working.
+        linker.disconnectNode(node);
+        expect(called).to.be(false);
+        simulate(node, 'click');
+        expect(called).to.be(false);
+
+        document.body.removeChild(node);
+        linker.dispose();
+        disposable.dispose();
+      });
+
+    });
+
+    describe('#dispose()', () => {
+
+      it('should dispose the resources held by the linker', () => {
+        let linker = new CommandLinker({ commands: new CommandRegistry() });
+        expect(linker.isDisposed).to.be(false);
+        linker.dispose();
+        expect(linker.isDisposed).to.be(true);
       });
 
     });