package filter

import (
	"testing"

	"gitbase.de/apairon/mark2web/pkg/mark2web"

	"github.com/flosch/pongo2"

	. "github.com/smartystreets/goconvey/convey"
)

func TestRelativePathFilter(t *testing.T) {
	Convey("set context", t, func() {
		ctx := pongo2.Context{
			"testrel": "rel",
			"testabs": "/abs",
			"testsub": "../sub/rel",
		}

		mark2web.Config.Directories.Output = "../../test/out"

		mark2web.CurrentTreeNode = &mark2web.TreeNode{
			InputPath:  "../../test/in/content",
			OutputPath: "../../test/out/sub",
			Config: &mark2web.PathConfig{
				Imaging: &mark2web.ImagingConfig{
					Quality: 60,
					Height:  300,
					Width:   300,
					Process: "fit",
				},
			},
		}

		Convey("parse template", func() {

			output, err := pongo2.RenderTemplateString("{{ testrel|relative_path }}", ctx)
			So(err, ShouldBeNil)
			So(output, ShouldEqual, "rel")

			output, err = pongo2.RenderTemplateString("{{ testabs|relative_path }}", ctx)
			So(err, ShouldBeNil)
			So(output, ShouldEqual, "../abs")

			/* TODO
			output, err = pongo2.RenderTemplateString("{{ testsub|relative_path }}", ctx)
			So(err, ShouldBeNil)
			So(output, ShouldEqual, "rel")
			*/
		})
	})
}
