model_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. OpenGraphTitle: "og title",
  20. OpenGraphDescription: "og description",
  21. OpenGraphURL: "http://dev.qor5.com/product/1",
  22. OpenGraphType: "",
  23. OpenGraphImageURL: "http://dev.qor5.com/product/1/og.jpg",
  24. },
  25. tags: map[string]string{},
  26. want: `
  27. <title>title</title>
  28. <meta name='description' content='description'>
  29. <meta name='keywords' content='keyword'>
  30. <meta property='og:title' name='og:title' content='og title'>
  31. <meta property='og:description' name='og:description' content='og description'>
  32. <meta property='og:type' name='og:type' content='website'>
  33. <meta property='og:image' name='og:image' content='http://dev.qor5.com/product/1/og.jpg'>
  34. <meta property='og:url' name='og:url' content='http://dev.qor5.com/product/1'>`,
  35. },
  36. {
  37. name: "Render the seo html using the tag data",
  38. setting: Setting{
  39. Title: "title",
  40. Description: "description",
  41. Keywords: "keyword",
  42. OpenGraphTitle: "og title",
  43. OpenGraphDescription: "og description",
  44. OpenGraphURL: "http://dev.qor5.com/product/1",
  45. OpenGraphType: "",
  46. OpenGraphImageURL: "http://dev.qor5.com/product/1/og.jpg",
  47. },
  48. tags: map[string]string{
  49. "og:type": "product",
  50. "twiiter:image": "http://dev.qor5.com/product/1/twitter.jpg",
  51. },
  52. want: `
  53. <title>title</title>
  54. <meta name='description' content='description'>
  55. <meta name='keywords' content='keyword'>
  56. <meta property='og:title' name='og:title' content='og title'>
  57. <meta property='og:description' name='og:description' content='og description'>
  58. <meta property='og:type' name='og:type' content='product'>
  59. <meta property='og:image' name='og:image' content='http://dev.qor5.com/product/1/og.jpg'>
  60. <meta property='og:url' name='og:url' content='http://dev.qor5.com/product/1'>
  61. <meta property='twiiter:image' name='twiiter:image' content='http://dev.qor5.com/product/1/twitter.jpg'>`,
  62. },
  63. }
  64. for _, tt := range tests {
  65. t.Run(tt.name, func(t *testing.T) {
  66. if got, _ := tt.setting.HTMLComponent(tt.tags).MarshalHTML(context.TODO()); !metaEqual(string(got), tt.want) {
  67. t.Errorf("Setting.HTMLComponent() = %v, want %v", string(got), tt.want)
  68. }
  69. })
  70. }
  71. }