PasteSpec.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* global sinon */
  2. import {
  3. bootstrapDiagram,
  4. inject
  5. } from 'test/TestHelper';
  6. import {
  7. forEach
  8. } from 'min-dash';
  9. import copyPasteModule from 'lib/features/copy-paste';
  10. import modelingModule from 'lib/features/modeling';
  11. import keyboardModule from 'lib/features/keyboard';
  12. import editorActionsModule from 'lib/features/editor-actions';
  13. import { createKeyEvent } from 'test/util/KeyEvents';
  14. var spy = sinon.spy;
  15. var KEYS = [ 'v', 'V' ];
  16. describe('features/keyboard - paste', function() {
  17. var defaultDiagramConfig = {
  18. modules: [
  19. copyPasteModule,
  20. modelingModule,
  21. editorActionsModule,
  22. keyboardModule,
  23. modelingModule
  24. ],
  25. canvas: {
  26. deferUpdate: false
  27. }
  28. };
  29. var decisionTable = [{
  30. desc: 'should call paste',
  31. keys: KEYS,
  32. ctrlKey: true,
  33. called: true
  34. }, {
  35. desc: 'should not call paste',
  36. keys: KEYS,
  37. ctrlKey: false,
  38. called: false
  39. }];
  40. beforeEach(bootstrapDiagram(defaultDiagramConfig));
  41. forEach(decisionTable, function(testCase) {
  42. forEach(testCase.keys, function(key) {
  43. it(testCase.desc, inject(function(keyboard, editorActions) {
  44. // given
  45. var pasteSpy = spy(editorActions, 'trigger');
  46. var event = createKeyEvent(key, { ctrlKey: testCase.ctrlKey });
  47. // when
  48. keyboard._keyHandler(event);
  49. // then
  50. expect(pasteSpy.calledWith('paste')).to.be.equal(testCase.called);
  51. }));
  52. });
  53. });
  54. });