mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 23:26:01 +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)") ```
190 lines
7.6 KiB
Ruby
190 lines
7.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Local dates", type: :system do
|
|
fab!(:topic)
|
|
fab!(:current_user) { Fabricate(:user, refresh_auto_groups: true) }
|
|
let(:year) { Time.zone.now.year + 1 }
|
|
let(:month) { Time.zone.now.month }
|
|
let(:bookmark_modal) { PageObjects::Modals::Bookmark.new }
|
|
let(:bookmark_menu) { PageObjects::Components::BookmarkMenu.new }
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
|
let(:insert_datetime_modal) { PageObjects::Modals::InsertDateTime.new }
|
|
|
|
before do
|
|
create_post(user: current_user, topic: topic, title: "Date range test post", raw: <<~RAW)
|
|
First option: [date=#{year}-12-15 time=14:19:00 timezone="Asia/Singapore"]
|
|
Second option: [date=#{year}-12-15 time=01:20:00 timezone="Asia/Singapore"], or [date=#{year}-12-15 time=02:40:00 timezone="Asia/Singapore"]
|
|
Third option: [date-range from=#{year}-12-15T11:25:00 to=#{year}-12-16T00:26:00 timezone="Asia/Singapore"] or [date-range from=#{year}-12-22T11:57:00 to=#{year}-12-23T11:58:00 timezone="Asia/Singapore"]
|
|
RAW
|
|
end
|
|
|
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
|
|
|
def formatted_date_for_year(month, day)
|
|
Date.parse("#{year}-#{month}-#{day}").strftime("%A, %B %-d, %Y")
|
|
end
|
|
|
|
it "renders local dates and date ranges correctly" do
|
|
using_browser_timezone("Asia/Singapore") do
|
|
sign_in current_user
|
|
|
|
topic_page.visit_topic(topic)
|
|
|
|
expect(topic_page).to have_content(topic.title)
|
|
|
|
# Single date in a paragraph.
|
|
#
|
|
find("span[data-date]:nth-of-type(1)").click
|
|
expect(page.find("[data-content] .current .date-time")).to have_text(
|
|
"#{formatted_date_for_year(12, 15)}\n 2:19 PM",
|
|
exact: true,
|
|
)
|
|
page.send_keys(:escape)
|
|
|
|
# Two single dates in the same paragraph.
|
|
#
|
|
find("span[data-date]:nth-of-type(2)").click
|
|
expect(page.find("[data-content] .current .date-time")).to have_text(
|
|
"#{formatted_date_for_year(12, 15)}\n 1:20 AM",
|
|
exact: true,
|
|
)
|
|
page.send_keys(:escape)
|
|
|
|
find("span[data-date]:nth-of-type(3)").click
|
|
expect(page.find("[data-content] .current .date-time")).to have_text(
|
|
"#{formatted_date_for_year(12, 15)}\n 2:40 AM",
|
|
exact: true,
|
|
)
|
|
page.send_keys(:escape)
|
|
|
|
# Two date ranges in the same paragraph.
|
|
#
|
|
find("span[data-date]:nth-of-type(4)").click
|
|
expect(page.find("[data-content] .current .date-time")).to have_text(
|
|
"#{formatted_date_for_year(12, 15)}\n 11:25 AM → 12:26 AM",
|
|
exact: true,
|
|
)
|
|
page.send_keys(:escape)
|
|
|
|
find("span[data-date]:nth-of-type(6)").click
|
|
expect(page.find("[data-content] .current .date-time")).to have_text(
|
|
"#{formatted_date_for_year(12, 22)} 11:57 AM → #{formatted_date_for_year(12, 23)} 11:58 AM",
|
|
exact: true,
|
|
)
|
|
page.send_keys(:escape)
|
|
end
|
|
end
|
|
|
|
describe "insert modal" do
|
|
let(:timezone) { "Australia/Brisbane" }
|
|
|
|
before do
|
|
current_user.user_option.update!(timezone: timezone)
|
|
sign_in(current_user)
|
|
end
|
|
|
|
it "allows selecting a date without a time and inserts into the post" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
expect(topic_page).to have_expanded_composer
|
|
composer.click_toolbar_button("local-dates")
|
|
expect(insert_datetime_modal).to be_open
|
|
insert_datetime_modal.calendar_date_time_picker.select_year(year)
|
|
insert_datetime_modal.calendar_date_time_picker.select_day(16)
|
|
insert_datetime_modal.click_primary_button
|
|
expect(composer.composer_input.value).to have_content(
|
|
"[date=#{Date.parse("#{year}-#{month}-16").strftime("%Y-%m-%d")} timezone=\"#{timezone}\"]",
|
|
)
|
|
end
|
|
|
|
it "allows selecting a date with a time and inserts into the post" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
expect(topic_page).to have_expanded_composer
|
|
composer.click_toolbar_button("local-dates")
|
|
expect(insert_datetime_modal).to be_open
|
|
insert_datetime_modal.calendar_date_time_picker.select_year(year)
|
|
insert_datetime_modal.calendar_date_time_picker.select_day(16)
|
|
insert_datetime_modal.calendar_date_time_picker.fill_time("11:45")
|
|
insert_datetime_modal.click_primary_button
|
|
|
|
expect(composer.composer_input.value).to have_content(
|
|
"[date=#{Date.parse("#{year}-#{month}-16").strftime("%Y-%m-%d")} time=11:45:00 timezone=\"#{timezone}\"]",
|
|
)
|
|
end
|
|
|
|
it "allows selecting a start date and time and an end date and time" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
expect(topic_page).to have_expanded_composer
|
|
composer.click_toolbar_button("local-dates")
|
|
expect(insert_datetime_modal).to be_open
|
|
insert_datetime_modal.calendar_date_time_picker.select_year(year)
|
|
insert_datetime_modal.calendar_date_time_picker.select_day(16)
|
|
insert_datetime_modal.calendar_date_time_picker.fill_time("11:45")
|
|
insert_datetime_modal.select_to
|
|
|
|
insert_datetime_modal.calendar_date_time_picker.select_year(year)
|
|
insert_datetime_modal.calendar_date_time_picker.select_day(23)
|
|
insert_datetime_modal.calendar_date_time_picker.fill_time("12:45")
|
|
|
|
insert_datetime_modal.click_primary_button
|
|
expect(composer.composer_input.value).to have_content(
|
|
"[date-range from=#{Date.parse("#{year}-#{month}-16").strftime("%Y-%m-%d")}T11:45:00 to=#{Date.parse("#{year}-#{month}-23").strftime("%Y-%m-%d")}T12:45:00 timezone=\"#{timezone}\"]",
|
|
)
|
|
end
|
|
|
|
it "allows clearing the end date and time" do
|
|
topic_page.visit_topic_and_open_composer(topic)
|
|
|
|
expect(topic_page).to have_expanded_composer
|
|
|
|
composer.click_toolbar_button("local-dates")
|
|
|
|
expect(insert_datetime_modal).to be_open
|
|
|
|
insert_datetime_modal.calendar_date_time_picker.select_year(year)
|
|
insert_datetime_modal.calendar_date_time_picker.select_day(16)
|
|
insert_datetime_modal.calendar_date_time_picker.fill_time("11:45")
|
|
insert_datetime_modal.select_to
|
|
insert_datetime_modal.calendar_date_time_picker.select_year(year)
|
|
insert_datetime_modal.calendar_date_time_picker.select_day(23)
|
|
insert_datetime_modal.calendar_date_time_picker.fill_time("12:45")
|
|
insert_datetime_modal.delete_to
|
|
insert_datetime_modal.click_primary_button
|
|
|
|
expect(composer.composer_input.value).to have_content(
|
|
"[date=#{Date.parse("#{year}-#{month}-16").strftime("%Y-%m-%d")} time=11:45:00 timezone=\"#{timezone}\"]",
|
|
)
|
|
end
|
|
end
|
|
|
|
describe "bookmarks" do
|
|
before do
|
|
current_user.user_option.update!(timezone: "Asia/Singapore")
|
|
sign_in(current_user)
|
|
end
|
|
|
|
it "can use the post local date for a bookmark preset" do
|
|
topic_page.visit_topic(topic)
|
|
topic_page.expand_post_actions(topic.first_post)
|
|
topic_page.click_post_action_button(topic.first_post, :bookmark)
|
|
bookmark_menu.click_menu_option("custom")
|
|
bookmark_modal.select_preset_reminder(:post_local_date)
|
|
expect(topic_page).to have_post_bookmarked(topic.first_post)
|
|
bookmark = Bookmark.find_by(bookmarkable: topic.first_post, user: current_user)
|
|
expect(bookmark.reminder_at.to_s).to eq("#{year}-12-15 06:19:00 UTC")
|
|
end
|
|
|
|
it "does not allow using post dates in the past for a bookmark preset" do
|
|
topic.first_post.update!(
|
|
raw: 'First option: [date=1999-12-15 time=14:19:00 timezone="Asia/Singapore"]',
|
|
)
|
|
topic.first_post.rebake!
|
|
topic_page.visit_topic(topic)
|
|
topic_page.expand_post_actions(topic.first_post)
|
|
topic_page.click_post_action_button(topic.first_post, :bookmark)
|
|
bookmark_menu.click_menu_option("custom")
|
|
expect(bookmark_modal).to be_open
|
|
expect(bookmark_modal).to have_no_preset(:post_local_date)
|
|
end
|
|
end
|
|
end
|