| 1 | package format |
| 2 | |
| 3 | import ( |
| 4 | "github.com/onsi/ginkgo/v2" |
| 5 | "github.com/onsi/gomega" |
| 6 | "github.com/onsi/gomega/format" |
| 7 | ) |
| 8 | |
| 9 | var _ = ginkgo.Describe("RenderMarkdown", func() { |
| 10 | format.CharactersAroundMismatchToInclude = 10 |
| 11 | |
| 12 | ginkgo.It("should render the expected output based on config reflection/tags", func() { |
| 13 | actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &struct { |
| 14 | Name string `default:"notempty" key:"name"` |
| 15 | Host string `url:"host"` |
| 16 | }{}) |
| 17 | |
| 18 | expected := ` |
| 19 | ### URL Fields |
| 20 | |
| 21 | * __Host__ (__Required__) |
| 22 | <br>URL part: <code class="service-url">mock://<strong>host</strong>/</code> |
| 23 | |
| 24 | ### Query/Param Props |
| 25 | |
| 26 | * __name__ |
| 27 | Default: `[1:] + "`notempty`" + ` |
| 28 | ` |
| 29 | |
| 30 | gomega.Expect(actual).To(gomega.Equal(expected)) |
| 31 | }) |
| 32 | |
| 33 | ginkgo.It("should render url paths in sorted order", func() { |
| 34 | actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &struct { |
| 35 | Host string `url:"host"` |
| 36 | Path1 string `url:"path1"` |
| 37 | Path3 string `url:"path3"` |
| 38 | Path2 string `url:"path2"` |
| 39 | }{}) |
| 40 | |
| 41 | expected := ` |
| 42 | ### URL Fields |
| 43 | |
| 44 | * __Host__ (__Required__) |
| 45 | <br>URL part: <code class="service-url">mock://<strong>host</strong>/path1/path2/path3</code> |
| 46 | * __Path1__ (__Required__) |
| 47 | <br>URL part: <code class="service-url">mock://host/<strong>path1</strong>/path2/path3</code> |
| 48 | * __Path2__ (__Required__) |
| 49 | <br>URL part: <code class="service-url">mock://host/path1/<strong>path2</strong>/path3</code> |
| 50 | * __Path3__ (__Required__) |
| 51 | <br>URL part: <code class="service-url">mock://host/path1/path2/<strong>path3</strong></code> |
| 52 | |
| 53 | ### Query/Param Props |
| 54 | |
| 55 | `[1:] // Remove initial newline |
| 56 | |
| 57 | gomega.Expect(actual).To(gomega.Equal(expected)) |
| 58 | }) |
| 59 | |
| 60 | ginkgo.It("should render prop aliases", func() { |
| 61 | actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &struct { |
| 62 | Name string `key:"name,handle,title,target"` |
| 63 | }{}) |
| 64 | |
| 65 | expected := ` |
| 66 | ### URL Fields |
| 67 | |
| 68 | ### Query/Param Props |
| 69 | |
| 70 | * __name__ (__Required__) |
| 71 | Aliases: `[1:] + "`handle`, `title`, `target`" + ` |
| 72 | ` |
| 73 | |
| 74 | gomega.Expect(actual).To(gomega.Equal(expected)) |
| 75 | }) |
| 76 | |
| 77 | ginkgo.It("should render possible enum values", func() { |
| 78 | actual := testRenderTree(MarkdownTreeRenderer{HeaderPrefix: `### `}, &testEnummer{}) |
| 79 | |
| 80 | expected := ` |
| 81 | ### URL Fields |
| 82 | |
| 83 | ### Query/Param Props |
| 84 | |
| 85 | * __choice__ |
| 86 | Default: `[1:] + "`Maybe`" + ` |
| 87 | Possible values: ` + "`Yes`, `No`, `Maybe`" + ` |
| 88 | ` |
| 89 | |
| 90 | gomega.Expect(actual).To(gomega.Equal(expected)) |
| 91 | }) |
| 92 | |
| 93 | ginkgo.When("there are no query props", func() { |
| 94 | ginkgo.It("should prepend an empty-message instead of props description", func() { |
| 95 | actual := testRenderTree(MarkdownTreeRenderer{ |
| 96 | HeaderPrefix: `### `, |
| 97 | PropsDescription: "Feel free to set these:", |
| 98 | PropsEmptyMessage: "There is nothing to set!", |
| 99 | }, &struct { |
| 100 | Host string `url:"host"` |
| 101 | }{}) |
| 102 | |
| 103 | expected := ` |
| 104 | ### URL Fields |
| 105 | |
| 106 | * __Host__ (__Required__) |
| 107 | <br>URL part: <code class="service-url">mock://<strong>host</strong>/</code> |
| 108 | |
| 109 | ### Query/Param Props |
| 110 | |
| 111 | There is nothing to set!`[1:] // Remove initial newline |
| 112 | |
| 113 | gomega.Expect(actual).To(gomega.Equal(expected)) |
| 114 | }) |
| 115 | }) |
| 116 | |
| 117 | ginkgo.When("there are query props", func() { |
| 118 | ginkgo.It("should prepend the props description", func() { |
| 119 | actual := testRenderTree(MarkdownTreeRenderer{ |
| 120 | HeaderPrefix: `### `, |
| 121 | PropsDescription: "Feel free to set these:", |
| 122 | PropsEmptyMessage: "There is nothing to set!", |
| 123 | }, &struct { |
| 124 | Host string `url:"host"` |
| 125 | CoolMode bool `key:"coolmode" optional:""` |
| 126 | }{}) |
| 127 | |
| 128 | expected := ` |
| 129 | ### URL Fields |
| 130 | |
| 131 | * __Host__ (__Required__) |
| 132 | <br>URL part: <code class="service-url">mock://<strong>host</strong>/</code> |
| 133 | |
| 134 | ### Query/Param Props |
| 135 | |
| 136 | Feel free to set these: |
| 137 | |
| 138 | * __coolmode__ |
| 139 | Default: *empty* |
| 140 | `[1:] // Remove initial newline |
| 141 | |
| 142 | gomega.Expect(actual).To(gomega.Equal(expected)) |
| 143 | }) |
| 144 | }) |
| 145 | }) |