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 | |
| 7 | #include <gtest/gtest.h> // IWYU pragma: keep |
| 8 | |
| 9 | // IWYU pragma: no_include <gtest/gtest-message.h> |
| 10 | // IWYU pragma: no_include <gtest/gtest-test-part.h> |
| 11 | // IWYU pragma: no_include "gtest/gtest_pred_impl.h" |
| 12 | |
| 13 | namespace json_html_util |
| 14 | { |
| 15 | namespace |
| 16 | { |
| 17 | |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 18 | const std::string boilerplateStart = |
| 19 | "<html>\n" |
| 20 | "<head>\n" |
| 21 | "<title>Redfish API</title>\n" |
Ed Tanous | a529a6a | 2024-05-29 16:51:37 -0700 | [diff] [blame] | 22 | "<link href=\"/styles/redfish.css\" rel=\"stylesheet\">\n" |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 23 | "</head>\n" |
| 24 | "<body>\n" |
| 25 | "<div class=\"container\">\n" |
Ed Tanous | a529a6a | 2024-05-29 16:51:37 -0700 | [diff] [blame] | 26 | "<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] | 27 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 28 | const std::string boilerplateEnd = |
| 29 | "</div>\n" |
| 30 | "</body>\n" |
| 31 | "</html>\n"; |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 32 | |
Ed Tanous | 5a60c56 | 2023-05-18 13:52:34 -0700 | [diff] [blame] | 33 | TEST(JsonHtmlSerializer, dumpHtmlLink) |
| 34 | { |
| 35 | std::string out; |
| 36 | nlohmann::json j; |
| 37 | j["@odata.id"] = "/redfish/v1"; |
| 38 | dumpHtml(out, j); |
| 39 | EXPECT_EQ( |
| 40 | out, |
Ed Tanous | bb8f3bb | 2023-05-18 14:05:17 -0700 | [diff] [blame] | 41 | boilerplateStart + |
| 42 | "<div class=\"content\">\n" |
| 43 | "{<div class=tab>"@odata.id": <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" + |
| 44 | boilerplateEnd); |
| 45 | } |
| 46 | |
| 47 | TEST(JsonHtmlSerializer, dumpint) |
| 48 | { |
| 49 | std::string out; |
| 50 | nlohmann::json j = 42; |
| 51 | dumpHtml(out, j); |
| 52 | EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" + |
| 53 | boilerplateEnd); |
| 54 | } |
| 55 | |
| 56 | TEST(JsonHtmlSerializer, dumpstring) |
| 57 | { |
| 58 | std::string out; |
| 59 | nlohmann::json j = "foobar"; |
| 60 | dumpHtml(out, j); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 61 | EXPECT_EQ(out, |
| 62 | boilerplateStart + "<div class=\"content\">\n\"foobar\"</div>\n" + |
| 63 | boilerplateEnd); |
Ed Tanous | 5a60c56 | 2023-05-18 13:52:34 -0700 | [diff] [blame] | 64 | } |
| 65 | } // namespace |
| 66 | } // namespace json_html_util |