|
46 | 46 | expect(popup2).is.null; |
47 | 47 | }); |
48 | 48 |
|
| 49 | + describe('Hex input', function () { |
| 50 | + // https://github.com/jodit/jodit-react/issues/310 |
| 51 | + it('Should apply pasted/typed hex color on Enter and on change', function () { |
| 52 | + const editor = getJodit(); |
| 53 | + |
| 54 | + editor.value = 'text2text'; |
| 55 | + |
| 56 | + const range = editor.s.createRange(); |
| 57 | + range.setStart(editor.editor.firstChild.firstChild, 3); |
| 58 | + range.setEnd(editor.editor.firstChild.firstChild, 6); |
| 59 | + editor.s.selectRange(range); |
| 60 | + |
| 61 | + clickButton('brush', editor); |
| 62 | + |
| 63 | + const popup = getOpenedPopup(editor); |
| 64 | + const input = popup.querySelector( |
| 65 | + '.jodit-color-picker__hex input' |
| 66 | + ); |
| 67 | + |
| 68 | + expect(input).is.not.null; |
| 69 | + |
| 70 | + input.value = '#FF0000'; |
| 71 | + simulateEvent('change', input); |
| 72 | + |
| 73 | + expect(editor.value).equals( |
| 74 | + '<p>tex<span style="background-color: rgb(255, 0, 0);">t2t</span>ext</p>' |
| 75 | + ); |
| 76 | + }); |
| 77 | + |
| 78 | + it('Should accept a hex value without the leading hash', function () { |
| 79 | + const editor = getJodit(); |
| 80 | + |
| 81 | + editor.value = 'text2text'; |
| 82 | + |
| 83 | + const range = editor.s.createRange(); |
| 84 | + range.setStart(editor.editor.firstChild.firstChild, 3); |
| 85 | + range.setEnd(editor.editor.firstChild.firstChild, 6); |
| 86 | + editor.s.selectRange(range); |
| 87 | + |
| 88 | + clickButton('brush', editor); |
| 89 | + |
| 90 | + const popup = getOpenedPopup(editor); |
| 91 | + const input = popup.querySelector( |
| 92 | + '.jodit-color-picker__hex input' |
| 93 | + ); |
| 94 | + |
| 95 | + input.value = '00FF00'; |
| 96 | + simulateEvent('keydown', input, e => { |
| 97 | + e.key = 'Enter'; |
| 98 | + }); |
| 99 | + |
| 100 | + expect(editor.value).equals( |
| 101 | + '<p>tex<span style="background-color: rgb(0, 255, 0);">t2t</span>ext</p>' |
| 102 | + ); |
| 103 | + }); |
| 104 | + |
| 105 | + it('Should ignore an invalid value', function () { |
| 106 | + const editor = getJodit(); |
| 107 | + |
| 108 | + editor.value = 'text2text'; |
| 109 | + |
| 110 | + const range = editor.s.createRange(); |
| 111 | + range.setStart(editor.editor.firstChild.firstChild, 3); |
| 112 | + range.setEnd(editor.editor.firstChild.firstChild, 6); |
| 113 | + editor.s.selectRange(range); |
| 114 | + |
| 115 | + clickButton('brush', editor); |
| 116 | + |
| 117 | + const popup = getOpenedPopup(editor); |
| 118 | + const input = popup.querySelector( |
| 119 | + '.jodit-color-picker__hex input' |
| 120 | + ); |
| 121 | + |
| 122 | + input.value = 'not-a-color'; |
| 123 | + simulateEvent('change', input); |
| 124 | + |
| 125 | + expect(editor.value).equals('<p>text2text</p>'); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
49 | 129 | describe('Show native color picker', function () { |
50 | 130 | describe('Enable', function () { |
51 | 131 | describe('Select all content by edges', function () { |
|
0 commit comments