mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
In categories with the "events" type (using the upcoming change "Enable events category type setup"), users who can create events now see a "New Event" button with a calendar icon instead of the default "New Topic". <img width="600" alt="image" src="https://github.com/user-attachments/assets/dfed0063-16cb-4da4-ba28-f58a1aca670c" /> Adds a new `create-topic-icon` value transformer alongside the existing `create-topic-label`, so plugins and themes can swap the create-topic button's icon. Also moves core's hardcoded shared-drafts label override out of `CreateTopicButton` and into `DNavigation`, so we're utilizing the same transformer. Fixed an issue with the create-topic button label not updating when navigating between categories.
71 lines
2.3 KiB
JavaScript
Vendored
71 lines
2.3 KiB
JavaScript
Vendored
import { visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
import { i18n } from "discourse-i18n";
|
|
|
|
const eventsPretender = (server, helper) => {
|
|
server.get("/discourse-post-event/events", () => {
|
|
return helper.response({ events: [] });
|
|
});
|
|
};
|
|
|
|
acceptance(
|
|
"Events Create Topic Button - allowed user in events category",
|
|
function (needs) {
|
|
needs.user({ can_create_discourse_post_event: true });
|
|
needs.settings({
|
|
calendar_enabled: true,
|
|
discourse_post_event_enabled: true,
|
|
events_calendar_categories: "1",
|
|
});
|
|
needs.pretender(eventsPretender);
|
|
|
|
test("renames the button to New Event and swaps the icon", async function (assert) {
|
|
await visit("/c/bug/1");
|
|
|
|
assert
|
|
.dom("#create-topic")
|
|
.hasText(i18n("discourse_post_event.new_event"));
|
|
assert.dom("#create-topic .d-icon-far-calendar-plus").exists();
|
|
});
|
|
|
|
test("keeps the default label and icon outside events categories", async function (assert) {
|
|
await visit("/c/feature/2");
|
|
|
|
assert.dom("#create-topic").hasText(i18n("topic.create"));
|
|
assert.dom("#create-topic .d-icon-far-pen-to-square").exists();
|
|
});
|
|
|
|
test("updates label and icon when navigating between categories", async function (assert) {
|
|
await visit("/c/feature/2");
|
|
assert.dom("#create-topic").hasText(i18n("topic.create"));
|
|
assert.dom("#create-topic .d-icon-far-pen-to-square").exists();
|
|
|
|
await visit("/c/bug/1");
|
|
assert
|
|
.dom("#create-topic")
|
|
.hasText(i18n("discourse_post_event.new_event"));
|
|
assert.dom("#create-topic .d-icon-far-calendar-plus").exists();
|
|
});
|
|
}
|
|
);
|
|
|
|
acceptance(
|
|
"Events Create Topic Button - user without permission",
|
|
function (needs) {
|
|
needs.user({ can_create_discourse_post_event: false });
|
|
needs.settings({
|
|
calendar_enabled: true,
|
|
discourse_post_event_enabled: true,
|
|
events_calendar_categories: "1",
|
|
});
|
|
needs.pretender(eventsPretender);
|
|
|
|
test("keeps the default label and icon", async function (assert) {
|
|
await visit("/c/bug/1");
|
|
|
|
assert.dom("#create-topic").hasText(i18n("topic.create"));
|
|
assert.dom("#create-topic .d-icon-far-pen-to-square").exists();
|
|
});
|
|
}
|
|
);
|