This repository was archived by the owner on Jul 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathexplorer_spec.rb
More file actions
98 lines (83 loc) · 2.91 KB
/
explorer_spec.rb
File metadata and controls
98 lines (83 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true
RSpec.describe "Explorer", type: :system, js: true do
fab!(:admin)
fab!(:group) { Fabricate(:group, name: "group") }
fab!(:group_user) { Fabricate(:group_user, user: admin, group: group) }
before do
SiteSetting.data_explorer_enabled = true
sign_in admin
end
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",
user: admin,
)
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
it "allows to edit custom name" do
visit("/admin/plugins/explorer/queries/#{query_1.id}")
find(".query-run .btn-primary").click
find(".edit-query-name").click
find(".name-text-field input").fill_in(with: "My custom name edited")
find(".btn-primary").click
find("button span", text: "Save Changes and Run").click
expect(page.find(".name h1")).to have_content("My custom name edited")
end
end
context "with the old url format" do
fab!(:query_1) do
Fabricate(
:query,
name: "My query",
description: "Test query",
sql: "SELECT * FROM users",
user: admin,
)
end
it "redirects to the new url format" do
visit("/admin/plugins/explorer/?id=#{query_1.id}")
expect(page).to have_current_path("/admin/plugins/explorer/queries/#{query_1.id}")
end
it "redirects to the new url format with params" do
visit("/admin/plugins/explorer/?id=#{query_1.id}¶ms=%7B%22limit%22%3A%2210%22%7D")
expect(page).to have_current_path(
"/admin/plugins/explorer/queries/#{query_1.id}?params=%7B%22limit%22%3A%2210%22%7D",
)
end
end
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/queries/#{q2.id}?params=%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
end