piechart_test.gno
0.94 Kb ยท 35 lines
1package piechart
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestRender(t *testing.T) {
9 title := "Test"
10 slices := []PieSlice{
11 {Value: 10, Color: "#00FF00", Label: "Green"},
12 {Value: 20, Color: "#FFFF00", Label: "Yellow"},
13 {Value: 30, Color: "#FF0000", Label: "Red"},
14 }
15
16 result := Render(slices, title)
17
18 // Check if the result contains the expected image SVG structure
19 if !strings.Contains(result, "data:image/svg+xml;base64,") {
20 t.Errorf("Expected result to contain data:image/svg+xml;base64, got %s", result)
21 }
22
23 // Check if the result contains the title
24 if !strings.Contains(result, title) {
25 t.Errorf("SVG does not contain the title %q", title)
26 }
27
28 // Check if the result contains non-empty slices
29 emptySlices := []PieSlice{}
30 emptyResult := Render(emptySlices, title)
31 expectedErr := "\npiechart fails: no data provided"
32 if emptyResult != expectedErr {
33 t.Errorf("Expected exact error for empty slices: %q, got %q", expectedErr, emptyResult)
34 }
35}