|
12 | 12 | end |
13 | 13 |
|
14 | 14 | let(:composer) { PageObjects::Components::Composer.new } |
| 15 | + let(:rich) { composer.rich_editor } |
15 | 16 | let(:toasts) { PageObjects::Components::Toasts.new } |
16 | 17 | let(:diff_modal) { PageObjects::Modals::DiffModal.new } |
| 18 | + let(:keyboard_shortcut) { [PLATFORM_KEY_MODIFIER, :alt, "p"] } |
17 | 19 |
|
18 | 20 | context "when triggering via keyboard shortcut" do |
19 | 21 | it "proofreads selected text using" do |
|
24 | 26 | composer.select_range(6, 12) |
25 | 27 |
|
26 | 28 | DiscourseAi::Completions::Llm.with_prepared_responses(["world"]) do |
27 | | - composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"]) |
| 29 | + composer.composer_input.send_keys(keyboard_shortcut) |
28 | 30 | diff_modal.confirm_changes |
29 | 31 | expect(composer.composer_input.value).to eq("hello world !") |
30 | 32 | end |
|
37 | 39 |
|
38 | 40 | # Simulate AI response |
39 | 41 | DiscourseAi::Completions::Llm.with_prepared_responses(["hello world"]) do |
40 | | - composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"]) |
| 42 | + composer.composer_input.send_keys(keyboard_shortcut) |
41 | 43 | diff_modal.confirm_changes |
42 | 44 | expect(composer.composer_input.value).to eq("hello world") |
43 | 45 | end |
|
48 | 50 |
|
49 | 51 | # Simulate AI response |
50 | 52 | DiscourseAi::Completions::Llm.with_prepared_responses(["hello world"]) do |
51 | | - composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"]) |
| 53 | + composer.composer_input.send_keys(keyboard_shortcut) |
52 | 54 | expect(toasts).to have_error(I18n.t("js.discourse_ai.ai_helper.no_content_error")) |
53 | 55 | end |
54 | 56 | end |
| 57 | + |
| 58 | + context "when using rich text editor" do |
| 59 | + before { SiteSetting.rich_editor = true } |
| 60 | + |
| 61 | + it "proofreads selected text and replaces it" do |
| 62 | + visit "/new-topic" |
| 63 | + expect(composer).to be_opened |
| 64 | + composer.toggle_rich_editor |
| 65 | + composer.type_content("hello worldd !") |
| 66 | + |
| 67 | + # NOTE: The rich text editor cannot use select_range on the page object since it is |
| 68 | + # a contenteditable element. It would be hard to make this generic enough to put in |
| 69 | + # the page object, maybe at some point in the future we can refactor this. |
| 70 | + execute_script(<<~JS, text) |
| 71 | + const composer = document.querySelector("#reply-control .d-editor-input"); |
| 72 | + const startNode = composer.firstChild.firstChild; |
| 73 | + composer.focus(); |
| 74 | + const range = document.createRange(); |
| 75 | + range.setStart(startNode, 6); |
| 76 | + range.setEnd(startNode, 12); |
| 77 | + const selection = window.getSelection(); |
| 78 | + selection.removeAllRanges(); |
| 79 | + selection.addRange(range); |
| 80 | + JS |
| 81 | + |
| 82 | + DiscourseAi::Completions::Llm.with_prepared_responses(["world"]) do |
| 83 | + composer.composer_input.send_keys(keyboard_shortcut) |
| 84 | + diff_modal.confirm_changes |
| 85 | + expect(rich).to have_css("p", text: "hello world !") |
| 86 | + end |
| 87 | + end |
| 88 | + end |
55 | 89 | end |
56 | 90 | end |
0 commit comments