-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_swagger_options_test.go
78 lines (74 loc) · 2.52 KB
/
ui_swagger_options_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package chioas
import (
"github.com/stretchr/testify/assert"
"html/template"
"testing"
)
func TestSwaggerOptions_ToMap_Empty(t *testing.T) {
o := &SwaggerOptions{}
m := o.ToMap()
assert.Empty(t, m)
}
func TestSwaggerOptions_ToMap_NonEmpty(t *testing.T) {
o := &SwaggerOptions{
DomId: "foo",
Layout: "foo",
DeepLinking: true,
DisplayOperationId: true,
DefaultModelsExpandDepth: 1,
DefaultModelExpandDepth: 1,
DefaultModelRendering: "foo",
DisplayRequestDuration: true,
DocExpansion: "foo",
MaxDisplayedTags: 1,
ShowExtensions: true,
ShowCommonExtensions: true,
UseUnsafeMarkdown: true,
SyntaxHighlightTheme: "foo",
TryItOutEnabled: true,
RequestSnippetsEnabled: true,
SupportedSubmitMethods: []string{"post"},
ValidatorUrl: "foo",
WithCredentials: true,
PersistAuthorization: true,
HeaderHtml: `<div>HEADER</div>`,
HeadScript: `head();`,
BodyScript: `body();`,
}
m := o.ToMap()
assert.Equal(t, 23, len(m))
assert.Contains(t, m, "dom_id")
assert.Contains(t, m, "layout")
assert.Contains(t, m, "deepLinking")
assert.Contains(t, m, "displayOperationId")
assert.Contains(t, m, "defaultModelsExpandDepth")
assert.Contains(t, m, "defaultModelExpandDepth")
assert.Contains(t, m, "defaultModelRendering")
assert.Contains(t, m, "displayRequestDuration")
assert.Contains(t, m, "docExpansion")
assert.Contains(t, m, "maxDisplayedTags")
assert.Contains(t, m, "showExtensions")
assert.Contains(t, m, "showCommonExtensions")
assert.Contains(t, m, "useUnsafeMarkdown")
assert.Contains(t, m, "syntaxHighlight.theme")
assert.Contains(t, m, "tryItOutEnabled")
assert.Contains(t, m, "requestSnippetsEnabled")
assert.Contains(t, m, "supportedSubmitMethods")
assert.Contains(t, m, "validatorUrl")
assert.Contains(t, m, "withCredentials")
assert.Contains(t, m, "persistAuthorization")
assert.Equal(t, template.HTML(`<div>HEADER</div>`), m[htmlTagHeaderHtml])
assert.Equal(t, template.HTML(`<script>head();</script>`), m[htmlTagHeadScript])
assert.Equal(t, template.HTML(`<script>body();</script>`), m[htmlTagBodyScript])
}
func TestSwaggerOptions_OverrideFavIcons(t *testing.T) {
o := SwaggerOptions{
FavIcons: FavIcons{
64: "test.png",
},
}
icons := o.GetFavIcons()
assert.NotNil(t, icons)
html := icons.toHtml()
assert.Equal(t, template.HTML(`<link rel="icon" type="image/png" href="./test.png" sizes="64x64" />`), html)
}