mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 17:02:35 +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)") ```
103 lines
3.4 KiB
Ruby
103 lines
3.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Emoji deny list", type: :system do
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
|
let(:emoji_picker) { PageObjects::Components::EmojiPicker.new }
|
|
fab!(:admin)
|
|
|
|
before { sign_in(admin) }
|
|
|
|
describe "when editing admin settings" do
|
|
before { SiteSetting.emoji_deny_list = "" }
|
|
let(:site_settings_page) { PageObjects::Pages::AdminSiteSettings.new }
|
|
|
|
it "allows admin to update emoji deny list" do
|
|
site_settings_page.visit_category("posting")
|
|
|
|
site_settings_page.select_from_emoji_list("emoji_deny_list", ":grinning_face:", false)
|
|
site_settings_page.select_from_emoji_list("emoji_deny_list", ":smiley:")
|
|
|
|
expect(site_settings_page.values_in_list("emoji_deny_list")).to eq(%w[grinning_face smiley])
|
|
end
|
|
end
|
|
|
|
describe "when visiting topics" do
|
|
SiteSetting.emoji_deny_list = "monkey"
|
|
Emoji.clear_cache
|
|
|
|
fab!(:topic) { Fabricate(:topic, title: "Time for :monkey: business") }
|
|
fab!(:post) { Fabricate(:post, topic: topic, raw: "We have no time to :monkey: around!") }
|
|
|
|
it "should remove denied emojis from page title, heading and body" do
|
|
topic_page.visit_topic(topic)
|
|
expect(page.title).to eq("Time for business - Discourse")
|
|
expect(topic_page).to have_topic_title("Time for business")
|
|
expect(page).not_to have_css(".emoji[title=':monkey:']")
|
|
end
|
|
end
|
|
|
|
describe "when using composer" do
|
|
before do
|
|
SiteSetting.enable_emoji = true
|
|
SiteSetting.emoji_deny_list = "fu|poop"
|
|
Emoji.clear_cache && Discourse.request_refresh!
|
|
end
|
|
|
|
fab!(:topic)
|
|
fab!(:post) { Fabricate(:post, topic: topic) }
|
|
|
|
xit "should remove denied emojis from emoji picker" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
expect(composer).to be_opened
|
|
|
|
composer.click_toolbar_button("insert-composer-emoji")
|
|
expect(composer.emoji_picker).to be_visible
|
|
|
|
expect(emoji_picker).to have_no_emoji("fu")
|
|
end
|
|
|
|
it "should not show denied emojis and aliases in emoji autocomplete" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
|
|
composer.type_content(":poop") # shows no results
|
|
expect(emoji_picker).to have_no_emoji("poo")
|
|
expect(emoji_picker).to have_no_emoji("poop")
|
|
|
|
composer.clear_content
|
|
|
|
composer.type_content(":middle") # middle_finger is alias
|
|
expect(composer).to have_no_emoji_suggestion("fu")
|
|
end
|
|
|
|
it "should not show denied emoji in preview" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
|
|
composer.fill_content(":wave:")
|
|
expect(composer).to have_emoji_preview("wave")
|
|
|
|
composer.clear_content
|
|
|
|
composer.fill_content(":fu:")
|
|
expect(composer).to have_no_emoji_preview("fu")
|
|
end
|
|
end
|
|
|
|
describe "when using private messages" do
|
|
before do
|
|
SiteSetting.emoji_deny_list = "pancakes|monkey"
|
|
Emoji.clear_cache && Discourse.request_refresh!
|
|
end
|
|
|
|
fab!(:topic) do
|
|
Fabricate(:private_message_topic, title: "Want to catch up for :pancakes: today?")
|
|
end
|
|
fab!(:post) { Fabricate(:post, topic: topic, raw: "Can we use the :monkey: emoji here?") }
|
|
|
|
it "should remove denied emojis from message title and body" do
|
|
topic_page.visit_topic(topic)
|
|
expect(topic_page).to have_topic_title("Want to catch up for today?")
|
|
expect(post).not_to have_css(".emoji[title=':monkey:']")
|
|
end
|
|
end
|
|
end
|