Ejemplo n.º 1
0
func TestResourceRendering(t *testing.T) {
	trees.SetMode(trees.Testing)
	defer trees.SetMode(trees.Normal)

	_ = design.Resource(func() {
		design.DoOrder(design.Any)
		design.UseRoute("/home/*")

		design.DoCSS("../some.css", false)
		design.DoScript("../some.js", "text/javascript", false)

		design.DoMarkup(elems.Header1(elems.Text("Speed Dashboard")), "", false)

		design.DoMarkup(func() *trees.Markup {
			return elems.Div(
				elems.Section(
					elems.Label(elems.Text("Current Speed")),
				),
			)
		}, "", false)

		design.DoView(gu.Static(elems.Div(
			elems.Section(
				design.DoRoute("/models/*", "/:speed"),
				elems.Label(elems.Text("Total Speed")),
			),
		)), "", false)

	})

	master := design.New().Init()

	testRender := master.Render(dispatch.UseLocation("/home/"))
	if testRender.HTML() != fullRender {
		t.Logf("\t\tExpected: %q", fullRender)
		t.Logf("\t\tReceived: %q", testRender.HTML())
		tests.Failed(t, "Should have rendered the expected full markup")
	}
	tests.Passed(t, "Should have rendered the expected full markup")

	testRender2 := master.Render(dispatch.UseLocation("/home/models/340mph"))
	if testRender2.HTML() != routedRender {
		t.Logf("\t\tExpected: %q", routedRender)
		t.Logf("\t\tReceived: %q", testRender2.HTML())
		tests.Failed(t, "Should have rendered the routed full markup")
	}
	tests.Passed(t, "Should have rendered the routed full markup")

	testFlatRender := master.Render(dispatch.UseLocation("/root"))
	if testFlatRender.HTML() != flatRender {
		t.Logf("\t\tExpected: %q", flatRender)
		t.Logf("\t\tReceived: %q", testFlatRender.HTML())
		tests.Failed(t, "Should have rendered the expected markup")
	}
	tests.Passed(t, "Should have rendered the expected markup")

}
Ejemplo n.º 2
0
func TestResolver(t *testing.T) {
	rx := dispatch.NewResolver("/:id")
	params, _, state := rx.Test("12")

	if !state {
		tests.Failed(t, "Should have matched giving path")
	}
	tests.Passed(t, "Should have matched giving path")

	val, ok := params["id"]
	if !ok {
		tests.Failed(t, "Should have retrieve parameter :id => %s", val)
	}
	tests.Passed(t, "Should have retrieve parameter :id => %s", val)

	rx.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have notified with Path %#v", px)
	})

	rx.ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have notified with Path %#v", px)
	})

	rx.Resolve(dispatch.UseLocation("/12"))
}
Ejemplo n.º 3
0
func TestRoute(t *testing.T) {
	rm := gu.NewRouteManager()

	home := rm.L("/home/*")
	if _, _, pass := home.Test("/home/models/12"); !pass {
		tests.Failed(t, "Should have validated path /home/models/12")
	}
	tests.Passed(t, "Should have validated path /home/models/12")

	index := rm.L("/index/*")
	if _, _, pass := index.Test("/index"); !pass {
		tests.Failed(t, "Should have validated path /index")
	}
	tests.Passed(t, "Should have validated path /index")

	getModel := home.N("/models/*")
	if _, _, pass := getModel.Test("/models"); !pass {
		tests.Failed(t, "Should have validated path /models")
	}
	tests.Passed(t, "Should have validated path /models")

	if _, _, pass := getModel.Test("/models/12"); !pass {
		tests.Failed(t, "Should have validated path /models/12")
	}
	tests.Passed(t, "Should have validated path /models/12")

	id := getModel.N("/:id")
	param, _, pass := id.Test("/12")
	if !pass {
		tests.Failed(t, "Should have validated path /12")
	}
	tests.Passed(t, "Should have validated path /12: %#v", param)

	home.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have validated path /home/models/12:  /home")
	}).ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have validated path /home/models/12:  /home")
	})

	getModel.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have validated path /home/models/12:  /models")
	}).ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have validated path /home/models/12:  /models")
	})

	id.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have validated path /home/models/12:  /id")
	}).ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have validated path /home/models/12:  /id")
	})

	home.Resolve(dispatch.UseLocation("/home/models/12"))
	home.Resolve(dispatch.UseLocationHash("http://thunderhouse.com/#home/models/12"))
}
Ejemplo n.º 4
0
func TestResolverFailed(t *testing.T) {
	rx := dispatch.NewResolver("/:id")
	rx.ResolvedPassed(func(px dispatch.Path) {
		tests.Failed(t, "Should have notified with failed Path %#v", px)
	})

	rx.ResolvedFailed(func(px dispatch.Path) {
		tests.Passed(t, "Should have notified with failed Path %#v", px)
	})

	rx.Resolve(dispatch.UseLocation("/home/12"))
}
Ejemplo n.º 5
0
func TestResolverLevels(t *testing.T) {
	home := dispatch.NewResolver("/home/*")
	rx := dispatch.NewResolver("/:id")

	home.Register(rx)

	rx.ResolvedPassed(func(px dispatch.Path) {
		tests.Passed(t, "Should have notified with Path %#v", px)
	})

	rx.ResolvedFailed(func(px dispatch.Path) {
		tests.Failed(t, "Should have notified with Path %#v", px)
	})

	home.Resolve(dispatch.UseLocation("home/12"))
}
Ejemplo n.º 6
0
Archivo: design.go Proyecto: influx6/gu
// RenderWithScript creates a complete markup definition using the giving set of Resource
// Definition by applying the giving path.
func (rs *Resources) RenderWithScript(path string, script string) *trees.Markup {
	return rs.RenderPathWithScript(dispatch.UseLocation(path), script)
}
Ejemplo n.º 7
0
Archivo: design.go Proyecto: influx6/gu
// Render creates a complete markup definition using the giving set of Resource
// Definition by applying the giving path.
func (rs *Resources) Render(path string) *trees.Markup {
	return rs.RenderPath(dispatch.UseLocation(path))
}