ToolManagerSpec.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import {
  6. createCanvasEvent as canvasEvent
  7. } from '../../../util/MockEvents';
  8. import toolManagerModule from 'lib/features/tool-manager';
  9. import handToolModule from 'lib/features/hand-tool';
  10. import draggingModule from 'lib/features/dragging';
  11. describe('features/tool-manager', function() {
  12. beforeEach(bootstrapDiagram({ modules: [ toolManagerModule, handToolModule, draggingModule ] }));
  13. beforeEach(inject(function(dragging) {
  14. dragging.setOptions({ manual: true });
  15. }));
  16. describe('basics', function() {
  17. it('should register a tool', inject(function(toolManager) {
  18. // when
  19. toolManager.registerTool('lasso', {
  20. tool: 'lasso.selection',
  21. dragging: 'lasso'
  22. });
  23. // then
  24. expect(toolManager.length()).to.equal(2);
  25. }));
  26. it('should throw error when registering a tool without events', inject(function(toolManager) {
  27. // when
  28. function result() {
  29. toolManager.registerTool('hand');
  30. }
  31. // then
  32. expect(result).to.throw('A tool has to be registered with it\'s "events"');
  33. }));
  34. it('should have hand-tool as active', inject(function(toolManager, handTool) {
  35. // when
  36. handTool.activateHand(canvasEvent({ x: 150, y: 150 }));
  37. expect(toolManager.isActive('hand')).to.be.true;
  38. }));
  39. it('should have no active tool', inject(function(toolManager, handTool, dragging) {
  40. // when
  41. handTool.activateHand(canvasEvent({ x: 150, y: 150 }));
  42. dragging.end();
  43. expect(toolManager.isActive('hand')).to.be.false;
  44. }));
  45. });
  46. });