2023-04-17 10:06:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Explorer", type: :system, js: true do
|
2024-03-12 12:06:01 -04:00
|
|
|
fab!(:admin)
|
2023-04-17 10:06:27 -04:00
|
|
|
fab!(:group) { Fabricate(:group, name: "group") }
|
2024-03-12 12:06:01 -04:00
|
|
|
fab!(:group_user) { Fabricate(:group_user, user: admin, group: group) }
|
2023-04-17 10:06:27 -04:00
|
|
|
|
2024-03-12 12:06:01 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.data_explorer_enabled = true
|
|
|
|
sign_in admin
|
|
|
|
end
|
2023-04-17 10:06:27 -04:00
|
|
|
|
|
|
|
context "with a query using a default param" do
|
|
|
|
fab!(:query_1) do
|
|
|
|
Fabricate(
|
|
|
|
:query,
|
|
|
|
name: "My default param query",
|
|
|
|
description: "Test default param query",
|
|
|
|
sql: "-- [params]\n-- string :limit = 42\n\nSELECT * FROM users LIMIT :limit",
|
2024-03-12 12:06:01 -04:00
|
|
|
user: admin,
|
2023-04-17 10:06:27 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
fab!(:query_group_1) { Fabricate(:query_group, query: query_1, group: group) }
|
|
|
|
|
|
|
|
it "pre-fills the field with the default param" do
|
|
|
|
visit("/g/group/reports/#{query_1.id}")
|
|
|
|
|
|
|
|
expect(page).to have_field("limit", with: 42)
|
|
|
|
end
|
|
|
|
end
|
2024-03-12 12:06:01 -04:00
|
|
|
|
|
|
|
context "with a group_list param" do
|
|
|
|
fab!(:q2) do
|
|
|
|
Fabricate(
|
|
|
|
:query,
|
|
|
|
name: "My query with group_list",
|
|
|
|
description: "Test group_list query",
|
|
|
|
sql:
|
|
|
|
"-- [params]\n-- group_list :groups\n\nSELECT g.id,g.name FROM groups g WHERE g.name IN(:groups) ORDER BY g.name ASC",
|
|
|
|
user: admin,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "supports setting a group_list param" do
|
|
|
|
visit(
|
|
|
|
"/admin/plugins/explorer?id=#{q2.id}¶ms=%7B\"groups\"%3A\"admins%2Ctrust_level_1\"%7D",
|
|
|
|
)
|
|
|
|
find(".query-run .btn-primary").click
|
|
|
|
|
|
|
|
expect(page).to have_css(".query-results .result-header")
|
|
|
|
|
|
|
|
expect(page).to have_css(
|
|
|
|
".query-results tbody tr:nth-child(1) td:nth-child(2)",
|
|
|
|
text: "admins",
|
|
|
|
)
|
|
|
|
expect(page).to have_css(
|
|
|
|
".query-results tbody tr:nth-child(2) td:nth-child(2)",
|
|
|
|
text: "trust_level_1",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2023-04-17 10:06:27 -04:00
|
|
|
end
|