CopySpec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = [ 'c', 'C' ];
  16. describe('features/keyboard - copy', function() {
  17. var defaultDiagramConfig = {
  18. modules: [
  19. copyPasteModule,
  20. modelingModule,
  21. keyboardModule,
  22. modelingModule,
  23. editorActionsModule
  24. ],
  25. canvas: {
  26. deferUpdate: false
  27. }
  28. };
  29. var decisionTable = [
  30. {
  31. desc: 'should call copy',
  32. keys: KEYS,
  33. ctrlKey: true,
  34. called: true
  35. }, {
  36. desc: 'should not call copy',
  37. keys: KEYS,
  38. ctrlKey: false,
  39. called: false
  40. }
  41. ];
  42. beforeEach(bootstrapDiagram(defaultDiagramConfig));
  43. forEach(decisionTable, function(testCase) {
  44. forEach(testCase.keys, function(key) {
  45. it(testCase.desc, inject(function(keyboard, editorActions) {
  46. // given
  47. var copySpy = spy(editorActions, 'trigger');
  48. var event = createKeyEvent(key, { ctrlKey: testCase.ctrlKey });
  49. // when
  50. keyboard._keyHandler(event);
  51. // then
  52. expect(copySpy.calledWith('copy')).to.be.equal(testCase.called);
  53. }));
  54. });
  55. });
  56. });