|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | describe('Limit plugin', function () { |
| 8 | + describe('limit.limit event', function () { |
| 9 | + it('Should fire limit.limit when limitChars is reached via keydown', function (done) { |
| 10 | + const editor = getJodit({ |
| 11 | + limitChars: 5, |
| 12 | + history: { |
| 13 | + timeout: 5 |
| 14 | + } |
| 15 | + }); |
| 16 | + |
| 17 | + let fired = false; |
| 18 | + editor.e.on('limit.limit', () => { |
| 19 | + fired = true; |
| 20 | + }); |
| 21 | + |
| 22 | + editor.value = '<p>12345</p>'; |
| 23 | + editor.s.setCursorAfter(editor.editor.firstChild.firstChild); |
| 24 | + |
| 25 | + simulateEvent(['keydown', 'keyup'], 'a', editor.editor); |
| 26 | + |
| 27 | + editor.async.setTimeout(() => { |
| 28 | + expect(fired).is.true; |
| 29 | + done(); |
| 30 | + }, 200); |
| 31 | + }); |
| 32 | + |
| 33 | + it('Should fire limit.limit on change when content exceeds limit', function (done) { |
| 34 | + const editor = getJodit({ |
| 35 | + limitChars: 5, |
| 36 | + history: { |
| 37 | + timeout: 5 |
| 38 | + } |
| 39 | + }); |
| 40 | + |
| 41 | + let fired = false; |
| 42 | + editor.e.on('limit.limit', () => { |
| 43 | + fired = true; |
| 44 | + }); |
| 45 | + |
| 46 | + editor.value = '<p>123456</p>'; |
| 47 | + |
| 48 | + editor.async.setTimeout(() => { |
| 49 | + expect(fired).is.true; |
| 50 | + done(); |
| 51 | + }, 200); |
| 52 | + }); |
| 53 | + |
| 54 | + it('Should fire limit.limit when inserting via insertHTML exceeds limit', function (done) { |
| 55 | + const editor = getJodit({ |
| 56 | + limitChars: 5, |
| 57 | + history: { |
| 58 | + timeout: 5 |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + let fired = false; |
| 63 | + editor.e.on('limit.limit', () => { |
| 64 | + fired = true; |
| 65 | + }); |
| 66 | + |
| 67 | + editor.value = '<p>1234</p>'; |
| 68 | + editor.s.setCursorAfter(editor.editor.firstChild.firstChild); |
| 69 | + |
| 70 | + // Insert 2 chars to exceed limit of 5 |
| 71 | + editor.s.insertHTML('ab'); |
| 72 | + |
| 73 | + editor.async.setTimeout(() => { |
| 74 | + expect(fired).is.true; |
| 75 | + done(); |
| 76 | + }, 200); |
| 77 | + }); |
| 78 | + |
| 79 | + it('Should fire limit.limit with limitWords', function (done) { |
| 80 | + const editor = getJodit({ |
| 81 | + limitWords: 3, |
| 82 | + history: { |
| 83 | + timeout: 5 |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + let fired = false; |
| 88 | + editor.e.on('limit.limit', () => { |
| 89 | + fired = true; |
| 90 | + }); |
| 91 | + |
| 92 | + editor.value = '<p>one two three four</p>'; |
| 93 | + |
| 94 | + editor.async.setTimeout(() => { |
| 95 | + expect(fired).is.true; |
| 96 | + done(); |
| 97 | + }, 200); |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
8 | 101 | describe('Keydown', function () { |
9 | 102 | describe('On keydown when editor already full', function () { |
10 | 103 | it('should deny insert any chars', function (done) { |
|
0 commit comments