discourse/plugins/chat/spec/system/admin/incoming_webhooks_spec.rb
Martin Brennan a879bcdc35
DEV: Introduce <DPageHeader /> and <DPageSubheader /> components (#30146)
This converts the `<AdminPageHeader />` component and the
`<AdminPageSubheader />` components into new components
that can be used outside of admin, and updates the CSS classes.
Also introduces a `<DPageActionButton />` component and child
components for the header action buttons.

I have to keep the old admin-only components around for
now until plugins are updated, then we can remove it,
and remove the re-exports that are done within
admin-page-action-button.gjs
2024-12-18 08:13:39 +10:00

77 lines
2.8 KiB
Ruby

# frozen_string_literal: true
describe "Admin Chat Incoming Webhooks", type: :system do
fab!(:current_user) { Fabricate(:admin) }
fab!(:chat_channel_1) { Fabricate(:chat_channel) }
let(:dialog) { PageObjects::Components::Dialog.new }
let(:admin_incoming_webhooks_page) { PageObjects::Pages::AdminIncomingWebhooks.new }
let(:d_page_header) { PageObjects::Components::DPageHeader.new }
before do
chat_system_bootstrap(current_user)
sign_in(current_user)
end
it "can create incoming webhooks" do
admin_incoming_webhooks_page.visit
expect(d_page_header).to be_visible
admin_incoming_webhooks_page.click_new
expect(d_page_header).to be_hidden
admin_incoming_webhooks_page.form.field("name").fill_in("Test webhook")
admin_incoming_webhooks_page.form.field("description").fill_in("Some test content")
admin_incoming_webhooks_page.form.field("username").fill_in("system")
admin_incoming_webhooks_page.channel_chooser.expand
admin_incoming_webhooks_page.channel_chooser.select_row_by_value(chat_channel_1.id)
admin_incoming_webhooks_page.channel_chooser.collapse
# TODO (martin) Add an emoji selection once Joffrey's emoji selector
# unification has landed in core.
admin_incoming_webhooks_page.form.submit
expect(page).to have_content(I18n.t("js.chat.incoming_webhooks.created"))
expect(page).to have_content(Chat::IncomingWebhook.find_by(name: "Test webhook").url)
end
describe "existing webhooks" do
fab!(:webhook_1) { Fabricate(:incoming_chat_webhook) }
fab!(:webhook_2) { Fabricate(:incoming_chat_webhook) }
it "can list existing incoming webhooks" do
admin_incoming_webhooks_page.visit
expect(page).to have_content(webhook_1.name)
expect(page).to have_content(webhook_1.chat_channel.title)
expect(page).to have_content(webhook_2.name)
expect(page).to have_content(webhook_2.chat_channel.title)
end
it "can edit an existing incoming webhook" do
admin_incoming_webhooks_page.visit
admin_incoming_webhooks_page
.list_row(webhook_1.id)
.find(".admin-chat-incoming-webhooks-edit")
.click
expect(admin_incoming_webhooks_page.form.field("name").value).to eq(webhook_1.name)
admin_incoming_webhooks_page.form.field("name").fill_in("Wow so cool")
admin_incoming_webhooks_page.form.submit
expect(page).to have_content(I18n.t("js.chat.incoming_webhooks.saved"))
admin_incoming_webhooks_page.visit
expect(page).to have_content("Wow so cool")
end
it "can delete an existing incoming webhook" do
admin_incoming_webhooks_page.visit
admin_incoming_webhooks_page
.list_row(webhook_1.id)
.find(".admin-chat-incoming-webhooks-delete")
.click
dialog.click_danger
expect(page).not_to have_content(webhook_1.name)
end
end
end