mirror of
https://github.com/discourse/discourse.git
synced 2025-06-11 04:43:52 +08:00

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)") ```
131 lines
3.8 KiB
Ruby
131 lines
3.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Send message", type: :system do
|
|
fab!(:user_1) { Fabricate(:admin) }
|
|
fab!(:user_2) { Fabricate(:admin) }
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
|
|
|
before do
|
|
# simpler user search without having to worry about user search data
|
|
SiteSetting.enable_names = false
|
|
|
|
chat_system_bootstrap
|
|
end
|
|
|
|
context "with direct message channels" do
|
|
context "when users are not following the channel" do
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [user_1, user_2]) }
|
|
|
|
before do
|
|
channel_1.remove(user_1)
|
|
channel_1.remove(user_2)
|
|
end
|
|
|
|
it "shows correct state" do
|
|
sign_in(user_1)
|
|
visit("/")
|
|
|
|
expect(chat_page.sidebar).to have_no_direct_message_channel(channel_1)
|
|
|
|
using_session(:user_2) do
|
|
sign_in(user_2)
|
|
visit("/")
|
|
|
|
expect(chat_page.sidebar).to have_no_direct_message_channel(channel_1)
|
|
end
|
|
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.filter(user_2.username)
|
|
chat_page.message_creator.click_row(user_2)
|
|
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
|
|
using_session(:user_2) do
|
|
expect(chat_page.sidebar).to have_no_direct_message_channel(channel_1)
|
|
end
|
|
|
|
channel_page.send_message
|
|
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
|
|
using_session(:user_2) do
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1, mention: true)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when users are following the channel" do
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [user_1, user_2]) }
|
|
|
|
it "shows correct state" do
|
|
sign_in(user_1)
|
|
visit("/")
|
|
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
|
|
using_session(:user_2) do
|
|
sign_in(user_2)
|
|
visit("/")
|
|
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
end
|
|
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.filter(user_2.username)
|
|
chat_page.message_creator.click_row(user_2)
|
|
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
|
|
using_session(:user_2) do
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
end
|
|
|
|
channel_page.send_message
|
|
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1)
|
|
|
|
using_session(:user_2) do
|
|
expect(chat_page.sidebar).to have_direct_message_channel(channel_1, mention: true)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when sending message from drawer" do
|
|
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
|
|
fab!(:post_1) { Fabricate(:post) }
|
|
fab!(:post_2) { Fabricate(:post, topic: post_1.topic) }
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
before do
|
|
sign_in(user_1)
|
|
channel_1.add(user_1)
|
|
Jobs.run_immediately!
|
|
end
|
|
|
|
it "has topic context" do
|
|
tested_context = {}
|
|
blk = Proc.new { |message, channel, user, context| tested_context = context }
|
|
|
|
begin
|
|
DiscourseEvent.on(:chat_message_created, &blk)
|
|
topic_page.visit_topic(post_1.topic)
|
|
chat_page.open_from_header
|
|
drawer_page.open_channel(channel_1)
|
|
channel_page.send_message
|
|
|
|
try_until_success do
|
|
expect(tested_context.dig(:context, :post_ids)).to eq([post_1.id, post_2.id])
|
|
expect(tested_context.dig(:context, :topic_id)).to eq(post_1.topic_id)
|
|
end
|
|
ensure
|
|
DiscourseEvent.off(:chat_message_created, &blk)
|
|
end
|
|
end
|
|
end
|
|
end
|