Ed Tanous | 5a60c56 | 2023-05-18 13:52:34 -0700 | [diff] [blame] | 1 | #include "json_html_serializer.hpp" |
| 2 | |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
| 5 | #include <string> |
| 6 | |
Ed Tanous | 478b7ad | 2024-07-15 19:11:54 -0700 | [diff] [blame^] | 7 | #include <gtest/gtest.h> |
Ed Tanous | 5a60c56 | 2023-05-18 13:52:34 -0700 | [diff] [blame] | 8 | |
| 9 | namespace json_html_util |
| 10 | { |
| 11 | namespace |
| 12 | { |
| 13 | |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 14 | const std::string boilerplateStart = |
| 15 | "<html>\n" |
| 16 | "<head>\n" |
| 17 | "<title>Redfish API</title>\n" |
Ed Tanous | a529a6a | 2024-05-29 16:51:37 -0700 | [diff] [blame] | 18 | "<link href=\"/styles/redfish.css\" rel=\"stylesheet\">\n" |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 19 | "</head>\n" |
| 20 | "<body>\n" |
| 21 | "<div class=\"container\">\n" |
Ed Tanous | a529a6a | 2024-05-29 16:51:37 -0700 | [diff] [blame] | 22 | "<img src=\"/images/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n"; |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 23 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 24 | const std::string boilerplateEnd = |
| 25 | "</div>\n" |
| 26 | "</body>\n" |
| 27 | "</html>\n"; |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 28 | |
Ed Tanous | 5a60c56 | 2023-05-18 13:52:34 -0700 | [diff] [blame] | 29 | TEST(JsonHtmlSerializer, dumpHtmlLink) |
| 30 | { |
| 31 | std::string out; |
| 32 | nlohmann::json j; |
| 33 | j["@odata.id"] = "/redfish/v1"; |
| 34 | dumpHtml(out, j); |
| 35 | EXPECT_EQ( |
| 36 | out, |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 37 | boilerplateStart + |
| 38 | "<div class=\"content\">\n" |
| 39 | "{<div class=tab>"@odata.id": <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" + |
| 40 | boilerplateEnd); |
| 41 | } |
| 42 | |
| 43 | TEST(JsonHtmlSerializer, dumpint) |
| 44 | { |
| 45 | std::string out; |
| 46 | nlohmann::json j = 42; |
| 47 | dumpHtml(out, j); |
| 48 | EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" + |
| 49 | boilerplateEnd); |
| 50 | } |
| 51 | |
| 52 | TEST(JsonHtmlSerializer, dumpstring) |
| 53 | { |
| 54 | std::string out; |
| 55 | nlohmann::json j = "foobar"; |
| 56 | dumpHtml(out, j); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 57 | EXPECT_EQ(out, |
| 58 | boilerplateStart + "<div class=\"content\">\n\"foobar\"</div>\n" + |
| 59 | boilerplateEnd); |
Ed Tanous | 5a60c56 | 2023-05-18 13:52:34 -0700 | [diff] [blame] | 60 | } |
| 61 | } // namespace |
| 62 | } // namespace json_html_util |