package wikipress

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestGetody(t *testing.T) {
	tts := []struct {
		name    string
		version Version
		expBody string
	}{
		{
			name:    "simple content",
			version: Version{content: "foobar\r\n---\r\nBlaBla"},
			expBody: "\r\nBlaBla",
		},
		{
			name:    "file without body",
			version: Version{content: "blabla"},
			expBody: "",
		},
	}

	for _, tt := range tts {
		t.Run(tt.name, func(t *testing.T) {
			body := tt.version.GetBody()
			assert.Equal(t, tt.expBody, body, "should return currect body")
		})
	}
}

func TestGetHeaders(t *testing.T) {
	expData1 := make(map[string]string)
	expData1["foo"] = "bar"
	tts := []struct {
		name      string
		version   Version
		expHeader map[string]string
	}{
		{
			name:      "simple test",
			version:   Version{content: "foo: bar\r\n---\r\ncontent"},
			expHeader: expData1,
		},
	}

	for _, tt := range tts {
		t.Run(tt.name, func(t *testing.T) {
			headers := tt.version.GetHeaders()
			assert.Equal(t, tt.expHeader, headers, "headers should match")
		})
	}
}

func TestGetHTMLContent(t *testing.T) {
	tts := []struct {
		name     string
		version  Version
		exptHTML string
	}{
		{
			name:     "simeple",
			version:  Version{content: "foo:bar\r\n---\r\n# Simple\r\nTest"},
			exptHTML: "<h1>Simple</h1>\n<p>Test</p>\n",
		},
	}

	for _, tt := range tts {
		t.Run(tt.name, func(t *testing.T) {
			html, err := tt.version.GetHTMLContent()
			assert.Nil(t, err, "should return no error")
			assert.Equal(t, tt.exptHTML, html, "should return expected html")
		})
	}
}
