-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18426 from lpichler/extract_format_column_report_…
…generator Extract method format_column from report generator
- Loading branch information
Showing
2 changed files
with
61 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
describe MiqReport do | ||
let(:miq_report) { FactoryBot.create(:miq_report) } | ||
|
||
before do | ||
EvmSpecHelper.local_miq_server | ||
end | ||
|
||
describe "#format_column" do | ||
it "formats resource_type column" do | ||
expect(miq_report.format_column("resource_type", {"resource_type" => "Vm"}, Time.zone)).to eq("VM and Instance") | ||
end | ||
|
||
it "formats column with base report Tenant" do | ||
miq_report.db = "Tenant" | ||
expect(miq_report.format_column("tenant_quotas.used", {"tenant_quotas.used" => 786, "tenant_quotas.name" => "cpu_allocated"}, Time.zone)).to eq("786 Count") | ||
end | ||
|
||
it "formats column with format method" do | ||
expect(miq_report.format_column("name", {"name" => "VM1"}, Time.zone)).to eq("VM1") | ||
end | ||
end | ||
|
||
describe "#build_html_col" do | ||
it "renders html for resource_type column" do | ||
expect(miq_report.build_html_col([], "resource_type", nil, {"resource_type" => "Vm"}, Time.zone)).to match_array(["<td>", "VM and Instance", "</td>"]) | ||
end | ||
|
||
it "renders html for with base report Tenant" do | ||
miq_report.db = "Tenant" | ||
expect(miq_report.build_html_col([], "tenant_quotas.used", nil, {"tenant_quotas.used" => 786, "tenant_quotas.name" => "cpu_allocated"}, Time.zone)).to match_array(["<td style=\"text-align:right\">", "786 Count", "</td>"]) | ||
end | ||
|
||
it "renders html for string column" do | ||
expect(miq_report.build_html_col([], "name", nil, {"name" => "VM1"}, Time.zone)).to match_array(["<td>", "VM1", "</td>"]) | ||
end | ||
|
||
it "renders html for time column" do | ||
string_time_now = "02/15/19 14:32:23 UTC" | ||
time_now = Time.zone.parse(string_time_now).utc | ||
expect(miq_report.build_html_col([], "time", nil, {"time" => time_now}, Time.zone)).to match_array(["<td style=\"text-align:center\">", string_time_now, "</td>"]) | ||
end | ||
|
||
it "renders html for integer and float column" do | ||
expect(miq_report.build_html_col([], "cpus", nil, {"cpus" => 10}, Time.zone)).to match_array(["<td style=\"text-align:right\">", "10", "</td>"]) | ||
expect(miq_report.build_html_col([], "average_speed", nil, {"average_speed" => 20.44}, Time.zone)).to match_array(["<td style=\"text-align:right\">", "20.44", "</td>"]) | ||
end | ||
end | ||
end |