Skip to content

Commit e9129ad

Browse files
committed
Add regression tests for limit.limit event
Verified that the limit.limit event fires correctly for limitChars and limitWords in all scenarios (keydown, change, insertHTML). Closes #1181
1 parent cc7ca79 commit e9129ad

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

src/plugins/limit/limit.test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,99 @@
55
*/
66

77
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+
8101
describe('Keydown', function () {
9102
describe('On keydown when editor already full', function () {
10103
it('should deny insert any chars', function (done) {

0 commit comments

Comments
 (0)