discourse/plugins/chat/spec/system/admin/csv_exports_spec.rb
Martin Brennan 61c1d35f17
FEATURE: Convert chat plugin UI to new show plugin and admin UI guidelines (#28632)
This commit converts the current chat plugin UI into the
new "show plugin" UI already followed by AI and Gamification.

In the process, I also:

* Made a dedicated /new route to create new webhooks
* Converted the webhook form to FormKit
* Made some fixes and improvements to the `AdminPluginConfigPage`, `AdminPageHeader`,
   and `AdminPageSubheader` generic components, so more plugins can
   adopt the UI guidelines too. This includes adding a header outlet so plugins
   can add action buttons to the plugin show page header.
* Fixes the submit button loading state for FormKit (by Joffrey)

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2024-09-10 15:16:16 +10:00

79 lines
2.2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Admin Chat CSV exports", type: :system do
let(:dialog) { PageObjects::Components::Dialog.new }
let(:csv_export_pm_page) { PageObjects::Pages::CSVExportPM.new }
fab!(:current_user) { Fabricate(:admin) }
before do
Jobs.run_immediately!
sign_in(current_user)
chat_system_bootstrap
end
it "exports chat messages" do
Jobs.run_immediately!
message_1 = Fabricate(:chat_message, created_at: 12.months.ago)
message_2 = Fabricate(:chat_message, created_at: 6.months.ago)
message_3 = Fabricate(:chat_message, created_at: 1.months.ago)
message_4 = Fabricate(:chat_message, created_at: Time.now)
visit "/admin/plugins/chat"
click_button I18n.t("js.chat.admin.export_messages.create_export")
dialog.click_yes
visit "/u/#{current_user.username}/messages"
click_link I18n.t(
"system_messages.csv_export_succeeded.subject_template",
export_title: "Chat Message",
)
expect(csv_export_pm_page).to have_download_link
exported_data = csv_export_pm_page.download_and_extract
expect(exported_data.first).to eq(
%w[
id
chat_channel_id
chat_channel_name
user_id
username
message
cooked
created_at
updated_at
deleted_at
in_reply_to_id
last_editor_id
last_editor_username
],
)
assert_message(exported_data.second, message_1)
assert_message(exported_data.third, message_2)
assert_message(exported_data.fourth, message_3)
assert_message(exported_data.fifth, message_4)
ensure
csv_export_pm_page.clear_downloads
end
def assert_message(exported_message, message)
time_format = "%Y-%m-%d %H:%M:%S UTC"
expect(exported_message).to eq(
[
message.id.to_s,
message.chat_channel.id.to_s,
message.chat_channel.name,
message.user.id.to_s,
message.user.username,
message.message,
message.cooked,
message.created_at.strftime(time_format),
message.updated_at.strftime(time_format),
nil,
nil,
message.last_editor.id.to_s,
message.last_editor.username,
],
)
end
end