Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.2] Disable admin notifications management if notifications are disabled in config #17114

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { createTestingPinia } from "@pinia/testing";
import { getLocalVue } from "@tests/jest/helpers";
import { shallowMount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { setActivePinia } from "pinia";

import { mockFetcher } from "@/api/schema/__mocks__";

import NotificationsManagement from "./NotificationsManagement.vue";

jest.mock("@/api/schema");

const localVue = getLocalVue(true);

const selectors = {
sendNotificationButton: "#send-notification-button",
createBroadcastButton: "#create-broadcast-button",
} as const;

async function mountNotificationsManagement(config: any = {}) {
const pinia = createTestingPinia();
setActivePinia(pinia);

mockFetcher.path("/api/configuration").method("get").mock({ data: config });

const wrapper = shallowMount(NotificationsManagement as object, {
localVue,
pinia,
stubs: {
FontAwesomeIcon: true,
},
});

await flushPromises();

return wrapper;
}

describe("NotificationsManagement.vue", () => {
it("should render the create notification buttons if the notification system is enabled", async () => {
const config = { enable_notification_system: true };
const wrapper = await mountNotificationsManagement(config);

expect(wrapper.find(selectors.sendNotificationButton).exists()).toBe(true);
expect(wrapper.find(selectors.createBroadcastButton).exists()).toBe(true);
});

it("should not render the create notification buttons if the notification system is disabled", async () => {
const config = { enable_notification_system: false };
const wrapper = await mountNotificationsManagement(config);

expect(wrapper.find(selectors.sendNotificationButton).exists()).toBe(false);
expect(wrapper.find(selectors.createBroadcastButton).exists()).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<script setup lang="ts">
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BButton } from "bootstrap-vue";
import { BAlert, BButton } from "bootstrap-vue";
import { useRouter } from "vue-router/composables";

import { useConfig } from "@/composables/config";

import BroadcastsList from "@/components/admin/Notifications/BroadcastsList.vue";
import Heading from "@/components/Common/Heading.vue";

const router = useRouter();
const { config, isConfigLoaded } = useConfig();

function goToCreateNewNotification() {
router.push("/admin/notifications/create_new_notification");
Expand All @@ -28,18 +31,32 @@ function goToCreateNewBroadcast() {
<i>broadcast notifications</i> to all users (even anonymous users).
</p>

<div>
<BButton class="mb-2" variant="outline-primary" @click="goToCreateNewNotification">
<FontAwesomeIcon icon="plus" />
Send new notification
</BButton>

<BButton class="mb-2" variant="outline-primary" @click="goToCreateNewBroadcast">
<FontAwesomeIcon icon="plus" />
Create new broadcast
</BButton>
<div v-if="isConfigLoaded && config.enable_notification_system">
<div>
<BButton
id="send-notification-button"
class="mb-2"
variant="outline-primary"
@click="goToCreateNewNotification">
<FontAwesomeIcon icon="plus" />
Send new notification
</BButton>

<BButton
id="create-broadcast-button"
class="mb-2"
variant="outline-primary"
@click="goToCreateNewBroadcast">
<FontAwesomeIcon icon="plus" />
Create new broadcast
</BButton>
</div>

<BroadcastsList class="mt-2" />
</div>

<BroadcastsList class="mt-2" />
<BAlert v-else variant="warning" show>
The notification system is disabled. To enable it, set the
<code>enable_notification_system</code> option to <code>true</code> in the Galaxy configuration file.
</BAlert>
</div>
</template>
Loading