0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/plugins/discourse-data-explorer/test/javascripts/acceptance/list-queries-test.js
Martin Brennan 2062faef44
DEV: Rename AdminFilterControls to DFilterControls (#41719)
The `AdminFilterControls` component isn't really admin specific,
and I want to use it in more places. Renaming to `DFilterControls`.
No backwards compat needed, it's only used in core + core plugins.

Also add `customEmptyState` to `DFilterControls`, which
allows caller to show a custom empty state for `DFilterControls`
in a yield when the array of result items is empty, for cases
where you might want to show e.g. a different message and CTA
when the filter is empty.

E.g. used in Kanban:

<img width="1107" height="439" alt="image"
src="https://github.com/user-attachments/assets/1466e4d9-ac4d-4c59-81e5-6e0e3e259c6f"
/>
2026-07-16 07:53:06 +10:00

91 lines
3 KiB
JavaScript
Vendored
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
acceptance("List Queries", function (needs) {
needs.user();
needs.settings({ data_explorer_enabled: true });
needs.pretender((server, helper) => {
server.get("/admin/plugins/discourse-data-explorer.json", () => {
return helper.response({
id: "discourse-data-explorer",
name: "discourse-data-explorer",
enabled: true,
has_settings: true,
humanized_name: "Data Explorer",
is_discourse_owned: true,
admin_route: {
label: "explorer.title",
location: "discourse-data-explorer",
use_new_show_route: true,
},
});
});
server.get("/admin/plugins/discourse-data-explorer/groups.json", () => {
return helper.response([]);
});
server.get("/admin/plugins/discourse-data-explorer/queries", () => {
return helper.response({
queries: [
{
id: -6,
name: "Top 100 Likers",
description:
"returns the top 100 likers for a given monthly period ordered by like_count. It accepts a months_ago parameter, defaults to 1 to give results for the last calendar month.",
username: "system",
group_ids: [],
last_run_at: "2021-02-11T08:29:59.337Z",
user_id: -1,
},
{
id: -5,
name: "Top 100 Active Topics",
description:
"based on the number of replies, it accepts a months_ago parameter, defaults to 1 to give results for the last calendar month.",
username: "system",
group_ids: [],
last_run_at: "2021-02-08T15:37:49.188Z",
user_id: -1,
},
],
total_rows_queries: 2,
});
});
});
test("renders the page with the list of queries", async function (assert) {
await visit("/admin/plugins/discourse-data-explorer/queries");
assert
.dom(".d-filter-controls__input")
.hasAttribute(
"placeholder",
i18n("explorer.search_placeholder"),
"the search box was rendered"
);
assert
.dom(".d-page-subheader .btn-primary")
.exists("the add query button was rendered");
assert
.dom(".d-page-subheader .d-page-action-wrapped-button")
.hasText(i18n("explorer.import.label"), "the import button was rendered");
assert
.dom("div.container table.recent-queries tbody tr")
.exists({ count: 2 }, "the list of queries was rendered");
assert
.dom("div.container table.recent-queries tbody tr:nth-child(1) td")
.hasText(/^\s*Top 100 Likers/, "The first query was rendered");
assert
.dom("div.container table.recent-queries tbody tr:nth-child(2) td")
.hasText(/^\s*Top 100 Active Topics/, "The second query was rendered");
});
});