mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-05 03:41:24 +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)") ```
402 lines
14 KiB
Ruby
402 lines
14 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "New topic list", type: :system do
|
|
fab!(:user)
|
|
fab!(:group) { Fabricate(:group, users: [user]) }
|
|
fab!(:category)
|
|
fab!(:tag)
|
|
|
|
fab!(:new_reply) { Fabricate(:new_reply_topic, current_user: user) }
|
|
fab!(:new_topic) { Fabricate(:post).topic }
|
|
fab!(:old_topic) { Fabricate(:read_topic, current_user: user) }
|
|
|
|
fab!(:new_reply_in_category) do
|
|
Fabricate(:new_reply_topic, category: category, current_user: user)
|
|
end
|
|
|
|
fab!(:new_topic_in_category) do
|
|
Fabricate(:post, topic: Fabricate(:topic, category: category)).topic
|
|
end
|
|
|
|
fab!(:old_topic_in_category) { Fabricate(:read_topic, category: category, current_user: user) }
|
|
fab!(:new_reply_with_tag) { Fabricate(:new_reply_topic, tags: [tag], current_user: user) }
|
|
|
|
fab!(:new_topic_with_tag) { Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic }
|
|
fab!(:old_topic_with_tag) { Fabricate(:read_topic, tags: [tag], current_user: user) }
|
|
|
|
let(:topic_list) { PageObjects::Components::TopicList.new }
|
|
let(:tabs_toggle) { PageObjects::Components::NewTopicListToggle.new }
|
|
|
|
before { sign_in(user) }
|
|
|
|
shared_examples "new list new topics and replies toggle" do
|
|
context "when the new new view is enabled" do
|
|
before { SiteSetting.experimental_new_new_view_groups = group.name }
|
|
|
|
it "shows all new topics and replies by default" do
|
|
visit("/new")
|
|
|
|
expect(topic_list).to have_topics(count: 6)
|
|
[
|
|
new_reply,
|
|
new_topic,
|
|
new_reply_in_category,
|
|
new_topic_in_category,
|
|
new_reply_with_tag,
|
|
new_topic_with_tag,
|
|
].each { |topic| expect(topic_list).to have_topic(topic) }
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(3)
|
|
expect(tabs_toggle.topics_tab).to have_count(3)
|
|
|
|
expect(tabs_toggle.all_tab).to be_active
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
end
|
|
|
|
it "respects the subset query param and activates the appropriate tab" do
|
|
visit("/new?subset=topics")
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_active
|
|
|
|
visit("/new?subset=replies")
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
end
|
|
|
|
it "shows only new topics when the user switches to the Topics tab" do
|
|
visit("/new")
|
|
tabs_toggle.topics_tab.click
|
|
|
|
expect(topic_list).to have_topics(count: 3)
|
|
[new_topic, new_topic_in_category, new_topic_with_tag].each do |topic|
|
|
expect(topic_list).to have_topic(topic)
|
|
end
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_active
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(3)
|
|
expect(tabs_toggle.topics_tab).to have_count(3)
|
|
|
|
expect(page).to have_current_path("/new?subset=topics")
|
|
end
|
|
|
|
it "shows only topics with new replies when the user switches to the Replies tab" do
|
|
visit("/new")
|
|
tabs_toggle.replies_tab.click
|
|
|
|
expect(topic_list).to have_topics(count: 3)
|
|
[new_reply, new_reply_in_category, new_reply_with_tag].each do |topic|
|
|
expect(topic_list).to have_topic(topic)
|
|
end
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(3)
|
|
expect(tabs_toggle.topics_tab).to have_count(3)
|
|
|
|
expect(page).to have_current_path("/new?subset=replies")
|
|
end
|
|
|
|
it "strips out the subset query params when switching back to the All tab from any of the other tabs" do
|
|
visit("/new")
|
|
tabs_toggle.replies_tab.click
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
|
|
expect(page).to have_current_path("/new?subset=replies")
|
|
|
|
tabs_toggle.all_tab.click
|
|
|
|
expect(tabs_toggle.all_tab).to be_active
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(page).to have_current_path("/new")
|
|
end
|
|
|
|
it "live-updates the counts shown on the tabs" do
|
|
visit("/new")
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(3)
|
|
expect(tabs_toggle.topics_tab).to have_count(3)
|
|
|
|
TopicUser.update_last_read(user, new_reply_in_category.id, 2, 1, 1)
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(2)
|
|
expect(tabs_toggle.topics_tab).to have_count(3)
|
|
|
|
TopicUser.update_last_read(user, new_topic.id, 1, 1, 1)
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(2)
|
|
expect(tabs_toggle.topics_tab).to have_count(2)
|
|
end
|
|
|
|
context "when the /new topic list is scoped to a category" do
|
|
it "shows new topics and replies in the category" do
|
|
visit("/c/#{category.slug}/#{category.id}/l/new")
|
|
expect(topic_list).to have_topics(count: 2)
|
|
expect(topic_list).to have_topic(new_reply_in_category)
|
|
expect(topic_list).to have_topic(new_topic_in_category)
|
|
|
|
expect(tabs_toggle.all_tab).to be_active
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
end
|
|
|
|
it "shows only new topics in the category when the user switches to the Topics tab" do
|
|
visit("/c/#{category.slug}/#{category.id}/l/new")
|
|
tabs_toggle.topics_tab.click
|
|
|
|
expect(topic_list).to have_topics(count: 1)
|
|
expect(topic_list).to have_topic(new_topic_in_category)
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_active
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
|
|
expect(page).to have_current_path(
|
|
"/c/#{category.slug}/#{category.id}/l/new?subset=topics",
|
|
)
|
|
end
|
|
|
|
it "shows only topics with new replies in the category when the user switches to the Replies tab" do
|
|
visit("/c/#{category.slug}/#{category.id}/l/new")
|
|
tabs_toggle.replies_tab.click
|
|
|
|
expect(topic_list).to have_topics(count: 1)
|
|
expect(topic_list).to have_topic(new_reply_in_category)
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
|
|
expect(page).to have_current_path(
|
|
"/c/#{category.slug}/#{category.id}/l/new?subset=replies",
|
|
)
|
|
end
|
|
|
|
it "respects the subset query param and activates the appropriate tab" do
|
|
visit("/c/#{category.slug}/#{category.id}/l/new?subset=topics")
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_active
|
|
|
|
visit("/c/#{category.slug}/#{category.id}/l/new?subset=replies")
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
end
|
|
|
|
it "live-updates the counts shown on the tabs" do
|
|
Fabricate(:post, topic: Fabricate(:topic, category: category))
|
|
|
|
visit("/c/#{category.slug}/#{category.id}/l/new")
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(2)
|
|
|
|
TopicUser.update_last_read(user, new_topic_in_category.id, 1, 1, 1)
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
end
|
|
end
|
|
|
|
context "when the /new topic list is scoped to a tag" do
|
|
it "shows new topics and replies with the tag" do
|
|
visit("/tag/#{tag.name}/l/new")
|
|
expect(topic_list).to have_topics(count: 2)
|
|
[new_reply_with_tag, new_topic_with_tag].each do |topic|
|
|
expect(topic_list).to have_topic(topic)
|
|
end
|
|
|
|
expect(tabs_toggle.all_tab).to be_active
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
end
|
|
|
|
it "shows only new topics with the tag when the user switches to the Topics tab" do
|
|
visit("/tag/#{tag.name}/l/new")
|
|
tabs_toggle.topics_tab.click
|
|
|
|
expect(topic_list).to have_topics(count: 1)
|
|
expect(topic_list).to have_topic(new_topic_with_tag)
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_active
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
|
|
expect(page).to have_current_path("/tag/#{tag.name}/l/new?subset=topics")
|
|
end
|
|
|
|
it "shows only topics with new replies with the tag when the user switches to the Replies tab" do
|
|
visit("/tag/#{tag.name}/l/new")
|
|
|
|
tabs_toggle.replies_tab.click
|
|
|
|
expect(topic_list).to have_topics(count: 1)
|
|
expect(topic_list).to have_topic(new_reply_with_tag)
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
|
|
expect(page).to have_current_path("/tag/#{tag.name}/l/new?subset=replies")
|
|
end
|
|
|
|
it "respects the subset query param and activates the appropriate tab" do
|
|
visit("/tag/#{tag.name}/l/new?subset=topics")
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_inactive
|
|
expect(tabs_toggle.topics_tab).to be_active
|
|
|
|
visit("/tag/#{tag.name}/l/new?subset=replies")
|
|
|
|
expect(tabs_toggle.all_tab).to be_inactive
|
|
expect(tabs_toggle.replies_tab).to be_active
|
|
expect(tabs_toggle.topics_tab).to be_inactive
|
|
end
|
|
|
|
it "live-updates the counts shown on the tabs" do
|
|
Fabricate(:post, topic: Fabricate(:topic, tags: [tag]))
|
|
|
|
visit("/tag/#{tag.name}/l/new")
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(2)
|
|
|
|
TopicUser.update_last_read(user, new_topic_with_tag.id, 1, 1, 1)
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(1)
|
|
expect(tabs_toggle.topics_tab).to have_count(1)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when the new new view is not enabled" do
|
|
before { SiteSetting.experimental_new_new_view_groups = "" }
|
|
|
|
it "doesn't show the tabs toggle" do
|
|
visit("/new")
|
|
expect(tabs_toggle).to be_not_rendered
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when on mobile", mobile: true do
|
|
include_examples "new list new topics and replies toggle"
|
|
|
|
context "when there are no new topics" do
|
|
before do
|
|
SiteSetting.experimental_new_new_view_groups = group.name
|
|
|
|
[new_topic, new_topic_in_category, new_topic_with_tag].each do |topic|
|
|
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
|
|
end
|
|
end
|
|
|
|
it "keeps the Topics tab even when there are no new topics" do
|
|
visit("/new")
|
|
|
|
expect(tabs_toggle.all_tab).to be_visible
|
|
expect(tabs_toggle.replies_tab).to be_visible
|
|
expect(tabs_toggle.topics_tab).to be_visible
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(3)
|
|
expect(tabs_toggle.topics_tab).to have_count(0)
|
|
end
|
|
end
|
|
|
|
context "when there are no new replies" do
|
|
before do
|
|
SiteSetting.experimental_new_new_view_groups = group.name
|
|
|
|
[new_reply, new_reply_in_category, new_reply_with_tag].each do |topic|
|
|
TopicUser.update_last_read(user, topic.id, 2, 1, 1)
|
|
end
|
|
end
|
|
|
|
it "keeps the Replies tab even when there are no new replies" do
|
|
visit("/new")
|
|
|
|
expect(tabs_toggle.all_tab).to be_visible
|
|
expect(tabs_toggle.replies_tab).to be_visible
|
|
expect(tabs_toggle.topics_tab).to be_visible
|
|
|
|
expect(tabs_toggle.replies_tab).to have_count(0)
|
|
expect(tabs_toggle.topics_tab).to have_count(3)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when on desktop" do
|
|
include_examples "new list new topics and replies toggle"
|
|
|
|
context "when there's only new topics" do
|
|
before do
|
|
SiteSetting.experimental_new_new_view_groups = group.name
|
|
|
|
[new_reply, new_reply_in_category, new_reply_with_tag].each do |topic|
|
|
TopicUser.update_last_read(user, topic.id, 2, 1, 1)
|
|
end
|
|
end
|
|
|
|
it "doesn't render the toggle and only shows a static label for new topics" do
|
|
visit("/new")
|
|
|
|
expect(tabs_toggle).to be_not_rendered
|
|
expect(find(".topic-list-header .static-label").text).to eq(
|
|
I18n.t("js.filters.new.topics_with_count", count: 3),
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when there's only new replies" do
|
|
before do
|
|
SiteSetting.experimental_new_new_view_groups = group.name
|
|
|
|
[new_topic, new_topic_in_category, new_topic_with_tag].each do |topic|
|
|
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
|
|
end
|
|
end
|
|
|
|
it "doesn't render the toggle and only shows a static label for new replies" do
|
|
visit("/new")
|
|
|
|
expect(tabs_toggle).to be_not_rendered
|
|
expect(find(".topic-list-header .static-label").text).to eq(
|
|
I18n.t("js.filters.new.replies_with_count", count: 3),
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|