UndoSpec.js 1.7 KB

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