-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Diabetes Report Section & Total registered patients (#5487)
**Story card:** [sc-14020](https://app.shortcut.com/simpledotorg/story/14020/add-diabetes-report-section-total-registered-patients) ## Because To add 2 more sections i.e. Diabetes report section and total registered patient ## This addresses In this PR we will add 2 sections Diabetes report section (1st section from figma) and total registered patient(3rd patient from figma). <img width="1512" alt="Screenshot 2024-11-13 at 10 59 24 PM" src="https://github.com/user-attachments/assets/83432c79-b0b8-49ec-98b8-4cdaa9fd0ec0"> ## Test instructions Enable this flipper flag :diabetes_progress_report_tab to check the functionality.
- Loading branch information
1 parent
8ddb9dc
commit 58ca22e
Showing
9 changed files
with
192 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 64 additions & 5 deletions
69
spec/components/progress_tab/diabetes/diagnosis_report_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,85 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe ProgressTab::Diabetes::DiagnosisReportComponent, type: :component do | ||
let(:region) { double("Region", slug: "region_slug", name: "Region 1") } | ||
let(:repository) { double("Repository") } | ||
let(:last_updated_at) { Time.current } | ||
|
||
let(:data) do | ||
{ | ||
"2024-06-01" => 42, | ||
"2024-07-01" => 44, | ||
"2024-08-01" => 49 | ||
} | ||
end | ||
|
||
let(:total_registrations) do | ||
data.map { |date_str, value| [Period.new(type: :month, value: date_str), value] }.to_h | ||
end | ||
|
||
let(:period_info) do | ||
data.keys.map do |date_str| | ||
period = Period.new(type: :month, value: date_str) | ||
date = Date.parse(date_str) | ||
[ | ||
period, | ||
{ | ||
name: date.strftime("%b-%Y"), | ||
ltfu_since_date: (date - 1.year).end_of_month.strftime("%d-%b-%Y"), | ||
ltfu_end_date: date.end_of_month.strftime("%d-%b-%Y") | ||
} | ||
] | ||
end.to_h | ||
end | ||
|
||
let(:diabetes_reports_data) do | ||
{ | ||
total_registrations: total_registrations, | ||
period_info: period_info, | ||
region: region, | ||
assigned_patients: 100, | ||
region: double("Region", name: "Region 1"), | ||
diagnosis: "diabetes" | ||
} | ||
end | ||
subject { render_inline(described_class.new(diabetes_reports_data: diabetes_reports_data)) } | ||
|
||
before do | ||
allow(repository).to receive(:cumulative_diabetes_registrations).and_return(total_registrations) | ||
allow(repository).to receive(:cumulative_assigned_diabetic_patients).and_return(diabetes_reports_data[:assigned_patients]) | ||
allow(repository).to receive(:period_info).and_return(period_info) | ||
allow(region).to receive(:slug).and_return("region_slug") | ||
end | ||
|
||
subject do | ||
render_inline(described_class.new( | ||
diabetes_reports_data: diabetes_reports_data, | ||
last_updated_at: last_updated_at | ||
)) | ||
end | ||
|
||
it "renders the diabetes report section" do | ||
expect(subject).to have_css("div#diabetes-report") | ||
end | ||
|
||
it "renders the back link with correct text and onclick behavior" do | ||
expect(subject).to have_css('a[onclick="goToPage(id=\'diabetes-report\', \'home-page\'); return false;"]', text: "back") | ||
expect(subject).to have_css( | ||
'a[onclick="goToPage(id=\'diabetes-report\', \'home-page\'); return false;"]', | ||
text: "back" | ||
) | ||
end | ||
|
||
it "renders the Reports::ProgressAssignedPatientsComponent with correct data" do | ||
expect(subject.text).to include("Region 1") | ||
expect(subject).to have_text(region.name) | ||
expect(subject.text).to include(diabetes_reports_data[:assigned_patients].to_s) | ||
expect(subject.text).to include("diabetes") | ||
expect(subject).to have_text("diabetes") | ||
end | ||
|
||
it "displays the last updated date and time" do | ||
formatted_date_time = last_updated_at.strftime("%d-%b-%Y at %I:%M %p") | ||
expect(subject).to have_text("Data last updated on #{formatted_date_time}") | ||
end | ||
|
||
it "renders the Reports::ProgressTotalRegistrationsComponent" do | ||
expect(subject).to have_text(region.name) | ||
expect(subject).to have_text("49") | ||
end | ||
end |
69 changes: 69 additions & 0 deletions
69
spec/components/reports/progress_total_registrations_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Reports::ProgressTotalRegistrationsComponent, type: :component do | ||
let(:region) { double("Region", name: "Region 1") } | ||
let(:total_registrations_data) do | ||
{ | ||
"2024-06-01" => 42, | ||
"2024-07-01" => 44, | ||
"2024-08-01" => 49, | ||
"2024-09-01" => 56, | ||
"2024-10-01" => 61, | ||
"2024-11-01" => 62 | ||
} | ||
end | ||
|
||
let(:total_registrations) do | ||
total_registrations_data.map { |date, value| [Period.new(type: :month, value: date), value] }.to_h | ||
end | ||
|
||
let(:period_info) do | ||
total_registrations_data.keys.map do |date| | ||
period = Period.new(type: :month, value: date) | ||
ltfu_since_date = Date.parse(date).prev_year.end_of_month.strftime("%d-%b-%Y") | ||
[period, {name: Date.parse(date).strftime("%b-%Y"), ltfu_since_date: ltfu_since_date}] | ||
end.to_h | ||
end | ||
let(:diagnosis) { "diabetes" } | ||
|
||
subject do | ||
render_inline(described_class.new( | ||
total_registrations: total_registrations, | ||
period_info: period_info, | ||
region: region, | ||
diagnosis: diagnosis | ||
)) | ||
end | ||
|
||
it "renders the component wrapper div" do | ||
expect(subject).to have_css("div.mb-8px.p-16px.bgc-white.bs-card") | ||
end | ||
|
||
it "renders the title with correct translation" do | ||
expect(subject).to have_text(I18n.t("progress_tab.diagnosis_report.total_registered_patients.title")) | ||
end | ||
|
||
it "renders the subtitle with the region name and diagnosis" do | ||
expect(subject).to have_text(I18n.t("progress_tab.diagnosis_report.total_registered_patients.subtitle", facility_name: region.name, diagnosis: diagnosis)) | ||
end | ||
|
||
it "renders the user analytics data bar graph partial" do | ||
expect(subject).to have_selector('div[data-graph-type="bar-chart"]') | ||
end | ||
|
||
it "passes the correct data to the data bar graph partial" do | ||
expect(subject).to have_selector('div[data-graph-type="bar-chart"]') | ||
|
||
expectations = [ | ||
"42", "44", "49", "56", "61", "62", | ||
"Jun-2024", "Jul-2024", "Aug-2024", "Sep-2024", "Oct-2024", "Nov-2024" | ||
] | ||
expectations.each { |expectation| expect(subject).to have_text(expectation) } | ||
end | ||
|
||
it "displays the correct number of total registrations" do | ||
total_registrations_data.values.each do |value| | ||
expect(subject).to have_text(value.to_s) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters