mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
FIX: Support add_directory_column in glimmered table header toggle (#29231)
#29209 introduced a bug where columns to the directory added via add_directory_column are not being translated properly. This fixes the issue and adds an integration test.
This commit is contained in:
@ -64,12 +64,11 @@ export default class TableHeaderToggle extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get label() {
|
get label() {
|
||||||
const labelKey = this.args.labelKey || `directory.${this.args.field}`;
|
const labelKey = this.labelKey || `directory.${this.args.field}`;
|
||||||
|
|
||||||
return this.args.translated
|
return this.args.translated
|
||||||
? this.args.field
|
? this.args.field
|
||||||
: I18n.t(`${labelKey}_long`, {
|
: I18n.t(labelKey + "_long", { defaultValue: I18n.t(labelKey) });
|
||||||
defaultValue: I18n.t(labelKey),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
112
spec/system/user_page/users_directory_spec.rb
Normal file
112
spec/system/user_page/users_directory_spec.rb
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "Users /u", type: :system do
|
||||||
|
fab!(:user)
|
||||||
|
|
||||||
|
before { Array.new(DirectoryItemsController::PAGE_SIZE + 10) { Fabricate(:user) } }
|
||||||
|
|
||||||
|
describe "shows a table of users" do
|
||||||
|
it "renders successfully for a logged-in user" do
|
||||||
|
DirectoryItem.refresh!
|
||||||
|
sign_in(user)
|
||||||
|
|
||||||
|
visit("/u")
|
||||||
|
|
||||||
|
expect(page).to have_css(".users-directory")
|
||||||
|
expect(page).not_to have_css(".spinner")
|
||||||
|
header_texts =
|
||||||
|
page
|
||||||
|
.all(".directory-table__column-header .header-contents")
|
||||||
|
.map { |element| element.text.strip }
|
||||||
|
|
||||||
|
expect(header_texts).to eq(
|
||||||
|
[
|
||||||
|
"Username",
|
||||||
|
"Received",
|
||||||
|
"Given",
|
||||||
|
"Topics Created",
|
||||||
|
"Replies Posted",
|
||||||
|
"Topics Viewed",
|
||||||
|
"Posts Read",
|
||||||
|
"Days Visited",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders successfully for an anonymous user" do
|
||||||
|
DirectoryItem.refresh!
|
||||||
|
visit("/u")
|
||||||
|
|
||||||
|
expect(page).to have_css(".users-directory")
|
||||||
|
expect(page).not_to have_css(".spinner")
|
||||||
|
header_texts =
|
||||||
|
page
|
||||||
|
.all(".directory-table__column-header .header-contents")
|
||||||
|
.map { |element| element.text.strip }
|
||||||
|
|
||||||
|
expect(header_texts).to eq(
|
||||||
|
[
|
||||||
|
"Username",
|
||||||
|
"Received",
|
||||||
|
"Given",
|
||||||
|
"Topics Created",
|
||||||
|
"Replies Posted",
|
||||||
|
"Topics Viewed",
|
||||||
|
"Posts Read",
|
||||||
|
"Days Visited",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "new directory item" do
|
||||||
|
let!(:plugin) { Plugin::Instance.new }
|
||||||
|
let!(:initial_directory_events) { [] }
|
||||||
|
|
||||||
|
before do
|
||||||
|
initial_directory_events.replace(DiscourseEvent.events["before_directory_refresh"].to_a)
|
||||||
|
DB.exec("ALTER TABLE directory_items ADD COLUMN IF NOT EXISTS links integer")
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
DiscourseEvent.events["before_directory_refresh"].delete(
|
||||||
|
(DiscourseEvent.events["before_directory_refresh"].to_a - initial_directory_events).last,
|
||||||
|
)
|
||||||
|
DB.exec("ALTER TABLE directory_items DROP COLUMN IF EXISTS links")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows the directory column with the appropriate label" do
|
||||||
|
plugin.add_directory_column(
|
||||||
|
"links",
|
||||||
|
query: "SELECT id, RANDOM() AS random_number FROM users;",
|
||||||
|
)
|
||||||
|
DirectoryItem.refresh!
|
||||||
|
DirectoryColumn.find_by(name: "links").update!(enabled: true)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
|
||||||
|
visit("/u")
|
||||||
|
|
||||||
|
expect(page).to have_css(".users-directory")
|
||||||
|
expect(page).not_to have_css(".spinner")
|
||||||
|
header_texts =
|
||||||
|
page
|
||||||
|
.all(".directory-table__column-header .header-contents")
|
||||||
|
.map { |element| element.text.strip }
|
||||||
|
|
||||||
|
expect(header_texts).to eq(
|
||||||
|
[
|
||||||
|
"Username",
|
||||||
|
"Received",
|
||||||
|
"Given",
|
||||||
|
"Topics Created",
|
||||||
|
"Replies Posted",
|
||||||
|
"Topics Viewed",
|
||||||
|
"Posts Read",
|
||||||
|
"Days Visited",
|
||||||
|
"Links",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user