|
12 | 12 | end |
13 | 13 |
|
14 | 14 | let(:composer) { PageObjects::Components::Composer.new } |
15 | | - let(:rich) { composer.rich_editor } |
16 | 15 | let(:toasts) { PageObjects::Components::Toasts.new } |
17 | 16 | let(:diff_modal) { PageObjects::Modals::DiffModal.new } |
18 | | - let(:keyboard_shortcut) { [PLATFORM_KEY_MODIFIER, :alt, "p"] } |
19 | 17 |
|
20 | 18 | context "when triggering via keyboard shortcut" do |
21 | 19 | it "proofreads selected text using" do |
|
26 | 24 | composer.select_range(6, 12) |
27 | 25 |
|
28 | 26 | DiscourseAi::Completions::Llm.with_prepared_responses(["world"]) do |
29 | | - composer.composer_input.send_keys(keyboard_shortcut) |
| 27 | + composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"]) |
30 | 28 | diff_modal.confirm_changes |
31 | 29 | expect(composer.composer_input.value).to eq("hello world !") |
32 | 30 | end |
|
39 | 37 |
|
40 | 38 | # Simulate AI response |
41 | 39 | DiscourseAi::Completions::Llm.with_prepared_responses(["hello world"]) do |
42 | | - composer.composer_input.send_keys(keyboard_shortcut) |
| 40 | + composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"]) |
43 | 41 | diff_modal.confirm_changes |
44 | 42 | expect(composer.composer_input.value).to eq("hello world") |
45 | 43 | end |
|
50 | 48 |
|
51 | 49 | # Simulate AI response |
52 | 50 | DiscourseAi::Completions::Llm.with_prepared_responses(["hello world"]) do |
53 | | - composer.composer_input.send_keys(keyboard_shortcut) |
| 51 | + composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"]) |
54 | 52 | expect(toasts).to have_error(I18n.t("js.discourse_ai.ai_helper.no_content_error")) |
55 | 53 | end |
56 | 54 | 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 |
89 | 55 | end |
90 | 56 | end |
0 commit comments