model_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package seo
  2. import (
  3. "context"
  4. "testing"
  5. )
  6. func TestSettingHTMLComponent(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. setting Setting
  10. tags map[string]string
  11. want string
  12. }{
  13. {
  14. name: "Render the seo html",
  15. setting: Setting{
  16. Title: "title",
  17. Description: "description",
  18. Keywords: "keyword",
  19. OpenGraphURL: "http://dev.qor5.com/product/1",
  20. OpenGraphType: "",
  21. OpenGraphImageURL: "http://dev.qor5.com/product/1/og.jpg",
  22. },
  23. tags: map[string]string{},
  24. want: `
  25. <title>title</title>
  26. <meta name='description' content='description'>
  27. <meta name='keywords' content='keyword'>
  28. <meta property='og:type' name='og:type' content='website'>
  29. <meta property='og:image' name='og:image' content='http://dev.qor5.com/product/1/og.jpg'>
  30. <meta property='og:title' name='og:title' content='title'>
  31. <meta property='og:description' name='og:description' content='description'>
  32. <meta property='og:url' name='og:url' content='http://dev.qor5.com/product/1'>`,
  33. },
  34. {
  35. name: "Render the seo html using the tag data",
  36. setting: Setting{
  37. Title: "title",
  38. Description: "description",
  39. Keywords: "keyword",
  40. OpenGraphURL: "http://dev.qor5.com/product/1",
  41. OpenGraphType: "",
  42. OpenGraphImageURL: "http://dev.qor5.com/product/1/og.jpg",
  43. },
  44. tags: map[string]string{
  45. "og:type": "product",
  46. "twiiter:image": "http://dev.qor5.com/product/1/twitter.jpg",
  47. },
  48. want: `
  49. <title>title</title>
  50. <meta name='description' content='description'>
  51. <meta name='keywords' content='keyword'>
  52. <meta property='og:type' name='og:type' content='product'>
  53. <meta property='og:image' name='og:image' content='http://dev.qor5.com/product/1/og.jpg'>
  54. <meta property='og:title' name='og:title' content='title'>
  55. <meta property='og:description' name='og:description' content='description'>
  56. <meta property='og:url' name='og:url' content='http://dev.qor5.com/product/1'>
  57. <meta property='twiiter:image' name='twiiter:image' content='http://dev.qor5.com/product/1/twitter.jpg'>`,
  58. },
  59. }
  60. for _, tt := range tests {
  61. t.Run(tt.name, func(t *testing.T) {
  62. if got, _ := tt.setting.HTMLComponent(tt.tags).MarshalHTML(context.TODO()); !metaEqual(string(got), tt.want) {
  63. t.Errorf("Setting.HTMLComponent() = %v, want %v", string(got), tt.want)
  64. }
  65. })
  66. }
  67. }