12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package seo
- import (
- "context"
- "testing"
- )
- func TestSettingHTMLComponent(t *testing.T) {
- tests := []struct {
- name string
- setting Setting
- tags map[string]string
- want string
- }{
- {
- name: "Render the seo html",
- setting: Setting{
- Title: "title",
- Description: "description",
- Keywords: "keyword",
- OpenGraphURL: "http://dev.qor5.com/product/1",
- OpenGraphType: "",
- OpenGraphImageURL: "http://dev.qor5.com/product/1/og.jpg",
- },
- tags: map[string]string{},
- want: `
- <title>title</title>
- <meta name='description' content='description'>
- <meta name='keywords' content='keyword'>
- <meta property='og:type' name='og:type' content='website'>
- <meta property='og:image' name='og:image' content='http://dev.qor5.com/product/1/og.jpg'>
- <meta property='og:title' name='og:title' content='title'>
- <meta property='og:description' name='og:description' content='description'>
- <meta property='og:url' name='og:url' content='http://dev.qor5.com/product/1'>`,
- },
- {
- name: "Render the seo html using the tag data",
- setting: Setting{
- Title: "title",
- Description: "description",
- Keywords: "keyword",
- OpenGraphURL: "http://dev.qor5.com/product/1",
- OpenGraphType: "",
- OpenGraphImageURL: "http://dev.qor5.com/product/1/og.jpg",
- },
- tags: map[string]string{
- "og:type": "product",
- "twiiter:image": "http://dev.qor5.com/product/1/twitter.jpg",
- },
- want: `
- <title>title</title>
- <meta name='description' content='description'>
- <meta name='keywords' content='keyword'>
- <meta property='og:type' name='og:type' content='product'>
- <meta property='og:image' name='og:image' content='http://dev.qor5.com/product/1/og.jpg'>
- <meta property='og:title' name='og:title' content='title'>
- <meta property='og:description' name='og:description' content='description'>
- <meta property='og:url' name='og:url' content='http://dev.qor5.com/product/1'>
- <meta property='twiiter:image' name='twiiter:image' content='http://dev.qor5.com/product/1/twitter.jpg'>`,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- if got, _ := tt.setting.HTMLComponent(tt.tags).MarshalHTML(context.TODO()); !metaEqual(string(got), tt.want) {
- t.Errorf("Setting.HTMLComponent() = %v, want %v", string(got), tt.want)
- }
- })
- }
- }
|