Use the same texts on event links and graphs
Note we're delegating the `t` method because i18n-tasks doesn't detect code like `ApplicationController.helpers.t` and so reports we aren't using the `admin.stats.graph` translations.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<div id="graph" class="small-12 column">
|
||||
<h2><%= t "admin.stats.graph.#{event}" %> (<%= count %>)</h2>
|
||||
<h2><%= title %></h2>
|
||||
<%= chart_tag %>
|
||||
</div>
|
||||
|
||||
@@ -18,4 +18,8 @@ class Admin::Stats::ChartComponent < ApplicationComponent
|
||||
def chart_tag
|
||||
tag.div("data-graph": admin_api_stats_path(event: event))
|
||||
end
|
||||
|
||||
def title
|
||||
"#{chart.title} (#{count})"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,11 +9,7 @@ class Admin::Stats::EventLinksComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def link_text(event)
|
||||
text = t("admin.stats.graph.#{event}")
|
||||
if text.to_s.match(/translation missing/)
|
||||
text = event
|
||||
end
|
||||
text
|
||||
Ahoy::Chart.new(event).title
|
||||
end
|
||||
|
||||
def title
|
||||
|
||||
@@ -2,6 +2,7 @@ module Ahoy
|
||||
class Chart
|
||||
attr_reader :event_name
|
||||
delegate :count, to: :records
|
||||
delegate :t, to: "ApplicationController.helpers"
|
||||
|
||||
def initialize(event_name)
|
||||
@event_name = event_name
|
||||
@@ -24,11 +25,19 @@ module Ahoy
|
||||
|
||||
def data_points
|
||||
ds = Ahoy::DataSource.new
|
||||
ds.add event_name.to_s.titleize, records_by_day.count
|
||||
ds.add title, records_by_day.count
|
||||
|
||||
ds.build
|
||||
end
|
||||
|
||||
def title
|
||||
text = t("admin.stats.graph.#{event_name}")
|
||||
if text.to_s.match(/translation missing/)
|
||||
text = event_name.to_s.titleize
|
||||
end
|
||||
text
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def records
|
||||
|
||||
@@ -10,8 +10,8 @@ describe Admin::Stats::EventLinksComponent do
|
||||
expect(page).to have_link count: 2
|
||||
|
||||
page.find("ul") do |list|
|
||||
expect(list).to have_link "legislation_annotation_created"
|
||||
expect(list).to have_link "legislation_answer_created"
|
||||
expect(list).to have_link "Legislation Annotation Created"
|
||||
expect(list).to have_link "Legislation Answer Created"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ describe Admin::Api::StatsController, :admin do
|
||||
get :show, params: { event: "proposal_created" }
|
||||
|
||||
expect(response).to be_ok
|
||||
expect(response.parsed_body).to eq "x" => ["2015-01-01", "2015-01-02"], "Proposal Created" => [2, 1]
|
||||
expect(response.parsed_body).to eq "x" => ["2015-01-01", "2015-01-02"], "Citizen proposals" => [2, 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ describe Ahoy::Chart do
|
||||
|
||||
chart = Ahoy::Chart.new(:proposal_created)
|
||||
|
||||
expect(chart.data_points).to eq x: ["2015-01-01", "2015-01-02"], "Proposal Created" => [2, 1]
|
||||
expect(chart.data_points).to eq x: ["2015-01-01", "2015-01-02"], "Citizen proposals" => [2, 1]
|
||||
end
|
||||
|
||||
it "accepts strings as the event name" do
|
||||
@@ -30,7 +30,7 @@ describe Ahoy::Chart do
|
||||
|
||||
chart = Ahoy::Chart.new("proposal_created")
|
||||
|
||||
expect(chart.data_points).to eq x: ["2015-01-01"], "Proposal Created" => [1]
|
||||
expect(chart.data_points).to eq x: ["2015-01-01"], "Citizen proposals" => [1]
|
||||
end
|
||||
|
||||
it "returns visits data for the visits event" do
|
||||
@@ -70,7 +70,7 @@ describe Ahoy::Chart do
|
||||
|
||||
chart = Ahoy::Chart.new(:level_3_user)
|
||||
|
||||
expect(chart.data_points).to eq x: ["2001-01-02"], "Level 3 User" => [2]
|
||||
expect(chart.data_points).to eq x: ["2001-01-02"], "Level 3 users" => [2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -159,9 +159,9 @@ describe "Stats", :admin do
|
||||
create(:user, :level_three)
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "level_3_user"
|
||||
click_link "Level 3 users"
|
||||
|
||||
expect(page).to have_content "Level 3 User (1)"
|
||||
expect(page).to have_content "Level 3 users (1)"
|
||||
|
||||
within("#graph") do
|
||||
expect(page).to have_content Date.current.strftime("%Y-%m-%d")
|
||||
|
||||
Reference in New Issue
Block a user