discourse/plugins/chat/spec/system/reply_to_message/mobile_spec.rb
Joffrey JAFFEUX b6aad28ccf
DEV: replace selenium driver with playwright (#31977)
This commit is replacing the system specs driver (selenium) by
Playwright: https://playwright.dev/

We are still using Capybara to write the specs but they will now be run
by Playwright. To achieve this we are using the non official ruby
driver: https://github.com/YusukeIwaki/capybara-playwright-driver

### Notable changes

- `CHROME_DEV_TOOLS` has been removed, it's not working well with
playwright use `pause_test` and inspect browser for now.

- `fill_in` is not generating key events in playwright, use `send_keys`
if you need this.

### New spec options

#### trace

Allows to capture a trace in a zip file which you can load at
https://trace.playwright.dev or locally through `npx playwright
show-trace /path/to/trace.zip`

_Example usage:_

```ruby
it "shows bar", trace: true do
  visit("/")

  find(".foo").click

  expect(page).to have_css(".bar")
end
```

#### video

Allows to capture a video of your spec.

_Example usage:_

```ruby
it "shows bar", video: true do
  visit("/")

  find(".foo").click

  expect(page).to have_css(".bar")
end
```

### New env variable

#### PLAYWRIGHT_SLOW_MO_MS

Allow to force playwright to wait DURATION (in ms) at each action.

_Example usage:_

```
PLAYWRIGHT_SLOW_MO_MS=1000 rspec foo_spec.rb
```

#### PLAYWRIGHT_HEADLESS

Allow to be in headless mode or not. Default will be headless.

_Example usage:_

```
PLAYWRIGHT_HEADLESS=0 rspec foo_spec.rb # will show the browser
```

### New helpers

#### with_logs

Allows to access the browser logs and check if something specific has
been logged.

_Example usage:_

```ruby
with_logs do |logger|
  # do something

  expect(logger.logs.map { |log| log[:message] }).to include("foo")
end
```

#### add_cookie

Allows to add a cookie on the browser session.

_Example usage:_

```ruby
add_cookie(name: "destination_url", value: "/new")
```

#### get_style

Get the property style value of an element.

_Example usage:_

```ruby
expect(get_style(find(".foo"), "height")).to eq("200px")
```

#### get_rgb_color

Get the rgb color of an element.

_Example usage:_

```ruby
expect(get_rgb_color(find("html"), "backgroundColor")).to eq("rgb(170, 51, 159)")
```
2025-05-06 10:44:14 +02:00

96 lines
3 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "Reply to message - channel - mobile", type: :system, mobile: true do
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:thread_page) { PageObjects::Pages::ChatThread.new }
let(:side_panel_page) { PageObjects::Pages::ChatSidePanel.new }
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:category_channel) }
fab!(:original_message) do
Fabricate(
:chat_message,
chat_channel: channel_1,
message: "This is a message to reply to!",
use_service: true,
)
end
before do
chat_system_bootstrap
channel_1.update!(threading_enabled: true)
channel_1.add(current_user)
sign_in(current_user)
end
context "when the message has not current thread" do
it "starts a thread" do
chat_page.visit_channel(channel_1)
channel_page.reply_to(original_message)
expect(side_panel_page).to have_open_thread
text = thread_page.send_message
expect(thread_page.messages).to have_message(text: text, persisted: true)
thread_page.back
expect(channel_page).to have_thread_indicator(original_message)
end
context "when reloading after creating thread" do
it "correctly loads the thread" do
chat_page.visit_channel(channel_1)
channel_page.reply_to(original_message)
thread_page.send_message("reply to message")
expect(thread_page.messages).to have_message(text: "reply to message")
refresh
expect(thread_page.messages).to have_message(text: "reply to message")
end
end
end
context "when the message has an existing thread" do
fab!(:message_1) { Fabricate(:chat_message, in_reply_to: original_message, use_service: true) }
it "replies to the existing thread" do
chat_page.visit_channel(channel_1)
expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(1)
channel_page.message_thread_indicator(original_message).click
expect(thread_page).to be_open
thread_page.send_message("reply to message")
expect(thread_page.messages).to have_message(text: message_1.message)
expect(thread_page.messages).to have_message(text: "reply to message")
thread_page.back
expect(channel_page.message_thread_indicator(original_message)).to have_reply_count(2)
expect(channel_page.messages).to have_no_message(text: "reply to message")
end
end
context "with threading disabled" do
before { channel_1.update!(threading_enabled: false) }
it "makes a reply in the channel" do
chat_page.visit_channel(channel_1)
channel_page.reply_to(original_message)
expect(page).to have_selector(
".chat-channel .chat-reply__excerpt",
text: original_message.excerpt,
)
text = channel_page.send_message("this is a test message")
expect(channel_page.messages).to have_message(text:)
end
end
end